Solved

Compiling error

Posted on 2004-10-16
16
194 Views
Last Modified: 2013-12-03
Choice font = new Choice();      
      for ( int i = 0; i < fontList.length; i++ )
       {
      add(font);
      font.addActionListener(this);
      font.addItem(fontList[i]);
      font.setBackground(Color.lightGray);
      }

      public void actionPerformed(ActionEvent e) {
             if (e.getSource() instanceof Choice) {
                 String choice = (String) e.getSelectedItem();
                 editorPane.setFont( new Font( choice,Font.ITALIC,10) );
            }
      }


Error:
cannot resolve symbol
method addActionListener()
class java.awt.Choice
>> font.addActionListener(this);

Error:
cannot resolve symbol
method getSelectedItem()
class java.awt.event.ActionEvent
>>  String choice = (String) e.getSelectedItem();

-------------------------------------------------------------------

Any expert please help me to debug this code.
0
Comment
Question by:tloip
  • 8
  • 3
  • 3
  • +1
16 Comments
 
LVL 24

Expert Comment

by:sciuriware
Comment Utility
Obviously Choice has no method 'addActionListener()'.
Ditto ActionEvent has no method 'getSelectedItem()'.
Please refer to the JAVADOC for the methods that exist for those classes.
;JOOP!
0
 
LVL 21

Assisted Solution

by:MogalManic
MogalManic earned 30 total points
Comment Utility
Is this what you want?

            Choice font = new Choice();
            for (int i = 0; i < fontList.length; i++) {
                  add(font);
                  font.addInputMethodListener(this);
                  font.addItem(fontList[i]);
                  font.setBackground(Color.lightGray);
            }
      }


      public void actionPerformed(ActionEvent e) {
            if (e.getSource() instanceof Choice) {
                  String choice = (String) e.getActionCommand();
                  editorPane.setFont(new Font(choice, Font.ITALIC, 10));
            }
      }
0
 

Author Comment

by:tloip
Comment Utility
what do u mean no method?
can u specify it?
0
 
LVL 24

Expert Comment

by:sciuriware
Comment Utility
The methods you wrote down do not exist for those classes.
;JOOP!
0
 

Author Comment

by:tloip
Comment Utility
an error occurred:

addInputMethodListener(java.awt.event.InputMethodListener) in java.awt.Component cannot be applied to (gui)

> font.addInputMethodListener(this)
0
 

Author Comment

by:tloip
Comment Utility
doesn't exist?
So do i need to modify my code or just add code to it?

0
 
LVL 24

Expert Comment

by:sciuriware
Comment Utility
If you think that Choice can have an actionListener ... read the JAVADOC.
;JOOP!
0
 
LVL 21

Expert Comment

by:MogalManic
Comment Utility
What do you want to accomplish?  

The Font class does NOT have an actionListener event.  It DOES have an inputMethod listener event.  Read the javadoc for the Font class and the Choice class.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Expert Comment

by:Celdric
Comment Utility
I think we need to see which libraries are you importing and if those classes are where
they are supposed to be regardless of method use, the error is because it
cant find the class, not an invalid method.

Also, it will be helpful if you tell us in which plataform are you coding...
Netbeans, Eclipse? Are you trying to make a webapp? an applet?

and MogalManic is correct

addInputMethodListener(java.awt.event.InputMethodListener) in java.awt.Component cannot be applied to (gui)
> font.addInputMethodListener(this)

This means that you cant attach a InputMethodListener to a GUI object.

We need more info here..
0
 

Author Comment

by:tloip
Comment Utility
i'm using dos platform (j2sdk1.4.2_04).
this is one part of my program.
This part allows user to select the font face being used display the message (typed in textfield) in editorpane.

i imported these:

/* * My GUI Client */
import javax.swing.*;
import javax.swing.text.*;
import java.awt.*;
//for HTML Headers
import javax.swing.text.StyledEditorKit.*;
import javax.swing.text.html.HTMLEditorKit.*;
import javax.swing.text.html.*;
import javax.swing.event.HyperlinkListener;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkEvent.EventType;
import javax.swing.text.html.HTMLFrameHyperlinkEvent;
//for layout managers
import java.awt.event.*;
//for action and window events
import java.io.*;
import java.net.*;
import java.awt.GraphicsEnvironment;
0
 
LVL 1

Expert Comment

by:Celdric
Comment Utility
Ah, now I think thats your problem, you see, (Well, in my case, I dont know if its by default)
Well, whenever I use only the command line to code, I have to manually
direct the jdk to the libraries.

So, no matter if you declare the imports in your java file, the JDK wont find it until you
point it to the right jar or libraries outside the file...heres an example:

This class uses the openjms library, although I declare it inside the java file, I still need
to tell the JDK where those imports are, this is done with the -classpath option.

Java -classpath c:\myJ2EEjdk\lib\openjms.jar com.softtek.mypackage.MyClass

The syntax is: Java -classpath <library location> <class package>

If still in doubt, I recommend you learn to use either Netbeans or MyEclipse they do all this
for you, and they are both great coding plataforms, plenty of info out there too.

Oh! Remember to have your enviromental variables set, JAVA_HOME is very important

Hope this helped.
0
 

Author Comment

by:tloip
Comment Utility
I have NetBean as well but i really no idea on how to run the file.
I'm running the server...something like i will type like this :
>>>    java gui 127.0.0.2 2222
I need to run 3 files at one go to run my program.

Is it the problem occured on what platform i'm using and isn't because the code problem?
0
 

Author Comment

by:tloip
Comment Utility
usually before i run my file..I might type..

>>>  path=C:\jsdk1.4.2_04\bin

0
 
LVL 1

Accepted Solution

by:
Celdric earned 20 total points
Comment Utility
Well, since you do include the jdk in your path, i guess you include the neccesary libraries..

Well, like they have said b4..this error:
Error:
cannot resolve symbol
method getSelectedItem()
class java.awt.event.ActionEvent

means thats the ActionEvent does not have a getSelectedItem method and its right:

http://java.sun.com/j2se/1.3/docs/api/java/awt/event/ActionEvent.html

That is the specification for the class ActionEvent, and there it is listed all methods that
are implemented within the class and inherited from others.
getSelectedItem is not one of them.

as for the choice class:
http://java.sun.com/j2se/1.3/docs/api/java/awt/Choice.html
it doesnt have an addActionListener either, although it has like 4 different listeners
ActionListener isnt one of them.

Sorry to say, you got to find different methods to implement your application.

Good luck

0
 

Author Comment

by:tloip
Comment Utility
Ok, thanks for giving comment. I can solve it with your guidance.
0
 

Author Comment

by:tloip
Comment Utility
I did that..I'm not sure correct or not but it doesn't work. Means didn't show the message in selected font face.

public void itemStateChanged(ItemEvent e) {
             if (e.getSource() instanceof Choice) {
                  String choice = (String) e.getItem();
                  editorPane.setFont( new Font( choice,Font.PLAIN,10 ) );
            }
      }
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now