• Post Reply Bookmark Topic Watch Topic
  • New Topic

Having problems in adding Border and line drawing  RSS feed

 
Ray Anderson
Ranch Hand
Posts: 98
Java Oracle Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have started Swing yesterday and I am getting multiple errors on my code:

My errors are :
SwingDemo.java:55: error: ')' expected
p.setBorder(BorderFactory.createLineBorder(Color.RED,5);
^
SwingDemo.java:58: error: illegal start of expression
protected void paintComponent(Graphics g)
^
SwingDemo.java:58: error: illegal start of expression
protected void paintComponent(Graphics g)
^
SwingDemo.java:58: error: ';' expected
protected void paintComponent(Graphics g)
^
SwingDemo.java:58: error: ';' expected
protected void paintComponent(Graphics g)
^
5 errors
 
Tony Docherty
Bartender
Posts: 3205
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error messages tell you what's wrong, To learn how to debug efficiently you need to learn how to read them.

The first message tells you Line 55 is missing a closing bracket - I suggest you count the number of opening and closing brackets on line 55.
The other messages are because the compiler has been unable to establish where the end of line 55 really is and these messages will disappear once you have fixed line 55.
 
Ray Anderson
Ranch Hand
Posts: 98
Java Oracle Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I have corrected my mistakes.

But my program does not draw lines.
 
Campbell Ritchie
Sheriff
Posts: 53774
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why on earth are you using flow layout? A JFrame defaults to border layout; use that instead.

You need to give more details of what is going wrong before we can help you.
 
Ray Anderson
Ranch Hand
Posts: 98
Java Oracle Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I will refine my code and post it again.
 
Rob Camick
Ranch Hand
Posts: 2754
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But my program does not draw lines.


You have been given a link to the Swing tutorial, so why don't you start with the section from the tutorial on "Custom Painting".

Start with the working demo code, then make changes.

The working demo will show you how to better structure your code.
 
Ray Anderson
Ranch Hand
Posts: 98
Java Oracle Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Rob, started to study them thoroughly.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!