Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Java Software Solutions Graphics Example 2.10

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java Software Solutions Graphics Example 2.10

    Hey guys quick question working on a graphics example in my Java book can not get this to run. Can you please take a look and get back to me with it is wrong.

    package Einstein;

    class Einstein;
    .................................................. ...............

    package einstein;

    import javax.swing.JApplet;
    import java.awt.*;

    public class Einstein extends JApplet
    {
    public void paint(Graphics page)
    {
    page.drawRect(50,50,40,40);
    page.drawRect(60,80,225,30);
    page.drawOval(75,65,20,20);
    page.drawLine(35,60,100,120);

    page.drawString("Out of Clutter, Find Simplicity." , 100,70);
    page.drawString("-- Alber Einstein --", 130,100);
    }
    }


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: Java Software Solutions Graphics Example 2.10

    can not get this to run
    What happens when you try to run it?

  3. #3
    Junior Member
    Join Date
    Sep 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Software Solutions Graphics Example 2.10

    When trying to run it on Netbeans it gave an error of not having a main class? So I tryed it in eclipse and it did run. Not really sure y it dident work on netbeans any ideas?

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Java Software Solutions Graphics Example 2.10

    Quote Originally Posted by erosgol View Post
    When trying to run it on Netbeans it gave an error of not having a main class? So I tryed it in eclipse and it did run. Not really sure y it dident work on netbeans any ideas?
    Applets do not have a main method. There is probably a way in your IDE to define whether to run it as an applet - which I presume you wish to run this as - or an application (I don't use Netbeans so cannot make any suggestions other than this)

  5. #5
    Junior Member
    Join Date
    Sep 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Software Solutions Graphics Example 2.10

    ok so they example above came from my friends java book. I have the newer book and it shows the example like this


    package Einstein;

    class Einstein;
    .................................................. ...............

    //package einstein; <----- lists no package

    import javax.swing.JApplet;
    import java.awt.*;

    Einstein JApplet <---- has not public class extends
    {
    paint(Graphics page) <---- has no public void
    {
    page.drawRect(50,50,40,40);
    page.drawRect(60,80,225,30);
    page.drawOval(75,65,20,20);
    page.drawLine(35,60,100,120);

    page.drawString("Out of Clutter, Find Simplicity." , 100,70);
    page.drawString("-- Alber Einstein --", 130,100);
    }
    }

    not really sure why id think it was a typo if not for the fact its in both of the examples ive looked at can some 1 explain this?

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Java Software Solutions Graphics Example 2.10

    No no no. The code you just posted is not valid- and you would know that if you had tried to run it yourself.

    You've already received the answer. Are you trying to run this as an applet or an application?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    Junior Member
    Join Date
    Sep 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Software Solutions Graphics Example 2.10

    err I did try the question was, why was the newer book different and found out there was a list of corrections released and it was a mistake in the book. I am running it as an applet, and now have it working. I hope with time I can become a Great programmer like you Kevin, but till then I guess ill be posting questions that ive already received the answer to.

Similar Threads

  1. JTable simple Solutions
    By chronoz13 in forum Java Swing Tutorials
    Replies: 3
    Last Post: October 21st, 2012, 04:26 AM
  2. Free Application or Software for Java Programming focused on OOP
    By seicair in forum Java Theory & Questions
    Replies: 3
    Last Post: June 14th, 2011, 01:00 AM
  3. Senior Java Software Developer - Omaha, NE
    By lfanella in forum Paid Java Projects
    Replies: 1
    Last Post: February 1st, 2011, 04:16 AM
  4. Help with jdk/Java software
    By IpodHero in forum Java IDEs
    Replies: 1
    Last Post: December 16th, 2010, 11:05 AM
  5. JTable simple Solutions
    By chronoz13 in forum Java Code Snippets and Tutorials
    Replies: 2
    Last Post: February 24th, 2010, 09:14 AM