Note that there are some explanatory texts on larger screens.

plurals
  1. POClosing a JFrame window?
    primarykey
    data
    text
    <p>I'm using two frames. In the first frame I have a button to open the second frame. In the second frame there is also a button, but this one is for closing the second frame. But I don't know how to do this, and I'm looking for some help to solve this?</p> <p>GUI1</p> <pre><code>import java.awt.*; import java.awt.event.*; import javax.swing.*; public class GUI1 extends JFrame implements ActionListener{ JButton btn1; Container contentPane; public GUI1() { setTitle("GUI 1"); setResizable(false); setSize(600,300); setDefaultCloseOperation(EXIT_ON_CLOSE); contentPane = getContentPane(); contentPane.setLayout(new FlowLayout()); btn1 = new JButton("Open GUI 2 frame"); contentPane.add(btn1); btn1.setFocusable(false); btn1.addActionListener(this); } public void actionPerformed(ActionEvent event){ if(event.getSource() == btn1) { GUI2 frame2 = new GUI2(); frame2.setVisible(true); } } public static void main(String[] args) { GUI1 frame = new GUI1(); frame.setVisible(true); } } </code></pre> <p>GUI2</p> <pre><code>import java.awt.*; import java.awt.event.*; import javax.swing.*; public class GUI2 extends JFrame implements ActionListener { Container contentPane; JButton btn2; public GUI2() { setTitle("GUI 2"); setResizable(false); setSize(400,200); setDefaultCloseOperation(DISPOSE_ON_CLOSE); contentPane = getContentPane(); contentPane.setLayout(new FlowLayout()); btn2 = new JButton("Close GUI 2 frame"); contentPane.add(btn2); btn2.addActionListener(this); } public void actionPerformed(ActionEvent event){ if(event.getSource() == btn2) { // Close GUI2 ?? } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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