[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Open JFrame from JFrame

Posted on 2004-04-17
7
Medium Priority
?
774 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 2000 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

656 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