DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3

Hybrid View

  1. #1
    Join Date
    Apr 2005
    Posts
    4

    Question JComboBox and IF Statement

    Hello,

    I am new to Java, and have been trying to make a program for my college course. I have come to a bit of a dead end.

    I am trying to make a JComboBox that is linked to a If statement.

    e.g.

    I want to make a JComboBox with three options (Natural, Yorkstone and Clay) and then create an If statement for it like (pseudocode):

    if (JComboBox = Natural)
    type = 1;
    else if (JComboBox = Yorkstone);
    type = 2;
    else
    type = 3;


    Any ideas would be greatly appreceated.

    Thanks in advance.

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560

    I haven't "linked" the if statement...

    .. to anything here, but this should work
    Code:
    JComboBox box=new JComboBox();
    .
    .
    box.addItem("Natural");
    box.addItem("Yorkstone");
    box.addItem("Clay");
    . 
    .
    if (box.getSelectedItem().equals("Natural")) 
      type=1;
    if (box.getSelectedItem().equals("Yorkstone")) 
      type=2;
    if (box.getSelectedItem().equals("Clay")) 
      type=3;

  3. #3
    Join Date
    Apr 2005
    Posts
    4
    Thankyou very much, you have sorted my java problems, and saved me many hours. I am in debt to you.

    Thanks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links