In my application ,When the user clicks the JButton, display a JLabel that prompts the user to enter an integer, a JTextField into which the user can type the integer, and a secondJButton that contains the text Double me. When the user clicks the second button, the integer is doubled and the answer is displayed in the JTextField.
I am not able to display second button and text fields, when i click first button...please help
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class JDouble extends JApplet implements ActionListener {
private Container container = getContentPane();
/**
* The JButton.
*/
private JButton button = new JButton("Click me");
private JButton button2 = new JButton("Double me");
/**
* The JLabel.
*/
private JLabel label = new JLabel("Enter Integer");
private JTextField textfield = new JTextField(4);
private JTextField textfield2 = new JTextField(4);
public void init() {
// set the layout to FlowLayout
container.setLayout(new FlowLayout());
// register the 'this' action listener for the button
button.addActionListener(this);
container.add(button);
}
public void init1(){
container.setLayout(new FlowLayout());
container.add(textfield);
container.add(button2);
container.add(textfield2);
button2.addActionListener(this);
}
public void actionPerformed(ActionEvent actionEvent) {
container.add(label);
}
public void actionPerformed1(ActionEvent actionEvent) {
String me = textfield.getText();
int computation = Integer.parseInt(me);
computation = computation*2;
String changecomputation = Integer.toString(computation);
textfield2.setText(changecomputation);
container.remove(button);
container.add(label);
repaint();
validate();
}
}