Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / April 2004

Tip: Looking for answers? Try searching our database.

Need help with drawString method

Thread view: 
zzallin - 25 Mar 2004 07:59 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.