• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Programming these buttons

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);


}
}
 
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post the question clearly.
do you want to close any frame when the "Close" button is clicked.
 
Mike Meakin
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Why fit in when you were born to stand out? - Seuss. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic