Handling 2 DropDown Menus in same class...??

Hi,
As you can imagine I am new to this....and I'm having trouble creating 2 DropDown Menus in the same class...
The problem is the "public void itemStateChanged(ItemEvent e) "...the compiler doesn't let me have 2 of them...I can understand why since it needs to make the difference between the 2 DropDown Menus...but how do I do it? I've tryed "public void itemStateChanged(ItemEvent f) " but java doesn't like it either...
Here is my code (note that without the second DropDown "ChoicePeople" it works just fine):
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.util.*;
public class Booking extends Applet implements ItemListener
String[][] c = { {"French Language","250","130","70"}, {"Painting","270","140","70"},
{"Yoga","250","130","70"} };
Courses courses_list = new Courses(c);
Choice ChoiceCourse;
public void init()
  add(new Label("Courses available for booking : "));
  ChoiceCourse = new Choice();
  add(ChoiceCourse);
  int i=0;
  while (i<c.length)
    ChoiceCourse.addItem(courses_list.getTitle(i));
    i++;
  ChoiceCourse.addItemListener(this);
public void itemStateChanged(ItemEvent e)
  String c1 = (String) e.getItem();
  add(new Label("Number of participants for the course selected : "));
  ChoicePeople = new Choice();
  add(ChoicePeople);
  int j=0;
  while (j<11)
    ChoicePeople.addItem(j);
    i++;
  ChoicePeople.addItemListener(this);
public void itemStateChanged(ItemEvent e)
  int p1 = (int) e.getItem();
}

I can't view my Applet via the AppletViewer anymore....
My classes compile just fine but when I try to view the applet I get stuck on "Applet Loaded" and even if I try to start it nothing happens...
It worked fine until I added the second DropDown Menu (ChoicePeople) and the if statements in the itemStateChanged as you'll see in my code below...I guess I've done something wrong there...but What?
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.util.*;
public class Booking extends Applet implements ItemListener
String[][] c = { {"French Language","250","130","70"}, {"Painting","270","140","70"}, {"Yoga","250","130","70"} };
Courses courses_list = new Courses(c);
Choice ChoiceCourse;
Choice ChoicePeople;
public void init()
  add(new Label("Courses available for booking : "));
  ChoiceCourse = new Choice();
  add(ChoiceCourse);
//the following populates the ChoiceCourse dropDown Menu with the Courses'Titles
  int i=0;
  while (i<c.length)
    ChoiceCourse.addItem(courses_list.getTitle(i));
    i++;
  ChoiceCourse.addItemListener(this);
  add(new Label("Number of participants for the course selected : "));
  ChoicePeople = new Choice();
  add(ChoicePeople);
//the following populates the ChoicePeople dropDown Menu with "numbers" from 1 to 10
  int j=1;
  while (j<11)
    ChoicePeople.addItem("j");
    i++;
  ChoicePeople.addItemListener(this);
public void itemStateChanged(ItemEvent e)
  if (e.getSource() == ChoiceCourse)
    String c1 = (String) e.getItem();  // When ChoiceCourse is modified
  if (e.getSource() == ChoicePeople)
    String p2 = (String) e.getItem();  // When ChoicePeople is modified
    int p1=Integer.parseInt(p2);       // converts the String into an integer
}

