aspose file tools*
The moose likes Beginning Java and the fly likes Programming these buttons Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Programming these buttons" Watch "Programming these buttons" New topic
Author

Programming these buttons

Mike Meakin
Ranch Hand

Joined: Dec 30, 2004
Posts: 88
Hey does anyone know how to what code I need for a 'close'(button 2) button and an 'Again'(button 3) button for this code. Button 1 works fine for the calculation. Heres the code:

jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
contentPane.setLayout(xYLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
jButton2.setBorder(BorderFactory.createRaisedBevelBorder());
jButton2.setText("Again");
jButton3.setBorder(BorderFactory.createRaisedBevelBorder());
jButton3.setText("Close");
jTextArea1.setBackground(SystemColor.control);
jTextArea1.setText("Enter Earth Weight (lbs):");
contentPane.setBorder(BorderFactory.createRaisedBevelBorder());
jLabel1.setText("Your Moon Weight Is:");
contentPane.add(jButton2, new XYConstraints(45, 241, 113, 39));
contentPane.add(jButton3, new XYConstraints(222, 241, 108, 39));
contentPane.add(jTextArea1, new XYConstraints(22, 68, 181, 28));
contentPane.add(jTextField1, new XYConstraints(211, 64, 122, 27));
contentPane.add(jButton1, new XYConstraints(130, 110, 116, 43));
contentPane.add(jLabel1, new XYConstraints(17, 159, 198, 42));
}
/**Overridden so we can exit when window is closed*/
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}

void jButton1_actionPerformed(ActionEvent e) {
jLabel1.setText("" + (Double.parseDouble(jTextField1.getText())*0.166));
}


void jButton2_actionPerformed(ActionEvent e) {

jTextField1.requestFocus();
}

void jButton3_actionPerformed(ActionEvent e) {
System.exit(0);


}
}
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
Please post the question clearly.
do you want to close any frame when the "Close" button is clicked.


Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Mike Meakin
Ranch Hand

Joined: Dec 30, 2004
Posts: 88
Basically when you run the programme it brings up a dialogue box, you enter a number then click the calculate button(button 1 in this code) which does the calculation, all this works fine. Now I need a 'close' button, (button 2 in this code) to close the dialogue box, I'm not sure what code I need for it to operate though...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Programming these buttons