May somebody help me? I have two questions. First, why CLEAR button not sweeping text(I tried t1.setText(null);, but it not working. And second, in SAVE button is same problem, it is not working. I want it to saved text go to SAVED frame. What i need to write.(I am 14 years old and i am only beginner, so do not judge strictly).
public class panabut {
public static void main(String[] args) {
JFrame f = new JFrame("Buttons");
f.setSize(400, 400);
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
f.setVisible(true);
JPanel p = new JPanel();
f.add(p);
JButton b = new JButton("Register");
JButton b1 = new JButton("Saved");
p.add(b);
p.add(b1);
p.add(b, BorderLayout.NORTH);
p.add(b1, BorderLayout.NORTH);
b.addActionListener(new Info());
b1.addActionListener(new Save());
}
}
class Info implements ActionListener {
public void actionPerformed(ActionEvent e) {
JFrame f1 = new JFrame();
JPanel p = new JPanel();
f1.add(p);
f1.setResizable(false);
f1.setSize(250, 150);
f1.setLocationRelativeTo(null);
f1.setVisible(true);
setLayout(new FlowLayout());
JButton b1, b2;
JTextField t1, t2;
JLabel l1, l2;
b1 = new JButton("Save");
b2 = new JButton("Clear");
l1 = new JLabel("Enter name");
l2 = new JLabel("Enter second name");
t1 = new JTextField(10);
t2 = new JTextField(10);
p.add(l1);
p.add(t1);
p.add(l2);
p.add(t2);
p.add(b1);
p.add(b2);
if (e.getSource() == b1) {
JOptionPane.showInputDialog("Saved");
}
if (e.getSource() == b2) {
t1.setText(" ");
t2.setText(" ");
}
}
private void setLayout(FlowLayout flowLayout) {
}
}
class Save implements ActionListener {
public void actionPerformed(ActionEvent b) {
JFrame f2 = new JFrame("Saved");
f2.setSize(300, 300);
f2.setVisible(true);
}
protected void setLayout(FlowLayout flowLayout) {
}
}