aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Can't get PaintComponent to work :( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Can Watch "Can New topic
Author

Can't get PaintComponent to work :(

Atsuko Maeda
Greenhorn

Joined: Mar 27, 2012
Posts: 6
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?



Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10393
    
    8

Welcome to the Ranch
Hint: Have you added the Grid to the frame at all?


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Atsuko Maeda
Greenhorn

Joined: Mar 27, 2012
Posts: 6
i tried putting this code in the createAndShowGUI() method but still no luck
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10393
    
    8

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

Joined: Mar 27, 2012
Posts: 6
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

Joined: Mar 27, 2012
Posts: 6
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.
 
wood burning stoves
 
subject: Can't get PaintComponent to work :(