Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-26-2012, 10:06 PM   PM User | #1
trantommyd
New Coder

 
Join Date: Mar 2012
Posts: 30
Thanks: 1
Thanked 0 Times in 0 Posts
trantommyd is an unknown quantity at this point
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..
trantommyd is offline   Reply With Quote
Old 07-27-2012, 09:01 PM   PM User | #2
trantommyd
New Coder

 
Join Date: Mar 2012
Posts: 30
Thanks: 1
Thanked 0 Times in 0 Posts
trantommyd is an unknown quantity at this point
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."
trantommyd is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:39 AM.


Advertisement
Log in to turn off these ads.