Similar Messages

  • How can I create secondary and tertiary dropdown menus whose choices are dependant on the parent?

    Kind of a weird question; I know. I'm new to both the Adobe Developer forums, and to XMP in general.
    Here's the basic gist of what I'm trying to do:
    We've got a Group, Category, and Subcategory structure for a given variable. Obviously, the subcategories are unique to a particular category, just as the categories are unique to a particular group; so displayed as a tree:
    I.     Group_1
              1. Category_1A
                        a. Subcategory_1Ax
                        b. Subcategory_1Ay
                        c. Subcategory_1Az
              2. Category_1B
                        a. Subcategory_1Bx
                        b. Subcategory_1By
                        c. Subcategory_1Bz
              3. Category_1C
                        a. Subcategory_1Cx
                        b. Subcategory_1Cy
                        c. Subcategory_1Cz
    II.     Group_2
              1. Category_2A
                        a. Subcategory_2Ax
                        b. Subcategory_2Ay
                        c. Subcategory_2Az
              2. Category_2B
                        a. Subcategory_2Bx
                        b. Subcategory_2By
                        c. Subcategory_2Bz
              3. Category_2C
                        a. Subcategory_2Cx
                        b. Subcategory_2Cy
                        c. Subcategory_2Cz
    The subcategories are unique to their categories; just as the categories are unique to their groups. In an effort to prevent garbage coming into the metadata, and because these groups, categories, and subcategories have already been defined, I'd like them displayed as dropdown menus; Once the user has selected a group for the file, the Category dropdown would appear (or become active) and display the Category choices available only to that group, and then do the same in terms of the Subcategory.
    I'm guessing that I'll start with a closed choice, assign the values to the groups, and then write a function to display only the choices for that group in the category dropdown. Trouble is, I don't have a whole lot of JavaScript experience -- and the word I've seen tossed around in this area seems to be an Array -- so I'm wondering if I'm barking up the wrong tree. If anyone has some kind of direction to point me in, it'd be helpful.
    I'm not looking for someone to do my work for me (that's missing the point) -- this is an exercise in learning XML, Some scripting, Flash Builder, and Javascript, and I'd really like to develop it entirely myself; because I am having fun!!
    Many thanks,
    .themumm

    Do you mean the stuff from here:
    http://projects.nateweiss.com/nwdc/workcode.htm
    If so, to be honest, don't ("use it", I mean).
    It might have been a reasonable approach to this sort of thing ten years ago, but it's not a very good way of doing this sort of thing these days.
    This sort of thing is pretty easy to knock together with some HTML, JQuery to do some JS stuff and a CFC behind the scenes.
    Indeed just using some binds to <cfselect> tags would be a better approach.
    Adam

  • How can I get my dropdown menus to work on Safari?

    I am in a real bind here. The blog I use for my class I teach has dropdown menus, but these don't seem to work in Safari on iPad. They work just fine in Chrome, but our lovely school blocks the Chrome browser...Don't even get me started.
    Is there something I could add to the code to get these menus to work in Safari on iPad?
    The blog URL is stmlatin2020.blogspot.com
    Thanks

    Try this ...
    Tap Settings > Safari > Advanced then make sure JavaScript is switched ON.
    That site is not optimized for iOS devices. Only browsers on desktop computers suport CSS (drop down menus).

  • Under "Basic" in the "Printer Settings" of the Print menu, the dropdown menus for both "Page Setup: Sheet" and "Media Type" are frozen.

    Frozen selections: I'm working from my Intel iMac trying to print (from both Aperture and Photoshop CS5) to my new Epson 4900 printer. When the Print menu comes up, under the "Basic" section of the "Printer Settings" the dropdown menus for both "Page Setup" and "Media Type" won't activate. All other options and selections work fine. Just these 2 are not functioning. What's up with that??

    Here we are 15 months later and Microsoft Excel 2013 has the SAME ERROR
    If one chooses:
    Print Preview
    Page Setup
    Sheet
    Then the print area and print titles (Rows to repeat at top, columns to repeat at top)
    are all grayed out and cannot be selected.
    If, however, I choose the
    page layout bar and click print titles then
    everything works fine.
    Thanks for the solution!!!

  • Multiple windows of the same class with a different argument

    Suppose I have a main window with a list of users. If I click on any one user, the "chat window" should open with the argument as that "user".
    If i click on another, a similar "chat window" should open but with a different user.
    I can't have so many stages because I don't know how many users are there.
    How do I open multiple windows of the same class but with a different argument?

    Here is a sample (opens, at random locations, a bunch of child windows parameterized by color).
    Could be simpler, but hopefully you get the gist.
    import java.util.Random;
    import javafx.application.Application;
    import javafx.geometry.Rectangle2D;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.layout.StackPane;
    import javafx.stage.*;
    public class ColoredStages extends Application {
      final String[] colors = { "firebrick", "palegreen", "azure", "chocolate", "goldenrod" };
      final Random random = new Random(42);
      Rectangle2D screenBounds;
      public static void main(String[] args) { launch(args); }
      @Override public void start(Stage stage) {
        screenBounds = Screen.getPrimary().getVisualBounds();
        stage.setTitle("Primary");
        stage.setScene(new ColoredScene("cornsilk"));
        stage.show();
        for (String color : colors) {
          Stage coloredStage = new ColoredStage(stage, color);
          coloredStage.show();
      class ColoredStage extends Stage {
        ColoredStage(Stage owner, String color) {
          super();
          initOwner(owner);
          initStyle(StageStyle.UTILITY);
          setX(screenBounds.getMinX() + random.nextInt((int) screenBounds.getWidth()));
          setY(screenBounds.getMinY() + random.nextInt((int) screenBounds.getHeight()));
          setScene(new ColoredScene(color));
      class ColoredScene extends Scene {
        ColoredScene(String color) {
          super(new StackPane());
          StackPane layout = (StackPane) getRoot();
          layout.getChildren().addAll(new Label(color));
          layout.setStyle("-fx-font-size: 20px; -fx-padding: 30px; -fx-background-color: " + color);
    }

  • Accessing a private variable from a public method of the same class

    can anyone please tell me how to access a private variable, declared in a private method from a public method of the same class?
    here is the code, i'm trying to get the variable int[][][] grids.
    public static int[][] generateS(boolean[][] constraints)
      private static int[][][] sudokuGrids()
        int[][][] grids; // array of arrays!
        grids = new int[][][]
        {

    Are you sure that you want to have everything static here? You're possibly throwing away all the object-oriented goodness that java has to offer.
    Anyway, it seems to me that you can't get to that variable because it is buried within a method -- think scoping rules. I think that if you want to get at that variable your program design may be under the weather and may benefit from a significant refactoring in an OOP-manner.
    If you need more specific help, then ask away, but give us more information please about what you are trying to accomplish here and how you want to do this. Good luck.
    Pete
    Edited by: petes1234 on Nov 16, 2007 7:51 PM

  • Two threads in the same class ? Is that possible ?

    Hello, I am trying to use threads to move two images around the frame. And I am wondering if it is possible if it is possible to create two separate threads that act differently in the same class, for each of the image.
    Is just that so far I can't see a way since, by implementing Runnable, I'll need to overwrite the run() method. Which in a way just allows me to manage one image.
    Of course I can do two separate classes (each implementing Runnable) for each of the image, but since I think it may be an overkill, I rather to do it in just one.
    So, is that possible ?
    Thank you in advance.

    Of course I can do two separate classes (each implementing Runnable) for each of the image,Use two instances of the same class. Something like this example:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=631379

  • After use and not even long use dropdown menus are blank, Firefox won't close.

    For a couple of weeks after a short time of use dropdown menus are blank almost as if they have been lifted off the screen but I can see an imprint of where they should be.. Sometimes running the cursor over them seems to make them appear but not often.
    When this happens I cannot close Firefox.
    == This happened ==
    Every time Firefox opened
    == a couple of weeks ago

    From your description, it seems that an add-on may me causing your issue. Follow the steps at [[Troubleshooting extensions and themes]] to test whether your extensions are causing this behavior. Reply back here with the results and with the name(s) of any extensions you have enabled.

  • Muse dropdown menus won't "hide" in design phase

    Suddenly (since downloading v3.0), when I'm in design mode, ALL of my dropdown menus are showing. Before, they'd do that every time I made a change to the menu, but I could go onto my master page and click a menu item that DIDN'T have a dropdown and they'd go away so that I could design without having them "in my face." But now, they're just there and I can't seem to get rid of them. Anyone else having this problem? Is there something I can do to hide the dropdowns while I'm designing?

    Yes. That and more.
    I want the top menus to be horizontal, when I scroll over them, I want the sub menu to scroll down horizontally if there are more than one sub menu, it won’t do that.
    All sub menus should drop down under the top menus so you can see three of them if there are there, four or five.
    Currently if I have a top menu of five items each one has say three submenus under each top menu, when I scroll over the top menu the sub menu roll out horizontally and the other two don’t show up until I actually scroll over the one submenu then the other submenu pops out one at a time.
    On top of all this the original post says menus won’t hide in design phase, making it all that much more frustrating.
    For goodness sake “it it ain’t broke don’t fix it!” Don’t assume that if something is obvious to one person is obvious to everyone else.

  • Referencing fields between objects of same class

    Say I have created multiple TicketMachines from this class. Is there a way I create a method that uses "System.out.println" that would print the price of another TicketMachine object. And if so, could you please point me in the direction to find out how.
    * TicketMachine models a naive ticket machine that issues
    * flat-fare tickets.
    * The price of a ticket is specified via the constructor.
    * It is a naive machine in the sense that it trusts its users
    * to insert enough money before trying to print a ticket.
    * It also assumes that users enter sensible amounts.
    * @author David J. Barnes and Michael Kolling
    * @version 2006.03.30
    public class TicketMachine
        // The price of a ticket from this machine.
        private int price;
        // The amount of money entered by a customer so far.
        private int balance;
        // The total amount of money collected by this machine.
        private int total;
        //Creates a machine that issues tickets at a default price of 1000.
        public TicketMachine( )
         //Exercise 2.39  & 2.42(continues below)
          * By removing the parameter from this constructer
          * and setting the value of price to 1000, objects
          * from this class are automatically constructed with
          * a ticket price of 1000.
            price = 1000;
            balance = 0;
            total = 0;
        //Exercise 2.42
         * Create a machine that issues tickets of the given price.
         * Note that the price must be greater than zero, and there
         * are no checks to ensure this.
        public TicketMachine(int thePrice)
            price = thePrice;
            balance = 0;
            total = 0;
         * Return the price of a ticket.
        public int getPrice()
            return price;
         * Return the amount of money already inserted for the
         * next ticket.
        public int getBalance()
            return balance;
         * Receive an amount of money in cents from a customer.
        public void insertMoney(int amount)
            balance = balance + amount;
         * Print a ticket.
         * Update the total collected and
         * reduce the balance to zero.
        public void printTicket()
            // Simulate the printing of a ticket.
            System.out.println("##################");
            System.out.println("# The BlueJ Line");
            System.out.println("# Ticket");
            System.out.println("# " + price + " cents.");
            System.out.println("##################");
            System.out.println();
            // Update the total collected with the balance.
            total = total + balance;
            // Clear the balance.
            balance = 0;
        //Exercise 2.33
        //Prints "Please insert the correct amount of money." to the text terminal.
        public void prompt()
            System.out.println("Please insert the correct amount of money.");
        //Exercise 2.34
        //Displays the value of the price field in the text terminal.
        public void showPrice()
            System.out.println("The price of a ticket is " + price + " cents.");
        //Exercise 2.35
         * After creating two ticket machines with different prices
         * and calling thier showPrice methods it showed a different
         * output for each instance. This effect happenes because the
         * showPrice method prints out a string and the value of the price
         * field, which happens to be different in each instance, thereby
         * printing a different output.
        //Exercise 2.36
         * The result of System.out.println("# " + "price" + " cents.");
         * would print the string "# price cents." to the text terminal.
        //Exercise 2.37
         * The result of System.out.println("# price cents.");
         * would be the same as the result of exercise 2.36.
        //Exercise 2.40
        //This method is a mutator and takes no parameters
        //Empties the money form the ticket machine
        public void empty()
            total = 0;
        //Exercise 2.41
        //This method is a mutator
        //Changes the price of a ticket
        public void setPrice(int newPrice)
            price = newPrice;
    }

    Objects can refer to fields in other objects of the same class.
    It's not clear from your description what you're trying to accomplish, however.

  • How to use ActionListener and ItemListener in the same class

    Why can't I use both ActionListener and ItemListener in the same Class?
    I want to use a drop down list and an entry box on the same form.
    How? I'm having trouble compling......
    Thanks!
    CODE:
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Disp extends Applet implements ActionListener, ItemListener
    { TextField entry=new TextField(7);
    Button Enter=new Button("Enter");
    public void init()
    add(entry);
    add(Enter);
    entry.addActionListener(this);
    entry.requestFocus();
    Enter.addActionListener(this);
    public void actionPerformed(ActionEvent thisEvent)
    String answer=entry.getText();

    Simply get your Applet to implement both ActionListener and ItemListener.
    public class MyApplet extends Applet implements ActionListener, ItemListener
      public void init()
        itemWidget.addItemListener(this):
        actionWidget.addActionListener(this);
      public void actionPerformed(ActionEvent e)
        System.out.println("ACTION PERFORMED!");
      public void itemStateChanged(ItemEvent e)
        System.out.println("ITEM STATE CHANGED!");
    }Hope this helps.

  • How to create an object within the same class???

    hi im just a newbie
    i v been always creating an object from the main class..
    but how to create an object inside the same class??
    i got main and students class
    the main got an array
    Students[] stu = new Students[]
    and i got
    stu[i] = new Students(id,name);
    i++;
    but i wanna do these things inside the Students class..
    i tried ..but i got errors.....
    how to do this
    .

    javaexpert, :)
    I really have no idea what you are trying to do since you say you've always been creating an object from the main class, yet you always want to create an object inside the same class.
    I'll assume that you have an object in the main class that you are trying to access from the Students class.
    If you are trying to access objects that are contained within the main class FROM the Students class, then know that there are two ways of doing so, one being static, and the other dynamic (look up definitions if unclear):
    1.) make the objects in the main class both static and public and access the the objects using a convention similiar to: Main.object; It's important to note that Main is the name of your main class, and object is a static object. There are better ways of doing this by using gettter/setter methods, but I'll omit that tutorial.
    2.) Create a new instance of the main class and access the objects using a similiar fashion: Main myInstance = new Main(); myInstance.myObject;
    You should really use getter and setter methods but I'll omit the code. In terms of which approach is better, step one is by far.
    I don't mean to be condecending, but you should really brush up on your programming skills before posting to this forum. This is a fundamenetal concept that you will encounter time and time again.

  • Synchronisation methods in same class

    I have three methods in same class A,B,C IN which A,B synchronised and c not.
    my question is if one thread is in A.another thread cann access B OR C?

    jverd wrote:
    Syncing a block on the object pointed to by X
    synchronized (X) { /* do stuff */}simply waits until no other thread is synced on that object, and then enters the block.
    Declaring a non-static method synchronized is the same as doing synchronized (this) { /* do stuff */ }Calling a non-synced method or executing a non-synced block or statement does not wait for the lock.Duke-wh0ring?? :)

  • How to convert the class in the one package to same class in the other pack

    How to convert the class in the one package to same class in the other package
    example:
    BeanDTO.java
    package cho3.hello.bean;
    public class BeanDTO {
    private String name;
    private int age;
    * @return
    public int getAge() {
         return age;
    * @return
    public String getName() {
         return name;
    * @param i
    public void setAge(int i) {
         age = i;
    * @param string
    public void setName(String string) {
         name = string;
    BeanDTO.java in other package
    package ch03.hello;
    public class BeanDTO {
    private String name;
    private int age;
    * @return
    public int getAge() {
         return age;
    * @return
    public String getName() {
         return name;
    * @param i
    public void setAge(int i) {
         age = i;
    * @param string
    public void setName(String string) {
         name = string;
    My converter lass lokks like
    public class BeanUtilTest {
         public static void main(String[] args) {
              try
                   ch03.hello.BeanDTO bean=new ch03.hello.BeanDTO();
              bean.setAge(10);
              bean.setName("mahesh");
              cho3.hello.bean.BeanDTO beanDto=new cho3.hello.bean.BeanDTO();
              ClassConverter classconv=new ClassConverter();
              //classconv.
              System.out.println("hi "+beanDto.getClass().toString());
              System.out.println("hi helli "+bean.toString()+" "+bean.getAge()+" "+bean.getName()+" "+bean.getClass());
              Object b=classconv.convert(beanDto.getClass(),(Object)bean);
              System.out.println(b.toString());
              beanDto= (cho3.hello.bean.BeanDTO)b;
              System.out.println(" "+beanDto.getAge()+" "+beanDto.getName() );
              }catch(Exception e)
                   e.printStackTrace();
    But its giving class cast exception. Please help on this..

    Do you mean "two different layers" as in separate JVMs or "two different layers" as in functional areas running within the same JVM.
    In either case, if the first class is actually semantically and functionally the same as the second (and they are always intended to be the same) then import and and use the first class in place of the second. That's beyond any question of how to get the data of the first into the second if and when you need to.
    Once you make the breakthrough and use one class instead of two I'd guess that almost solves your problem. But if you want to describe your architecture a little that would help others pin down want you're trying to do.

  • Passing values between methods in the same class

    Hi,
    How to pass internal tables or values between methods in the same class.
    How to check if the internal method in another method is initial or not.
    How to see if the method has already been executed.
    Thanks.

    Just declare the internal table as an attribute in the class - that way every method in this class has access to it.
    Since any method has access to all class attributes you can easily check if the internal table is initial or not.
    I am not aware of any standard functionality if a method has already been executed or not, one way would be to declare a class attribute for each method and set it once the method has been executed. That way every method in that class would know which method has already been executed or not.
    Hope that helps,
    Michael

Maybe you are looking for