A beginner question

I don't understand why my code gets the error cannot find symbol on the getGraphics line.import java.awt.*;public class Main{public static void main(String[] args){Graphics g = getGraphics();g.drawOval(10 , 10 , 5, 5);}}
[291 byte] By [iamdanthemanstana] at [2007-10-1 1:48:06]
# 1
Why do you think getGraphics() will work? Where do you think it comes from?Press the code button next time you want to include code.
mlka at 2007-7-8 8:10:13 > top of Java-index,Security,Event Handling...
# 2
I've seen it used in tutorials. If not this how sould I initilise g?
iamdanthemanstana at 2007-7-8 8:10:13 > top of Java-index,Security,Event Handling...
# 3

Have you covered object orientation yet?

At a guess what you have done before was using Applets? Applet[1] have a method called getGraphics(), and when you extended Applet, you inhereted its functionallity.

class MyClass extends Applet

Now you are not extending applet, so you need to create an object to draw on. Applets are for webpages, but as you are using

public static void main

I'm guessing you don't want an applet. Take a look at Frame[2]. And read the tutorials below.

Resources for Beginners

Sun's basic Java tutorial - http://java.sun.com/docs/books/tutorial/

Sun's New To Java Center.

http://java.sun.com/learning/new2java/index.html

Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.

javaalmanac.com

http://javaalmanac.com]

A couple dozen code examples that supplement

The Java Developers Almanac

http://www.amazon.com/exec/obidos/tg/detail/-/0201752808?v=glance

jGuru.

http://www.jguru.com

A general Java resource site. Includes FAQs, forums, courses, more.

JavaRanch.

http://www.javaranch.com

To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.

Bruce Eckel's Thinking in Java (Available online.)

http://mindview.net/Books/DownloadSites

Joshua Bloch's [url=http://www.amazon.co.uk/exec/obidos/Author=Bloch,%20Josh]Effective Java[/url]

Bert Bates and Kathy Sierra's [url=http://www.amazon.com/exec/obidos/tg/detail/-/0596004656?v=glance]Head First Java[/url]. This one has been getting a lot of very positive comments lately.

[1] http://java.sun.com/j2se/1.5.0/docs/api/java/applet/Applet.html

[2] http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Frame.html

mlka at 2007-7-8 8:10:13 > top of Java-index,Security,Event Handling...
# 4
I don't see why I can't call getGraphics from http://java.sun.com/j2se/1.5.0/docs/api/index.html?java/awt/Frame.html
iamdanthemanstana at 2007-7-8 8:10:13 > top of Java-index,Security,Event Handling...
# 5

> I don't see why I can't call getGraphics from

> http://java.sun.com/j2se/1.5.0/docs/api/index.html?jav

> a/awt/Frame.html

You have posted a link to the Frame class, and yes you can call that method on a Frame, but you neither have a frame nor extends frame.

/Kaj

kajbja at 2007-7-8 8:10:13 > top of Java-index,Security,Event Handling...
# 6
posted wrong link http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Component.html
iamdanthemanstana at 2007-7-8 8:10:13 > top of Java-index,Security,Event Handling...
# 7
iam the beginner of java.and iam doing my project in j2ee.it is possible to do my project.
sankarms15a at 2007-7-8 8:10:13 > top of Java-index,Security,Event Handling...