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 03-01-2013, 06:08 PM   PM User | #1
nervousprogramm
New Coder

 
Join Date: Oct 2012
Posts: 28
Thanks: 17
Thanked 0 Times in 0 Posts
nervousprogramm is an unknown quantity at this point
Help with selecting options in java

Hi im new to the java language.

import javax.swing.JOptionPane;

public class TravelAgentSystem {

public static void main(String[] args) {
// Local variable declared
int selectValue;

// Main Menu is displayed

System.out.println("| Flight Travel Systems |");
System.out.println("|--------------------------|");
System.out.println("| Options: |");
System.out.println("| 1. Time |");
System.out.println("| 2. Price |");
System.out.println("| 3. Hotels |");
System.out.println("| 4. End |");
System.out.println("============================") ;

selectValue();

}
public static void selectValue()
{

int choice = -1;
while(choice < 0)
{
String input = JOptionPane.showInputDialog("Please select an option: ");
}

}
}

I want to make it so when i select an option such as 1, it will take me to a new option where i can display more infomation.
Anyone know how i can go about doing this?
nervousprogramm is offline   Reply With Quote
Old 03-01-2013, 06:29 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
That's wierd; you're combining gui and cli for io?
The input within the selectValue method will contain the value entered into the option dialog. Cast that to an integer with Integer.parseInt and assign it to the choice. Then switch on the choice to determine what to do next.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
nervousprogramm (03-01-2013)
Old 03-01-2013, 06:41 PM   PM User | #3
nervousprogramm
New Coder

 
Join Date: Oct 2012
Posts: 28
Thanks: 17
Thanked 0 Times in 0 Posts
nervousprogramm is an unknown quantity at this point
Quote:
Originally Posted by Fou-Lu View Post
That's wierd; you're combining gui and cli for io?
The input within the selectValue method will contain the value entered into the option dialog. Cast that to an integer with Integer.parseInt and assign it to the choice. Then switch on the choice to determine what to do next.
At the moment im just sticking to basics so would using scanner be more easier?

also this is what ive done is it correct??

import javax.swing.JOptionPane;

public class TravelAgentSystem {

public static void main(String[] args) {
// Local variable declared
int selectValue;

// Main Menu is displayed

System.out.println("| Flight Travel Systems |");
System.out.println("|--------------------------|");
System.out.println("| Options: |");
System.out.println("| 1. Time |");
System.out.println("| 2. Price |");
System.out.println("| 3. Hotels |");
System.out.println("| 4. End |");
System.out.println("============================");

selectValue();

}
public static void selectValue()
{

int choice = -1;
while(choice < 0)
{
String input = JOptionPane.showInputDialog("Please select an option: ");
if (input.equals("1")){
System.out.println("fdsfds");
}
else if (input.equals("2")){
System.out.println("ggfdgd " );
}
else if (input.equals("3")){
System.out.println("hgfdhgf " );
}
else if (input.equals("4")){
System.out.println("nhgdhd " );
}
else {
JOptionPane.showMessageDialog(null, "User error,please select an option");

}

}
}
}



i need to change the system to options but at the moment the concept seems baffling. If i select 1 i want to bring up an array of flights in which can be selected
nervousprogramm is offline   Reply With Quote
Old 03-01-2013, 06:58 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Yeah more or less.
I'd use the scanner and keep the components separate. If you want to use JOptionPane, I'd use that in conjunction with a frame instead of with the cli.
The while loop won't end though, so you'll need to do something with the choice variable. Or change it to something like a do/while with a boolean control and simply default it to not loop and simply swap it to loop if entry is no good.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
nervousprogramm (03-01-2013)
Old 03-01-2013, 07:15 PM   PM User | #5
nervousprogramm
New Coder

 
Join Date: Oct 2012
Posts: 28
Thanks: 17
Thanked 0 Times in 0 Posts
nervousprogramm is an unknown quantity at this point
Quote:
Originally Posted by Fou-Lu View Post
Yeah more or less.
I'd use the scanner and keep the components separate. If you want to use JOptionPane, I'd use that in conjunction with a frame instead of with the cli.
The while loop won't end though, so you'll need to do something with the choice variable. Or change it to something like a do/while with a boolean control and simply default it to not loop and simply swap it to loop if entry is no good.
Kk im going to convert it to CLI and then when i finish i will convert to GUI to get a better understanding. Thanks for the help, i need a nice break lol.
nervousprogramm 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 04:35 AM.


Advertisement
Log in to turn off these ads.