I am facing a bit problem as I am a newbe in Java. I made two frame, the first one's name is test and the second one is Login. In the test Jframe, there are three buttons. The third one which name is "Admin" is for taking me to the second frame. How can I make the third buttonwork to take me to the second frame without closing the first frame?
Thanks in advance.
import javax.swing.*;
import javax.swing.JButton;
import javax.swing.JFrame;
import java.awt.*;
import java.awt.event.*;
public class test extends JFrame {
private static final int width = 600, height = 480;
private static final int buttonWidth = 200, buttonHeight = 100;
static JFrame frame;
static JButton button;
static JButton button2;
static JButton button3;
public static void main(String[] args) {
createWindow();
createButtons();
addEverything();
frame.setVisible(true);
}
private static void createWindow() {
frame = new JFrame("Welcome to Easy Hire");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(width, height);
}
private static void createButtons() {
button = new JButton("Hire A Taxi");
button.setLocation(0, 0);
button2 = new JButton("User Login");
button2.setLocation(200, 0);
button3 = new JButton("Admin");
button3.setLocation(400, 0);
}
private static void addEverything() {
addButtons();
}
private static void addButtons() {
frame.getContentPane().setLayout(null);
frame.getContentPane().add(button);
frame.getContentPane().add(button2);
frame.getContentPane().add(button3);
button.setSize(200,50);
button2.setSize(200,50);
button3.setSize(200,50);
}
}