Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Why bottons are not working?

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Why bottons are not working?

    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) {

    }
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Why bottons are not working?

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Please post your code correctly using code or highlight tags per the above link. No judging, but we do ask that you follow some basic rules outlined in the above link. . . well, guidelines really.

  3. #3
    Junior Member
    Join Date
    Sep 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Why bottons are not working?

    Okay, thank you

Similar Threads

  1. Replies: 2
    Last Post: June 25th, 2013, 06:33 AM
  2. Replies: 7
    Last Post: April 25th, 2013, 01:12 PM
  3. my three bottons is not centering
    By poldz123 in forum AWT / Java Swing
    Replies: 0
    Last Post: February 25th, 2013, 04:24 PM
  4. Replies: 4
    Last Post: January 27th, 2009, 12:03 AM