Results 1 to 8 of 8
- 01-24-2012, 04:01 PM #1
Member
- Join Date
- Nov 2011
- Posts
- 23
- Rep Power
- 0
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); } }
- 01-24-2012, 04:04 PM #2
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!
- 01-24-2012, 04:07 PM #3
Member
- Join Date
- Nov 2011
- Posts
- 23
- Rep Power
- 0
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
- 01-24-2012, 04:20 PM #4
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!
- 01-24-2012, 04:43 PM #5
Member
- Join Date
- Nov 2011
- Posts
- 23
- Rep Power
- 0
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.
- 01-24-2012, 04:47 PM #6
Member
- Join Date
- Nov 2011
- Posts
- 23
- Rep Power
- 0
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.
- 01-24-2012, 04:51 PM #7
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,158
- Rep Power
- 5
Re: Simple draw line program not working
It should be:
You are missing the 'static' keyword.Java Code:public static void main(String [] args){
- 01-24-2012, 04:51 PM #8
Re: Simple draw line program not working
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
-
How to draw a line?
By Lund01 in forum New To JavaReplies: 9Last Post: 10-27-2011, 06:09 PM -
Draw line
By janes in forum Java 2DReplies: 6Last Post: 03-25-2010, 10:48 PM -
Draw more than one line on run time
By aiman in forum Java AppletsReplies: 3Last Post: 12-10-2009, 02:44 AM -
How to Draw line in Java
By Java Tip in forum java.awtReplies: 0Last Post: 06-22-2008, 11:08 PM -
How to draw a thick line
By johnt in forum Java 2DReplies: 1Last Post: 05-31-2007, 04:27 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks