Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Next Page- GUI

  1. #1
    New Coder
    Join Date
    Mar 2012
    Posts
    30
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Next Page- GUI

    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;
    			}
    		}
        }
    }
    Last edited by trantommyd; 07-26-2012 at 10:12 PM.

  • #2
    New Coder
    Join Date
    Mar 2012
    Posts
    30
    Thanks
    1
    Thanked 0 Times in 0 Posts
    i figured out my gui problem.
    i added an action listener to the button.
    in the action listener i used .getText on the textBox and .setText on the labels. this effectively gave me the "next page."


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •