• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

paintcomponent in constructor

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
which rule must the brace standing? only }?
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 732
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic