Solved

Open JFrame from JFrame

Posted on 2004-04-17
7
767 Views
Last Modified: 2008-02-26
Hi
How do I open a new frame by clickingon a menu item in the first main frame? I tried it but something must be wrong since nothing happens when i click on the menu item anymore
I'm sure this is simple for you experts but it's urgent
thanks
0
Comment
Question by:Samooramad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 10849175
In the menu item event handler:


addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
            otherFrame.show();
      }
});
0
 

Author Comment

by:Samooramad
ID: 10849206
I'm not sure if that is the problem. The made the secondary frame into a class and declared it with something like:

secframeclass newframe = new secframeclass();

is that wrong?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10849213
>>is that wrong?

No - not necessarily. Obviously you need to set the size before you show it.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:Samooramad
ID: 10849228
so i still need to call it with show?
could you give me an example?
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 10849317
Something like:


public class F extends JFrame {
      JFrame otherFrame;
      JPanel buttonPanel;


      private void setGui() {
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            // Create other frame
            otherFrame = new JFrame("Hello");
            otherFrame.setSize(100, 100);
            buttonPanel = new JPanel();
            JButton bnShowFrame = new JButton("Show/hide frame");
            buttonPanel.add(bnShowFrame);
            bnShowFrame.addActionListener(
                  new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                              otherFrame.setVisible(!otherFrame.isVisible());
                        }
                  });
            getContentPane().add(buttonPanel, BorderLayout.CENTER);
      }


      public static void main(String[] args) {
            F f = new F();
            f.setGui();
            f.pack();
            f.setVisible(true);
      }
}

0
 

Author Comment

by:Samooramad
ID: 10849382
thaaaaaaaaaaaaaaaaaaaaaaaank you
that was quick and great!!!!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10849408
8-)
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question