Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Programming these buttons

 
Mike Meakin
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • 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);


}
}
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • 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
  • 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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic