Note that there are some explanatory texts on larger screens.

plurals
  1. PO(Java) Difficulty in classes
    text
    copied!<p><img src="https://i.stack.imgur.com/PiLBI.jpg" alt="enter image description here"></p> <p>Based on the diagram above; I would like Frame1 to show Frame2 using New(Jbutton) and Frame3 show using Show(JButton). Frame3 has this default "Hello World"(JtextField) and I would like to make this empty using the Yes(JButton) from Frame2. </p> <p>The problem is that I don't know the code for Frame2 and how to empty the textfield from frame3.</p> <p>Here is my code so far:</p> <p>Frame1.java</p> <pre><code>public class Frame1 extends JFrame implements ActionListener{ JButton b1 = new JButton("New"); JButton b2 = new JButton("Show"); Frame2 f2 = new Frame2(); Frame3 f3 = new Frame3(); public Frame1(){ setLayout(new FlowLayout()); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(300,300); add(b1); add(b2); b1.addActionListener(this); b2.addActionListener(this); } public static void main(String args[]){ new Frame1(); } public void actionPerformed(ActionEvent e) { if(e.getSource()==b1){ f2.setVisible(true); } else{ f3.setVisible(true); } } } </code></pre> <p>Frame2.java</p> <pre><code>public class Frame2 extends JFrame implements ActionListener{ JButton b1 = new JButton("Yes"); JButton b2 = new JButton("No"); public Frame2(){ setLayout(new FlowLayout()); setVisible(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(300,100); add(b1); add(b2); } public void actionPerformed(ActionEvent e) { if(e.getSource()==b1){ }else{ } } } </code></pre> <p>Frame3.java</p> <pre><code>public class Frame3 extends JFrame{ JTextField t1 = new JTextField("Hello WOrld"); public Frame3(){ setLayout(new FlowLayout()); setVisible(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(200,200); add(t1); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload