So I want to write a program using GUI. The first frame will be a log in. When the user presses enter, I want the initial page to go away and be replaced with, basically, the next screen. I will want to do this multiple times, with each page asking a question and the next page dependent on that preceding answer. How do I do this? Will I need create an action listener for that button to exit the first frame, then create another frame?
Also, my program will use multithreading to allow multiple users to access the program at once. Although I don't think this will have anything to do with the gui, besides for launching multiple screens.
This is what I have so far.
Code:
/*
Written by trantommyd
How do I make another frame pop up after they log in? I want to include the user I'd in each succeeding title
*/
import java.util.*;
import javax.swing.*;
import java.awt.*;
public class AirlineProgram extends JFrame implements Runnable
{
JLabel welcomeLBL = new JLabel("Hi! Welcome to St. Steven's Airlines!");
JLabel loginLBL = new JLabel("Please log in.");
JTextField loginTF = new JTextField(8);
JButton loginB = new JButton("Enter");
JLabel vipLBL = new JLabel("Do you have a VIP code?");
JTextField vipTF = new JTextField(6);
public AirlineProgram()
{
JPanel p1 = new JPanel(new GridLayout(4,4));
p1.add(welcomeLBL);
p1.add(loginLBL);
p1.add(loginTF);
p1.add(loginB);
setLayout(new BorderLayout(4,4));
add(p1, BorderLayout.NORTH);
}
public void run()
{
//make a gui
AirlineProgram frame = new AirlineProgram();
frame.setTitle("St. Steven's Airlines");
frame.setSize(400,300);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
public static void main(String args[])
{
Scanner keyboard = new Scanner(System.in);
boolean newUser = true;
while(newUser)
{
System.out.println("Enter any key to start a new user. Press 'n' to end the program.");
String newThread = keyboard.nextLine();
if(!newThread.equalsIgnoreCase("n"))
{
(new Thread(new AirlineProgram())).start();
}
else
{
System.out.println("Thank you for using St. Stephen's Airlines. Goodbye.");
newUser = false;
}
}
}
}