Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help me ! what's wrong with my JDK1.2.2 compiler

 
sean zang
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI, Jim, Tony ,and Maha AaNa
I try to complie the following code, But the compiler give the the silly message .I try to reinstall the JKD1.2.2 , but the problem stills exsit. please help me to check wether my compiler works correctly.
<pre>

import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class TextDemo extends Applet implements ActionListener {
TextField textField;
TextArea textArea;
String newline;
public void init() {
textField = new TextField(20);
textArea = new TextArea(5, 20);
textArea.setEditable(false);
//Add Components to the Applet.
GridBagLayout gridBag = new GridBagLayout();
setLayout(gridBag);
GridBagConstraints c = new GridBagConstraints();
c.gridwidth = GridBagConstraints.REMAINDER;
c.fill = GridBagConstraints.HORIZONTAL;
gridBag.setConstraints(textField, c);
add(textField);
c.fill = GridBagConstraints.BOTH;
c.weightx = 1.0;
c.weighty = 1.0;
gridBag.setConstraints(textArea, c);
add(textArea);
textField.addActionListener(this);
newline = System.getProperty("line.separator");
}
public void actionPerformed(ActionEvent evt) {
String text = textField.getText();
textArea.append(text + newline);
textField.selectAll();
}
}

</pre>
// look the following error message, why new TextField(20) is wrong.
C:\java\TextDemo.java:15: Wrong number of arguments in constructor.
textField = new TextField(20);
^
C:\java\TextDemo.java:35: Method addActionListener(TextDemo) not found in class TextField.
textField.addActionListener(this);
^
C:\java\TextDemo.java:41: Method getText() not found in class TextField.
String text = textField.getText();
^
C:\java\TextDemo.java:43: Method selectAll() not found in class TextField.
textField.selectAll();
^
4 errors
Process completed with exit code 1

[This message has been edited by maha anna (edited April 29, 2000).]
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sean zang,
I copied your code and compiled . It compiles fine. I am also using jdk1.2.2 on win 98. All java related executables will be kept in the_installed_dir\bin directory.
Try to write a simple HellowWorld.java which doesn't import any pack as such and compile and run. We will go from there. And tell us what is the error message you get now.
<pre>
class Test {
public static void main(String[] args) {
System.out.println("HelloWorld");
}
}
</pre>
regds
maha anna
[This message has been edited by maha anna (edited April 29, 2000).]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IF I WERE TO GUESS...
I believe that you have another "TextField" class defined somewhere in your classpath. Try this - instead of just 'TextField' , write out java.awt.TextField anywhere you previously had just TextField in your code. If this compiles, search your hard drive for TextField.class (search .jar files too). That should give you the solution to your problem if I'm guessing right.
 
sean zang
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
Java Nut
your "guess" is definetely helpful. Yes long time ago I declared the class named TextFied, so It always "overide" JAVA lib TextField.I change my classpath searching order, It works correctlly.
Thank you very much your great guess
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Java Nut.
regds
maha anna.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic