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 / General / September 2006

Tip: Looking for answers? Try searching our database.

Beginner's question

Thread view: 
Jacky Luk - 20 Sep 2006 19:38 GMT
import java.awt.Graphics;

public class printtest extends java.applet.Applet
{
  public void init()
  {
  }

     public void paint (Graphics g)
     {
      g.drawString ("Hello from java!", 60, 30);
     }

     public static void main (String args)
     {

     }
}
===============================
java.lang.NoSuchMethodError: main
Exception in thread "main"

What happened?
Thanks
Jack
Thomas Hawtin - 20 Sep 2006 19:59 GMT
> public class printtest extends java.applet.Applet

>       public static void main (String args)
>       {

That should be:
    public static void main(String[] args) {

>       }

But it still wont do anything.

Applets run in web pages. You'll need something like this in an HTML
file (in the same directory as your class file):

<applet class="printtest.class" width="100" height="100"></applet>

Then either view the web page in your browser (if it has a sufficiently
recent version of Java enabled) or use appletviewer.

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

Jacky Luk - 20 Sep 2006 20:05 GMT
How do you make the paint method work?
Thanks
Jack

"Thomas Hawtin" <usenet@tackline.plus.com>
???????:45118f8b$0$2663$ed2619ec@ptn-nntp-reader02.plus.net...

>> public class printtest extends java.applet.Applet
>
[quoted text clipped - 17 lines]
>
> Tom Hawtin
Thomas Hawtin - 20 Sep 2006 20:23 GMT
> How do you make the paint method work?

Works for me... My entire (Java 1.5) code:

import java.awt.Graphics;

public class PrintTest extends java.applet.Applet {
    @Override
    public void paint(Graphics g) {
        g.drawString("Hello from java!", 60, 30);
    }
}

<applet code="PrintTest.class" width="100" height="100"></applet>

(Note that's code= not class= as I said earlier.)

Are you sure it's running? No exception messages in the terminal/console
for appletviewer or Java console of your web browser?

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

Jacky Luk - 20 Sep 2006 23:35 GMT
Severity Description Resource In Folder Location Creation Time Id
2 The public type PrintTest must be defined in its own file printtest.java
test1 line 3...
1 The serializable class PrintTest does not declare a static final
serialVersionUID field of type long printtest.java test1 line 3...

"Thomas Hawtin" <usenet@tackline.plus.com>
???????:45119539$0$559$ed2619ec@ptn-nntp-reader03.plus.net...
>> How do you make the paint method work?
>
[quoted text clipped - 17 lines]
>
> Tom Hawtin
Andrew Thompson - 20 Sep 2006 23:49 GMT
> > public class printtest extends java.applet.Applet
....
>      public static void main(String[] args) {
...
> But it still wont do anything.

Sure it will*.  Adding a main allows you to run your applet as
either an applet or an application.  Most of my applets have mains
(even if I never intend to use them as applications) simply
because it can be so much quicker developing something
you can simply launch from the command line.

* So long as the main creates a frame, instantiates the
applet class, calls init() and adds it to the frame.

Andrew T.


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.