This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems creating a new frame

 
jon ladd
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a help menu bar and it has about section and when that is called I want to open another frame and have my name and a logo of sorts. I am having hard time even having it open the frame window once about is selected. Below I have commented out thinking I am on the right track. I am not sure I keep looking at suns java.awt packet and I can't find anything that will help. Any ideas would greatly appreciated
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here are few lines from one of my programs:

You can see for Help I open a new frame, which happens to display an HTML help file. For HelpAbout I just show an option pane with hard coded contents. Do either of those help?
It looks like you're trying to create the HelpAbout window invisible and just show and hide it. That might be more trouble than it's worth ... would it be ok to create it on demand and let it be destroyed on close?
 
jon ladd
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it to show a frame now but when I click on about under the menu it shows a frame but I will no draw an oval or anything from the Graphics package. I added about section under the action listner class listed on large secion of code above. But once with about window runs you can see in blow up in the command promp.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Swing / JFC / AWT forum...
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

but I will no draw an oval or anything from the Graphics package.

The way to draw on a component in Java is to subclass the component and override the paintComponent(Graphics) method. Then Java will call this method when the window needs to be painted. If you try to do it the way you're doing it, then as soon as the window is resized, moved, overlapped, etc, the picture will disappear and never come back.
What you need to do is:
1) Make a subclass of JPanel.
2) Override the paintComponent() method. Do the drawing in that method.
3) When you create a JFrame in response to your menu pick, also create am instance of your JPanel subclass and add it to the JFrame's contentPane -- i.e., myFrame.getContentPane().add(new MyJPanel()) .
That'll do it!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic