File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Problems creating a new frame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problems creating a new frame " Watch "Problems creating a new frame " New topic

Problems creating a new frame

jon ladd
Ranch Hand

Joined: Feb 11, 2003
Posts: 53
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

Joined: Jan 29, 2003
Posts: 8791
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?

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
jon ladd
Ranch Hand

Joined: Feb 11, 2003
Posts: 53
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

Joined: Dec 10, 2001
Posts: 7023
Moving this to the Swing / JFC / AWT forum...

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

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!

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: Problems creating a new frame
jQuery in Action, 3rd edition