I probably have a really simple problem. I want to create two frames - mainfr (in the class called Pag) and dscrpt (in a class called Apras). I managed to create the first frame (mainfr) and the second frame (dscrpt) using button skaiciav from the frame mainfr. When question is how to come back to the first frame using the button griz located in frame dscrp?
package grap;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Pag implements ActionListener {
JFrame mainfr;
JFrame apras;
JLabel psl_apras;
JLabel galim_veiksm;
JLabel paspaud;
public Pag() {
//Create JFrame container
mainfr = new JFrame("Turinys");
//Choosing layout type
mainfr.setLayout(new FlowLayout());
//window resolution
mainfr.setSize(500, 300);
//Program terminates on close
mainfr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Label's
psl_apras = new JLabel("Mokomoji programa");
galim_veiksm = new JLabel("Galimi veiksmai");
//adding them to main frame
mainfr.add(psl_apras);
mainfr.add(galim_veiksm);
//Button
JButton skaiciav = new JButton("Description");
//action listener
skaiciav.addActionListener(this);
//adding button to frame
mainfr.add(skaiciav);
//another label
paspaud = new JLabel("Press button");
//adding label to frame
mainfr.add(paspaud);
//making frame visible
mainfr.setVisible(true);
}
//action listener method
public void actionPerformed(ActionEvent a) {
if(a.getActionCommand().equals("Description"))
{
Apras.suk();
mainfr.setVisible(false);
}
//Started to get confused here
/*if(a.getActionCommand().equals("back")){
mainfr.setVisible(true);
apras.setVisible(false);
dscrp.dispose();
*/
}
public static void main (String args[]) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new Pag();
}
});
}
}
Second class
package grap;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Apras {
static JFrame dscrp;
static void suk() {
dscrp = new JFrame("Description");
dscrp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//frame2.setLocationByPlatform(true);
dscrp.setBackground(Color.WHITE);
JButton griz = new JButton("back");
//griz.addActionListener();
dscrp.add(griz);
dscrp.setSize(500, 300);
dscrp.setVisible(true);
}
}