AddActionListener and Choice class

Hello,
I'm using the Choice class to create my drop down list/menu. After researching the Choice class and the methods they have, (I've tried all of the getters) and the select(), to pinpoint which item in the drop down list the user has selected to have certain text display. Here's what I've coded in the if statement (that if the user selects this item from the drop down, this will happen) in the displayAllRoomsOnFloor() but the computer isn't happy with it. The error says: "{color:#ff6600}The method getItem(int) in the type Choice is not applicable for the arguments(){color}". I still don't know what method in the Choice class I'm supposed to use to figure out which item the user has selected. Please help!
Here's my code:
public class Hotel{
Panel inputPanel = new Panel();
TextArea roomDisplay[] = new TextArea[16];
Button displayRoomsOnFloor = new Button("Get Floor Info");
Choice floorNumber = new Choice();
public Hotel()
inputPanel.add(floorNumber);
for(int i=1; int<4;i++)
floorNumber.add(String.valueOf(i));
displayRoomsOnFloor.addActionListener(this);
public void displayAllRoomsOnFloor()
if(floorNumber.getItem()==1)
roomDisplay+.setText("Room 101:");+
+}+
+}+
+public void actionPerformed(ActionEvent e)+
+{+
+String arg == e.getActionCommand();+
+if (arg == "Get Floor Info");+
+displayAllRoomsOnFloor();+
+}+
+}//end of Hotel class+
++

You want to see which one the user selected, and it didn't occur to you to use the getSelectedItem or getSelectedIndex method?
On another note:
getItem takes an integer argument, and you're not passing it any, so that explains the error message (though the original error message should suffice).

Similar Messages

  • Annonymous and inner classes

    Hello,
    Can anyone tell me what the benefits of anonymous and inner classes are? inner classes are seem pretty complicated without any obvious benefit.
    I have read about these in books and have some understanding of them but these don't appear to have any benefits.
    Any info on either would be really cool.
    regards

    There are many places where inner classes can be useful. One place where anonymous inner classes are particularly neat is for ActionListeners. For example, compare the "normal" way of doing it:
         for(int i = 0; i < 2; i++)
              JButton button = new JButton("Button " + i);
              button.setActionCommand("ACTION" + i);
              button.addActionListener(this);
         public void actionPerformed(ActionEvent e)
              if("ACTION0".equals(e.getActionCommand()))
                   doSomething(0);
              else if("ACTION1".equals(e.getActionCommand()))
                   doSomething(1);
         }with the way using anonymous inner classes:
         for(int i = 0; i < 2; i++)
              final int index = i;
              JButton button = new JButton("Button " + index);
              button.addActionListener(new ActionListener()
                        public void actionPerformed(ActionEvent e)
                             doSomething(index);
         .In the first case you need a global actionPerformed method with some if statements inside. If there are many types of action then this can quickly become very large and error-prone. In the second case, each action is handled in its own class, right with the button that it's associated with. This is easier to maintain. Note that local variables must be declared final to be accessible from the inner class.

  • How to find master data info objects. Partner function and customer class.

    hi,
    Can you please tell me what are the available extractors for Partner Function (PARVW from VBPA)and Customer Class (KUKLA from KNA1).
    I hope these fields are master data. I checked in 0customer. But I didn't find it. There is a info object (Business partner). Is it the same?
    pls reply

    I will admit that I am not familiar with ECC and there may be different interpretations of what KUKLA means and different means of extracting Customer information to/from ECC.
    However, for us, when extracting Customer Attributes using the 0CUSTOMER_ATTR datasource in R/3, we map KUKLA to 0CUST_CLASS.  They are both set up as 2 CHAR.  That is not to say that you should also.  You can map it to a custom infoobject in BW as long as you set it up as an attribute of 0CUSTOMER.  KUKLA is available in the standard datasource 0CUSTOMER_ATTR in R/3.  When looking at what is available in the infosource for 0CUSTOMER in BW, 0CUST_CLASS is a logical choice to map.
    As far as VBPA-PARVW, VBPA is not a source for master data for 0BPARTNER.  VBPA contains the business partners associated with Sales documents.  So if you are going to create a data provider (cube/ODS) in BW and VBPA-PARVW is part of the transactional datasource in R/3, the you can map it to 0BPARTNER in your cube/ODS.
    Hope this helps.

  • AddActionListener and addItemListener

    Hi all, i am quite new to Java and kinda stuck somewhere
    for my program.
    public class DinerMenu extends Applet implements ItemListenerIs it possible to put the addActionListener and addItemListener together in a program??? As I wanted to include some calculation into the addActionListener but I don't know how to do it. Can somebody advise???
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    public class DinerMenu extends Applet implements ItemListener
         Label companyName = new Label("Anwar's Diner Menu");
         Label price = new Label("Dinner Price is $0");
         String priceString = new String();
         Font bigFont = new Font("Arial",Font.PLAIN,28);
         Font littleFont = new Font("Arial", Font.PLAIN,16);
         int totalPrice = 0;
         CheckboxGroup soupGrp = new CheckboxGroup();
         Checkbox soup1 = new Checkbox("Tomato",false,soupGrp);
         Checkbox soup2 = new Checkbox("Vegetable",false,soupGrp);
         Checkbox soup3 = new Checkbox("Lemon Rice",false,soupGrp);
         int soup1Price = 2,soup2Price = 3,soup3Price =4;
         CheckboxGroup entreeGrp = new CheckboxGroup();
         Checkbox entree1 = new Checkbox("Lamb",false,entreeGrp);
         Checkbox entree2 = new Checkbox("Eggplant",false,entreeGrp);
         Checkbox entree3 = new Checkbox("Beef",false,entreeGrp);
         int entree1Price = 12,entree2Price =9,entree3Price =15;
         Button WagePayable = new Button("Wage Payable");
         public void init()
              companyName.setFont(bigFont);
              add(companyName);
              add(soup1);
              soup1.addItemListener(this);
              add(soup2);
              soup2.addItemListener(this);
              add(soup3);
              soup3.addItemListener(this);
              add(entree1);
              entree1.addItemListener(this);
              add(entree2);
              entree2.addItemListener(this);
              add(entree3);
              entree3.addItemListener(this);
              price.setFont(littleFont);
              add(WagePayable);
              WagePayable.addActionListener(this);
              add(price);
         public void itemStateChanged(ItemEvent check)
              totalPrice =0;
              if(soup1.getState())totalPrice += soup1Price;
              if(soup2.getState())totalPrice += soup2Price;
              if(soup3.getState())totalPrice += soup3Price;
              if(entree1.getState())totalPrice += entree1Price;
              if(entree2.getState())totalPrice += entree2Price;
              if(entree3.getState())totalPrice += entree3Price;
              remove(price);
              priceString = ("Dinner Price is $"+Integer.toString(totalPrice));
              price.setText(priceString);
              price.setFont(littleFont);
              add(price);

    I think you're quite close to the solution you want. If it's possible to have tomato and beef for $17, but not tomato and lemon rice, try this:
    Actually, you don't need the ItemListener. You collect the information and then you press your button for calculation. As it was pointed out in the other post, implement the Interface ActionListener:public class DinerMenu extends Applet implements ActionListener {} Now the compiler complains about the inherited but not implemented method actionPerformed. Implement this: public void actionPerformed(ActionEvent e) {
         // maybe you'll have more buttons     
         Object obj = e.getSource();
         if (obj == WagePayable) {
              // just a copy of your itemStateChanged method
              totalPrice =0;
              if(soup1.getState())totalPrice += soup1Price;
              if(soup2.getState())totalPrice += soup2Price;
              if(soup3.getState())totalPrice += soup3Price;
              if(entree1.getState())totalPrice += entree1Price;
              if(entree2.getState())totalPrice += entree2Price;
              if(entree3.getState())totalPrice += entree3Price;
              remove(price);
              priceString = ("Dinner Price is $"+Integer.toString(totalPrice));
              price.setText(priceString);
              price.setFont(littleFont);
              add(price);
    } Your init method might look like this:public void init() {
         companyName.setFont(bigFont);
         add(companyName);
         add(soup1);
         add(soup2);
         add(soup3);
         add(entree1);
         add(entree2);
         add(entree3);
         price.setFont(littleFont);
         add(WagePayable);
         WagePayable.addActionListener(this);
         add(price);
    }Kill your itemStateChanged method (you don't need it, but you can keep it, if you have implemented ItemListener). You can implement as many Listeners as you want, but than you have to implement all the inherited methods. If you override these methods, your application will do what you wrote into these methods (hopefully) when the event fires.

  • Using Timer and TimerTask classes in EJB's(J2EE)

    Does J2EE allow us to use Timer and TimerTask classes from java.util package in SessionBean EJB's ( Statless or Statefull )?.
    If J2EE does allow, I am not sure how things work in practical, Lets take simple example where a stateless SessionBean creates a Timer class
    and schedules a task to be executed after 5 hours and returns. Assuming
    GC kicks in many times in 5 hours, I wonder if the Timer object created by survives the GC run's so that it can execute the scheduled tasks.
    My gut feeling says that the Timer Object will not survive.. Just
    want to confirm that.
    I will be interested to know If there are any techiniques that can make
    the usage of Timer and TimeTask classes in EJB's possible as well as reliable with minmum impact on over all performance.

    Have a look at J2EE 1.4. I think they add a timer service for EJBs there...
    Kai

  • Whats the difference between an INTERFACE and a CLASS?

    Whats the difference between an INTERFACE and a CLASS?
    Please help.
    Thanx.

    http://search.java.sun.com/search/java/index.jsp?col=javaforums&qp=%2Bforum%3A31&qt=Difference+between+interface+and+class

  • Page Attributes and Application Class Attributes

    Hi, everyone,
    I am quite new to BSP.
    I have a question here:
    what is the difference between page attributes and application class attributes of a bsp application? As they are both global attributes, there seems to be no big difference when we use them.
    thanks a lot.
    Fan

    Hi Fan,
    a BSP application can be made up of many pages.
    A page attribute is visible only in the page it is associated with.
    Attributes of the application class are visible from every page in that application.
    Cheers
    Graham Robbo

  • What is the difference between document class and normal class

    Hi,
    Please let me know what is the difference between document class and normal class.
    And I have no idea which class should call as document class or call as an object.
    Thanks
    -Actionscript Developer

    the document class is invoked immediately when your swf opens.  the document class must subclass the sprite or movieclip class.
    all other classes are invoked explicitly with code and need not subclass any other class.

  • How to get the jar file without knowing its name and any class inside it?

    Hello, everybody!
    I would like to know if there's a way to get a reference programatically to the initial jar without knowing its name and any class contained in it. By "initial jar" I mean the jar that was called in the prompt, like this:
    java -jar jarfile.jaror in another way, in a graphical system. To be sincere what I really want is to get a reference to the jar's manifest, but I know if I can get a reference to the jar I can get a reference to its manifest file. Or if you know a way to get the manifest directly, it would also help. So, is there a way to do this?
    Thank you.
    Marcos

    jverd wrote:
    marcos_aps wrote:
    abillconsl wrote:
    Can you be more specific - IOW, can you cite a specific case?Absolutely. I want to access the jar in source code with the java.util.zip.JarFile class, for example.But why? You still haven't provided a use case or explained what you're trying to accomplish. As already pointed out, whatever you're trying to do, this is a brittle solution. If you explain what you're trying to accomplish with this, somebody may be able to suggest a better approach.jverd, I explained for baftos. Anyway, I will try to be more specific. I start my sytem like this, from, say, for example, jar1.jar:
    import br.product.System;
    public static void main(String[] args)
        System.start("NameOfTheSystem");
    }The System class is in util.jar, for example. This jar is used by all systems. I wouldn't like to pass in the name of the system, as above. I would like that the System class could read it from jar1.jar's manifest file. I just would like to have this:
    import br.product.System;
    public static void main(String[] args)
        System.start();
    }It is more elegant and I don't have the name of the system in two places: code and manifest file.
    Marcos

  • Problem in generic value copier class / reflection and generic classes

    Hello experts,
    I try to archive the following and am struggling for quite some time now. Can someone please give an assessment if this is possible:
    I am trying to write a generic data copy method. It searches for all (parameterless) getter methods in the source object that have a corresponding setter method (with same name but prefixed by "set" instead of "get" and with exactly one parameter) in the destination object.
    For each pair I found I do the following: If the param of the setter type (T2) is assignable from the return type of the getter (T1), I just assign the value. If the types are not compatible, I want to instantiate a new instance of T2, assign it via the setter, and invoke copyData recursively on the object I get from the getter (as source) and the newly created instance (as destination). The assumption is here, that the occurring source and destination objects are incompatible but have matching getter and setter names and at the leaves of the object tree, the types of the getters and setters are compatible so that the recursion ends.
    The core of the problem I am struggling with is the step where I instantiate the new destination object. If T2 is a non-generic type, this is straightforward. However, imagine T1 and T2 are parametrized collections: T1 is List<T3> and T2 is List<T4>. Then I need special handling of the collection. I can easily iterate over the elements of the source List and get the types of the elements, but I can not instantiate only a generic version of the destinatino List. Further I cannot create elements of T4 and add it to the list of T2 and go into recursion, since the information that the inner type of the destination list is T4 is not available at run-time.
    public class Source {
       T1 getA();
       setA(T1 x);
    public class Dest {
       T2 getA();
       setA(T2 x);
    public class BeanDataCopier {
       public static void copyData(Object source, Object destination) {
          for (Method getterMethod : sourceGetterMethods) {
             ... // find matching getter and setter names
             Class sourceParamT = [class of return value of the getter];
             Class destParamT = [class of single param of the setter];
             // special handling for collections -  I could use some help here
             // if types are not compatible
             Object destParam = destination.getClass().newInstance();
             Object sourceParam = source.[invoke getter method];
             copyData(sourceParam, destParam);
    // usage of the method
    Souce s = new Source(); // this is an example, I do not know the type of s at copying time
    Dest d = new Dest(); // the same is true for d
    // initialize s in a complicated way (actually JAX-B does this)
    // copy values of s to d
    BeanDataCopier.copyData(s, d);
    // now d should have copied values from s Can you provide me with any alternative approaches to implement this "duck typing" behaviour on copying properties?
    Best regards,
    Patrik
    PS: You might have guessed my overall use case: I am sending an object tree over a web service. On the server side, the web service operation has a deeply nested object structure as the return type. On the client side, these resulting object tree has instances not of the original classes, but of client classes generated by axis. The original and generated classes are of different types but have the identically named getter and setter methods (which again have incompatible parameter types that however have consistent names). On the client side, I want to simply create an object of the original class and have the values of the client object (including the whole object tree) copied into it.
    Edited by: Patrik_Spiess on Sep 3, 2008 5:09 AM

    As I understand your use case this is already supported by Axis with beanMapping [http://ws.apache.org/axis/java/user-guide.html#EncodingYourBeansTheBeanSerializer]
    - Roy

  • Problems using different tables for base class and derived class

    I have a class named SuperProject and another class Project derived from
    it. If I let SchemaTool generate the tables without specifying a "table"
    extension, I get a single TABLE with all the columns from both classes and
    everything works fine. But if I specify a "table" for the derived class,
    SchemaTool generates the derived class with just one column (corresponds
    to the attribute in derived class). Also it causes problems in using the
    Project class in collection attributes.
    JDO file:
    <jdo>
    <package name="jdo">
    <class name="Project" identity-type="application"
    persistence-capable-superclass="SuperProject">
    <extension vendor-name="kodo" key="table" value="PROJECT"/>
    </class>
    <class name="SuperProject" identity-type="application"
    objectid-class="ProjectId">
    <field name="id" primary-key="true"/>
    </class>
    </package>
    </jdo>
    java classes:
    public class Project extends SuperProject
    String projectSpecific
    public class SuperProject
    BigDecimal id;
    String name;
    tables generated by SchemaTool:
    TABLE SUPERPROJECTSX (IDX, JDOCLASSX, JDOLOCKX, NAMEX);
    TABLE PROJECT(PROJECTSPECIFICX)
    Thanks,
    Justine Thomas

    Justine,
    This will be resolved in 2.3.4, to be released later this evening.
    -Patrick
    In article <aofo2q$mih$[email protected]>, Justine Thomas wrote:
    I have a class named SuperProject and another class Project derived from
    it. If I let SchemaTool generate the tables without specifying a "table"
    extension, I get a single TABLE with all the columns from both classes and
    everything works fine. But if I specify a "table" for the derived class,
    SchemaTool generates the derived class with just one column (corresponds
    to the attribute in derived class). Also it causes problems in using the
    Project class in collection attributes.
    JDO file:
    <jdo>
    <package name="jdo">
    <class name="Project" identity-type="application"
    persistence-capable-superclass="SuperProject">
    <extension vendor-name="kodo" key="table" value="PROJECT"/>
    </class>
    <class name="SuperProject" identity-type="application"
    objectid-class="ProjectId">
    <field name="id" primary-key="true"/>
    </class>
    </package>
    </jdo>
    java classes:
    public class Project extends SuperProject
    String projectSpecific
    public class SuperProject
    BigDecimal id;
    String name;
    tables generated by SchemaTool:
    TABLE SUPERPROJECTSX (IDX, JDOCLASSX, JDOLOCKX, NAMEX);
    TABLE PROJECT(PROJECTSPECIFICX)
    Thanks,
    Justine Thomas
    Patrick Linskey [email protected]
    SolarMetric Inc. http://www.solarmetric.com

  • Data class and Delivery class in ABAP Dictionary

    Hi all,
    I want to know the exact information about Data class and Delivery class in ABAP Dictionary
    Moderator message : Search for available information. Thread locked.
    Edited by: Vinod Kumar on Aug 3, 2011 1:35 PM

    As your name Suggests, there were exactly 21 rajapandian already who wanted exact information about  Data class and Delivery class. Fortunately some has found the information by own and some were dumped by SAP Police.
    Cheers
    Amit

  • BOR Object and ABAP Class

    Hi,
        Can anybody say when to use BOR object and Abap class in the task with an example.
    Thanks,
    Mugundhan

    There is no any specific condition or rule that for this purpose you need to use BOR and Class , it depends on your requirement. not only the requirement but also the new techniques to make classes not just as simple way to create objects but when you use classes in the Workflows they are not simple classes but they are BUSINESS CLASSES which makes a lot of difference.
    Check the blogs of [Jocelyn Dart|https://www.sdn.sap.com/irj/scn/wiki?path=/pages/viewpage.action%3fpageid=55566]

  • Difference between narrow() method usage and simple class cast for EJB

    Hi,
    I have a very simple question:
    what is the difference between PortableRemoteObject.narrow(fromObj,
    toClass) method usage and simple class cast for EJB.
    For example,
    1)
    EJBObject ejbObj;
    // somewhere in the code the home.create() called for bean ...
    ABean a = (ABean)PortableRemoteObject.narrow(ejbObj,ABean.class);
    OR
    2)
    EJBObject bean;
    // somewhere in the code the home.create() called for bean ...
    ABean a = (ABean)ejbObj;
    Which one is better?
    P.S. I'm working with WL 6.1 sp2
    Any help would be appreciated.
    Thanks in advance,
    Orly

    [email protected] (Orly) writes:
    Hi,
    I have a very simple question:
    what is the difference between PortableRemoteObject.narrow(fromObj,
    toClass) method usage and simple class cast for EJB.
    For example,
    1)
    EJBObject ejbObj;
    // somewhere in the code the home.create() called for bean ...
    ABean a = (ABean)PortableRemoteObject.narrow(ejbObj,ABean.class);
    OR
    2)
    EJBObject bean;
    // somewhere in the code the home.create() called for bean ...
    ABean a = (ABean)ejbObj;
    Which one is better?(1) is mandated by the spec. It is required because CORBA systems may
    not have sufficient type information available to do a simple case.
    P.S. I'm working with WL 6.1 sp2 You should always use PRO.narrow()
    andy

  • [svn:bz-trunk] 22429: Adding the default fallback of serializer and deserializer classes to amf deserializer and amf serializer

    Revision: 22429
    Revision: 22429
    Author:   [email protected]
    Date:     2011-09-07 08:04:46 -0700 (Wed, 07 Sep 2011)
    Log Message:
    Adding the default fallback of serializer and deserializer classes to amf deserializer and amf serializer
    Modified Paths:
        blazeds/trunk/modules/core/src/flex/messaging/io/SerializationContext.java

Maybe you are looking for

  • I think i should be on ADSL2+ but BT say I can't c...

    Hi all. First post but it might be an easy one to solve. I have recently moved to a new house where the exchange was upgraded to 21CN earlier in December.  I think I have been connected on ADSL Max but as I am pretty close to the exchange I think I w

  • Network files not showing when saving a document in Word 2010

    I have some users setup where their local profile on their laptop syncs with our server so they can take the laptop home, work on files, bring it back to work and have it sync with files and folders when they get back. One user is able to open a docu

  • Another Safari 4 crashing story

    I originally posted my question as a reply to another cry for help about Safari 4 crashes and it was suggested I add it as a separate topic so that is what I am doing. Safari 4 always crashes when I close the final instance of Safari that I have open

  • MBA 11" vs. 13" for low to moderate intensity user

    I'm looking to transition from my 2008 15" MBP to something a little more portable. My partner and I share a 27" iMac at home that has way more power and storage space than we need, and it serves as our primary computer. I am having a hard time decid

  • LKM for MySQL Error

    Hi, Can someone help me please. I am new to ODI and trying to work with it. My source DB = MS SQL 2005 Server Target DB = MySQL5.1 I created a new project and models. I have the physical and logical architecture and all the connections are working. I