Results 1 to 8 of 8
  1. #1
    forms is offline Member
    Join Date
    Nov 2011
    Posts
    23
    Rep Power
    0

    Default Simple draw line program not working

    Hi, im trying to get this simple program to work and it wont run.
    I can't see what i am doing wrong.
    I keep getting a lightbulb icon next to the class header saying: The serializable class Balls does not declare a static final serialVersionUID field of type long.

    All i want to do is draw a line.
    Any help would be greatly appreciated. Thanks.

    Java Code:
    
    import java.awt.*;
    import javax.swing.*;
    
    public class Balls extends JPanel {
    	
    	public void main(String [] args){
    		Balls b = new Balls();	
    		JFrame frame = new JFrame();
    		frame.add(b);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.setSize(300, 300);
    		frame.setVisible(true);
    	}
    	
    	public void paintComponent(Graphics g){
    	    g.drawLine(0,0,90,90);
    		
    	}
    
    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,879
    Rep Power
    8

    Default Re: Simple draw line program not working

    Your program works for me. That's just a compiler warning, not an error.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    forms is offline Member
    Join Date
    Nov 2011
    Posts
    23
    Rep Power
    0

    Default Re: Simple draw line program not working

    When i click run a different program runs in the same folder.
    I cant get this particular program to run.
    Im using eclipse.
    Thanks

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,879
    Rep Power
    8

    Default Re: Simple draw line program not working

    Not really sure what we can do with that description. Have you tried running from the command prompt? Have you tried cleaning your project, or doing a refresh?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    forms is offline Member
    Join Date
    Nov 2011
    Posts
    23
    Rep Power
    0

    Default Re: Simple draw line program not working

    I get a message saying the code does not contain a main type and it does not contain an applet therefore it cannot run.
    Any ideas?
    All my other programs run fine.

  6. #6
    forms is offline Member
    Join Date
    Nov 2011
    Posts
    23
    Rep Power
    0

    Default Re: Simple draw line program not working

    I found the error.
    There was no static keyword in the main method header. I would have assumed eclispe would have highlighted this as an error.
    How did the program work for you?
    Thanks for your help.

  7. #7
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,234
    Rep Power
    7

    Default Re: Simple draw line program not working

    It should be:

    Java Code:
        public static void main(String [] args){
    You are missing the 'static' keyword.

  8. #8
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,879
    Rep Power
    8

    Default Re: Simple draw line program not working

    Quote Originally Posted by forms View Post
    I found the error.
    There was no static keyword in the main method header. I would have assumed eclispe would have highlighted this as an error.
    How did the program work for you?
    Thanks for your help.
    It's not an error because you can have a non-static method named main. Never assume eclipse is going to do anything for you- in fact, at this stage in the game, I suggest ditching eclipse altogether.

    And it worked for me because I copied it into my own test program that had the correct syntax for main.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. How to draw a line?
    By Lund01 in forum New To Java
    Replies: 9
    Last Post: 10-27-2011, 06:09 PM
  2. Draw line
    By janes in forum Java 2D
    Replies: 6
    Last Post: 03-25-2010, 10:48 PM
  3. Draw more than one line on run time
    By aiman in forum Java Applets
    Replies: 3
    Last Post: 12-10-2009, 02:44 AM
  4. How to Draw line in Java
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-22-2008, 11:08 PM
  5. How to draw a thick line
    By johnt in forum Java 2D
    Replies: 1
    Last Post: 05-31-2007, 04:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •