• 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Can't get PaintComponent to work :(

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm doing a word search game. I'm just starting to learning java so it might be a stupid mistake. My problem is that I can't get the PaintComponent to work even though I already tried every possible thing that I know. Please help me! Where should I put paintComponent?



 
Bartender
Posts: 11445
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
Hint: Have you added the Grid to the frame at all?
 
Atsuko Maeda
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried putting this code in the createAndShowGUI() method but still no luck
 
Maneesh Godbole
Bartender
Posts: 11445
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In pseudo code
Create a JPanel instance (which has the overridden paint method)
Create a JFrame instance
Add the panel instance to the frame instance
Show the frame
Recommended reading http://docs.oracle.com/javase/tutorial/uiswing/painting/step2.html (It would be a very good idea to read it right from the start http://docs.oracle.com/javase/tutorial/uiswing/painting/)
 
Atsuko Maeda
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made my code like this still doesn't work. In creating a Jpanel instance does it mean that I have to put JPanel panel = new Jpanel("") etc? Sorry my mind doesn't really work well now.
 
Atsuko Maeda
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i see the problem now. I think i should do something to this part but I'm not sure what. When I removed this part of the code the Jpanel with the text appeared. Can you give me a hint? I tried reading several sources but I still can't figure it out.
 
Hey! You're stepping on my hand! Help me tiny ad!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic