aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes jButtons  are driving me crazy Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "jButtons  are driving me crazy" Watch "jButtons  are driving me crazy" New topic
Author

jButtons are driving me crazy

Tami Hart
Greenhorn

Joined: Jun 09, 2004
Posts: 7
how do I get my buttons to have functionality? the window is set up the way I want it. however, when the user clicks on the calculate button I want it to perform a mathmatical function and then display the results in the payment field.

Please Help

here is my program:

import javax.swing.*;
import java.awt.*;

class PosMortg1 extends JFrame {

PosMortg1() {
super("Calculate a Mortgage Payment?");
setSize(370, 270);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container pane = getContentPane();
FlowLayout flow = new FlowLayout(FlowLayout.RIGHT);
pane.setLayout(flow);
JPanel row1 = new JPanel();
JLabel amountLabel = new JLabel("How much are you Borrowing?");
row1.add(amountLabel);
JTextField amount = new JTextField(14);
row1.add(amount);
pane.add(row1);
JPanel row2 = new JPanel();
JLabel percentLabel = new JLabel("Enter Percent Rate:");
row2.add(percentLabel);
JTextField percent = new JTextField(14);
row2.add(percent);
pane.add(row2);
JPanel row3 = new JPanel();
JLabel yearsLabel = new JLabel("How Many Years?");
row3.add(yearsLabel);
JTextField years = new JTextField(14);
row3.add(years);
pane.add(row3);
JPanel row4 = new JPanel();
JButton calculate = new JButton("Calculate");
row4.add(calculate);
pane.add(row4);
JPanel row5 = new JPanel();
JLabel paymentLabel = new JLabel("Monthly Payments");
row5.add(paymentLabel);
JTextArea payment = new JTextArea(4, 14);
payment.setLineWrap(true);
payment.setWrapStyleWord(true);
JScrollPane scroll = new JScrollPane(payment,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
row5.add(scroll);
pane.add(row5);
setContentPane(pane);
setVisible(true);
}

public static void main(String[] arguments) {
PosMortg1 mortgage = new PosMortg1();
}
}
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

I'd say you need to visit Sun's tutorial on Buttons.



GenRocket - A Test Data Generation Platform
Eddie Vanda
Ranch Hand

Joined: Mar 18, 2003
Posts: 281
I do not think you need the second last line of your constructor:

But it probably does not do any harm.


The nice thing about Standards is that there are so many to choose from!
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

Tami asked:


if I want to use the fields the user fills in How do I call them into the same math equation? I need to use all three in the same math equation.


In your event method you can simply call amount.getText() to get a String of the value entered in the textfield. Keep in mind though that you will then need to convert your String to an Integer to do calculations. Also note that the compile will probably complain that your variables like amount, percent, etc will need to be declared final.
[ July 03, 2004: Message edited by: Gregg Bolinger ]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

Here's how I might do it:

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jButtons are driving me crazy
 
Similar Threads
GUI
Problems with this weeks code..Still not understanding Illegal start of expression...HELP PLEASE
help I am having trouble getting the field to fill in
Very Very New
Trying to figure out Exception Error in code