I'm doing a program in java, and I want pass at the new window when I click the button but when I run the program it automatically open me the 2 views also if I don't press the button.What can I do for fix this problem?
Main:
package com.SimplyGeometry.src.tiles;
import com.SimplyGeometry.src.windows.SelectWindow;
import com.SimplyGeometry.src.windows.StartWindow;
public class Main {
public static void main(String[] args) {
String title = "SimplyGeometry";
int WIDTH = 1320, HEIGHT = 840;
StartWindow stw = new StartWindow(/*WIDTH, HEIGHT, title*/);
}
}
Vew1:
package com.SimplyGeometry.src.windows;
import javax.swing.*;
import Actions.Actions;
public class StartWindow implements ActionListener {
public static JFrame window;
SelectWindow sw;
public StartWindow(/*int WIDTH, int HEIGHT, String title*/) {
window = new JFrame("SimplyGeometry");
window.setPreferredSize(new Dimension(1320, 840));
window.setMaximumSize(new Dimension(1320, 840));
window.setMinimumSize(new Dimension(1320, 840));
window.setLocationRelativeTo(null);
window.setResizable(false);
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setBounds(0, 0, 1320, 840);
panel.setBackground(Color.CYAN);
JLabel label = new JLabel();
label.setIcon(new ImageIcon("/Users/gaetanodonnarumma/Documents/workspace/SimplyGeometry(Complete)/src/Images/titolo.png"));
label.setSize(650, 250);
label.setLocation(320, 100);
JButton button = new JButton("Start");
button.setBackground(Color.white);
button.setForeground(Color.black);
button.setSize(350, 100);
button.setLocation(455, 450);
button.setEnabled(true);
button.addActionListener(new Actions());
window.add(panel);
panel.add(label);
window.validate();
panel.add(button);
window.setVisible(true);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}
View 2:
package com.SimplyGeometry.src.windows;
import java.awt.Dimension;
import javax.swing.*;
public class SelectWindow {
public static JFrame window;
public SelectWindow(/*int WIDTH, int HEIGHT, String title*/) {
window = new JFrame("SimplyGeometry");
window.setPreferredSize(new Dimension(1320, 840));
window.setMaximumSize(new Dimension(1320, 840));
window.setMinimumSize(new Dimension(1320, 840));
window.setLocationRelativeTo(null);
window.setLayout(null);
window.setVisible(true);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
the actionListener class:
package Actions;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import com.SimplyGeometry.src.windows.SelectWindow;
import com.SimplyGeometry.src.windows.StartWindow;
public class Actions implements ActionListener {
public Actions() {
SelectWindow window = new SelectWindow();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}