Comments are available to members only. Sign up or Log in to view these comments.
Main Topics
Browse All TopicsI have a friend that is also taking a class and is having a problem with the size of his JButtons. All he wants to do is increase the width of the buttons so the lable can fix inside the button and not have "...." in the button. Here is his code:
//
//
//
//HayesMortgageMadness2 is a edited version of Rick Littons code posted at UOPHX
//Class POS 407.
// This code has been modified from using Ricks original MortgageGUI.java File.
// It still utilizes a Mortgage File and a MortgageDriver File
// The Mortgage Driver handles all the events from the HayesMortgageMadness
// Added in Tabs control which the two tabs are Mortgage calculator and Radio Buttons.
// Program does not take numbers larger than 12 digits so dont waste your time trying.
//The second panel Radio buttons has the radio buttons on it
//
import java.awt.*;
import javax.swing.*;
import javax.swing.border.EmptyBo
import java.awt.event.*;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import java.awt.Dimension;
import java.awt.GridLayout;
public class HayesMortgageMadness2 extends JFrame
{
MortgageDriver listener = new MortgageDriver(this);
//set labels
JLabel mortAmount = new JLabel("Mortgage Amount:$");
JLabel loanTerm = new JLabel("Loan Years:");
JLabel Primerate = new JLabel("Interest Rate(0.00):");
JLabel MonthlyPayment = new JLabel("Mortgage Monthly Payment:$");
//text fields
JTextField userinputmortgageamt = new JTextField("",10);
JTextField userinputterm = new JTextField("",10);
JTextField userinputrate = new JTextField("",10);
JTextField calculatedPaymentfield = new JTextField("",10);
JTextField calculatedPayment = new JTextField ("",10);
//buttons
public ButtonFrame(){
super("Button Frame");
setSize(170,25);
JButton calculate = new JButton("Calculate");
JButton reset = new JButton("reset");
JButton exit = new JButton("Exit");
//strings OR COMMANDS for Radio buttons.
static String sevenyearString = "7 years at 5.35";
static String fifteenyearString = "15 years at 5.5";
static String thirtyyearString = "30 years at 5.75";
//*******************
public HayesMortgageMadness2 (){
super ("Hayes Mortgage MADness");
setSize (420,350);
setDefaultCloseOperation(J
init(); //runs intialization subroutine or method to build screen.
}
//***********************
//begining code init method
public void init(){
//listener setups for calculate, reset and exit
calculate.addActionListene
reset.addActionListener(li
exit.addActionListener(lis
//Create the radio buttons.
JRadioButton sevenyearButton = new JRadioButton(sevenyearStri
sevenyearButton.setMnemoni
sevenyearButton.setActionC
sevenyearButton.setSelecte
JRadioButton fifteenyearButton = new JRadioButton(fifteenyearSt
fifteenyearButton.setMnemo
fifteenyearButton.setActio
JRadioButton thirtyyearButton = new JRadioButton(thirtyyearStr
thirtyyearButton.setMnemon
thirtyyearButton.setAction
//Register a listener for the radio buttons.
sevenyearButton.addActionL
fifteenyearButton.addActio
thirtyyearButton.addAction
//************
JPanel mainPanel = new JPanel(new BorderLayout());
//buttons calculate reset and add
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(1,3));
buttonPanel.setBorder( BorderFactory.createEmptyB
buttonPanel.add(calculate)
buttonPanel.add(reset);
buttonPanel.add(exit);
//set first tabs
JTabbedPane Tabs = new JTabbedPane();
JPanel textPanel = new JPanel();
//***************
textPanel.setLayout(new GridLayout(8,2));
textPanel.setBorder( BorderFactory.createEmptyB
// Panels to container
textPanel.add(mortAmount);
textPanel.add(userinputmor
textPanel.add(userinputmor
textPanel.add(loanTerm);
textPanel.add(userinputter
textPanel.add(Primerate);
textPanel.add(userinputrat
textPanel.add(MonthlyPayme
textPanel.add(calculatedPa
//textPanel.add(calculate)
//textPanel.add(reset);
//textPanel.add(exit);
//*************
textPanel.add(buttonPanel,
Tabs.addTab ("Mortgage calculator", null, textPanel, "first panel");
//end of first tab
//***************
//set second tab JTabbedPane Tab = new JTabbedPane();
//****************
JPanel radioPanel = new JPanel();
//table
//end of second tab
Tabs.addTab ("Radio buttons", null, radioPanel, "Radiobuttons");
//table
String[] columnNames = {"Payment number",
"Interest",
"Balance due"
};
Object[][] data = {
{"Mary", "Campione",
"Snowboarding", new Integer(5), new Boolean(false)},
{"Alison", "Huml",
"Rowing", new Integer(3), new Boolean(true)},
{"Kathy", "Walrath",
"Knitting", new Integer(2), new Boolean(false)},
};
JTable table = new JTable(data, columnNames);
JScrollPane scrollPane = new JScrollPane(table);
table.setPreferredScrollab
//Group the radio buttons.
ButtonGroup group = new ButtonGroup();
group.add(sevenyearButton)
group.add(fifteenyearButto
group.add(thirtyyearButton
//add buttons to radiopanel
radioPanel.add(sevenyearBu
radioPanel.add(fifteenyear
radioPanel.add(thirtyyearB
radioPanel.add(scrollPane)
// make payment text box read only
calculatedPaymentfield.set
getContentPane().add(Tabs)
// finally, display the frame
setVisible(true);
//sets the action events
}
public static void main(String[] args) {
HayesMortgageMadness2 gui = new HayesMortgageMadness2();
}
}
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: objectsPosted on 2006-01-07 at 18:59:20ID: 15640149
Comments are available to members only. Sign up or Log in to view these comments.