• Post Reply Bookmark Topic Watch Topic
  • New Topic

paintcomponent in constructor  RSS feed

 
wesley johnsen
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

I'm working on a java app and want in the constructor put paintComponent.
But I get error messages:
1. modifier public not allowed here, protected also be getting the same error
2. @Override declaration should not be there
3.; expected

How can I solve this?

Can someone help me?

thanks in advance

 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are missing a brace (}).  Proper formatting will show you these kinds of error quickly.
 
wesley johnsen
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
which rule must the brace standing? only }?
 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go through the code and format it like this: start the first line on column 0 (no indent).  For every { you see, indent the following lines one tab (or 4 spaces).  For every } you see, "outdent" (reduce the tab) by one.  You will quickly see the problem.

I'm not trying to be annoying, it's just that this sort of skill is vital to being a programmer.  Poor formatting is a bug.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Get yourself a text editor which supports automatic indentation and it will help you get the indentation right first time.
 
Fred Kleinschmidt
Bartender
Posts: 571
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
want in the constructor put paintComponent.

Whatever for? The paintComponent() method should NEVER be placed inside a constructor.
Also note that your Grid class does not extend any other class or implement any interfaces, so your paintComponent() method cannot use @Override.
 
Carey Brown
Saloon Keeper
Posts: 3328
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This post has been superseded by
https://coderanch.com/t/674910/java/grids
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!