This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

paintcomponent in constructor

 
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

 
Sheriff
Posts: 6265
167
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • 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: 6265
167
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • 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.
 
Marshal
Posts: 65769
250
  • 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.
 
Bartender
Posts: 708
10
  • 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.
 
My first bit of advice is that if you are going to be a mime, you shouldn't talk. Even the tiny ad is nodding:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!