Solved

Open JFrame from JFrame

Posted on 2004-04-17
7
761 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
  • 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now