File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Programming these buttons" Watch "Programming these buttons" New topic

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) {
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
jTextArea1.setText("Enter Earth Weight (lbs):");
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) {
if (e.getID() == WindowEvent.WINDOW_CLOSING) {

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

void jButton2_actionPerformed(ActionEvent e) {


void jButton3_actionPerformed(ActionEvent e) {

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:
subject: Programming these buttons
It's not a secret anymore!