With this code:
import java.awt.Graphics;
import java.applet.*;
import javax.swing.*;
/*
class PhoneBook{
String name, number;
public PhoneBook(){
this.name =" ";
this.number = " ";
}
public PhoneBook(String pname, String pnumber){
name = pname;
number = pnumber;
}
public String toString() {
return name + " " + number;
}
}
*/
public class b2 extends JApplet{
public void init(){
//String Raw;
//Raw = JOptionPane.showInputDialog("Enter name and telephone number:");
//PhoneBook test = new PhoneBook("test" , "1234");
}
public void paint(Graphics g){
g.drawString("test");
}
}
I get this error:
symbol : method drawString (java.lang.String)
location: class java.awt.Graphics
g.drawString("test");
^
Anyone have any idea why this won't work?
Thanks,
Zack
Erwin Moller - 25 Mar 2004 11:01 GMT
> public void paint(Graphics g){
> g.drawString("test");
[quoted text clipped - 11 lines]
> Thanks,
> Zack
Hi,
Why didn't you check the API??
It's here:
http://java.sun.com/j2se/1.4.2/docs/api/
This is how it works:
click java.awt in the upper left frame.
Then click Graphics in the lower left frame.
Now you see the API for Graphics in the mainframe.
The method you use on Graphics doesn't exist!
Regards,
Erwin Moller
Alex Hunsley - 14 Apr 2004 12:15 GMT
> With this code:
>
[quoted text clipped - 51 lines]
> Thanks,
> Zack
Because you didn't RTFM!
see:
http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Graphics.html#drawString(java.l
ang.String,
int, int)
i.e. there isn't a method that just takes a string, you have to provide a
coordinate (x,y).
HTH,
alex
Roedy Green - 16 Apr 2004 00:10 GMT
> I get this error:
>>
>> symbol : method drawString (java.lang.String)
>> location: class java.awt.Graphics
>> g.drawString("test");
>> ^
That is not the error message you got. That is just WHERE you got it.
If you looked up the error message at
http://mindprod.com/jgloss/errormessages.html
it would tell you the most likely cause.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.