• 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:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

JPanel painComponent not working

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont know how to best put it, but that seems to be whats happening here. I started a project recently to use up some of the free time I have and decided that Id attack the GUI first, to a degree. Well, ran into my first major problem already, less than 100 lines of code into the project. What Im trying to do is to have a main JFrame that will contain all of the program's graphical elements, and its meant to be without a title bar or any other decoration ( exit using esc key for now). To that I am trying to add a JPanel that will function as a menu ( I want to make it pretty in a sort of way that would be hard using buttons and dialogs.) Now to test out that the panel is working fine, I tried to make it draw a rect....which it didnt. I made sure to set the color, check if the panel is visible, and do all those other things you should do. Im certain I missed something though as Im not having much luck, and I am also certain that its something pretty small and stupid on my part. Anyways, without further ado, here's the code:

Thats the main class that will eventually run everything. So far it creates the main frame, the panel and adds one to the other, in the process printing out if the panel is visible ( which when I run the code returns as a yes )

Thats the code for the MainFrame. Ignore the methods for key and mouse listeners, I know they work fine.

And finally, the code for the menu Panel.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sorry, but what a dog's breakfast.

class MainScreen extends JFrame, but then you create a JFrame in the constructor???
class MainMenu extends JPanel, but then you create a JPanel in the constructor???
many other 'strange' lines of code.

here's a working version of your code, stripped to the problem (no listeners),
in particular look at the commented out lines and the added one

 
Sergey Schek
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
D'oh, I knew coding so late at night wasnt a good idea.

Thanks for the prompt reply.
 
I don't even know how to spell CIA. But this tiny ad does:
Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders
https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing
reply
    Bookmark Topic Watch Topic
  • New Topic