473,442 Members | 3,148 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

GUI ComboBox Opens Other GUIs

63
Hey, I have a problem which I need to resolve for my project. I want to open a different GUI class based on the selection made from a combobox:
Expand|Select|Wrap|Line Numbers
  1.  public void actionPerformed(ActionEvent event) { 
  2.          JComboBox comboBox = (JComboBox)event.getSource(); 
  3.          String selection = (String)comboBox.getSelectedItem(); 
  4.          if (selection == "Price Elasticity of Demand") { 
  5.             runGUI 
  6.          } 
  7.  
How can I do this in java ?
Furthermore, how can i call a method from a different class when a button is clicked ?

Cheers in advance ;)
Nov 25 '08 #1
1 2375
Nepomuk
3,112 Expert 2GB
@MiziaQ
First of all, you don't compare Strings like that in Java. Try
Expand|Select|Wrap|Line Numbers
  1. selection.equals("Price Elasticity of Demand")
instead.

Then, your idea seems to be good: use if's and elses. So for example:
Expand|Select|Wrap|Line Numbers
  1. String selection = (String)comboBox.getSelectedItem(); 
  2. if (selection.equals("First option")) { 
  3.    runGUI1();
  4. } else if (selection.equals("Second option")) { 
  5.   runGUI2();
  6. } else if (selection.equals("Third option")) { 
  7.   runGUI3();
  8. } // etc.
Greetings,
Nepomuk
Nov 25 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Steve | last post by:
I have an unbound combobox in the form header of a continuous form. The selection in the combobox sets the where clause in a querydef which determines QryPFrmInventoryManagement. The following code...
2
by: Tom | last post by:
I have the following tables: TblState StateID State TblCounty CountyID StateID County
6
by: dbuchanan | last post by:
VS2005 I've been reading all the help I can on the topic (MSDN, other) but I can't make sense of this. Desired behavior; The user is to choose from the displayed list of the databound combobox...
6
by: dbuchanan | last post by:
VS2005 I've been reading all the help I can on the topic (MSDN, other) but I can't make sense of this. Desired behavior; The user is to choose from the displayed list of the databound combobox...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.