Solved

Simple Gui question........

Posted on 2004-04-30
3
212 Views
Last Modified: 2010-03-31
I have a class which shows a gui
As well as that there are action listeners for various button-presses, apart from that, nothing else.

When one of the buttons is pressed, within the action listener i call a second class........

mainGui.butStart.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
            callConnect = new Connect();
           callConnect.callResponder(mainGui);
        } /* end actionPerformed */  
}); /* end addActionListener */

This class also shows a gui.

When the cancel button on that gui is pressed, as follows.........i want it to return to the previous gui, but when i do that the first gui disappears as well. How can i stop that?

settingsGui.butCancel.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
                           
               mG.butStart.setEnabled(true);
             mG.butStop.setEnabled(false);
               
                settingsGui.hide();
           
           
           }
 });    


How come when i do the .hide(), the other gui disappears also and how do i stop it from happening?
0
Comment
Question by:vinoboy
3 Comments
 
LVL 13

Expert Comment

by:copyPasteGhost
ID: 10964561
settingsGui is a panel? JFrame?

if you want both of them open are you refering to like a MDI model? (Multiple Document Interface) an example of this model is Ms Word version 97 where there was one big window (parent window) and mulitple other windows (child) anyways I'm sure you know what I'm talking about.

is that what you want?
You can look into the JInternalFrame and the JDesktopFrame classes for more information
Cheers,
Ghost
0
 

Author Comment

by:vinoboy
ID: 10965240
Both the first gui (mainGui) and the second one (settingsGui) are JFrames.

When i click a 'Cancel' button on the second gui (settingsGui) why does the gui behind it (mainGui)also disappear? And how can i solve it?

0
 
LVL 7

Accepted Solution

by:
maheshexp earned 30 total points
ID: 10965356

class Frame1 extends JFrame {
      public Frame1() {
            setSize(200, 300);
            JButton b = new JButton("Open");
            b.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                        new Frame2(Frame1.this); ---> referes to the class Frame1
                  }
            });
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.getContentPane().add(b);
            this.show();
      }
}

class Frame2 extends JFrame {
      public Frame2(final JFrame caller) {
            setSize(200, 300);
            JButton b = new JButton("Close");
            b.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                        caller.show();
                        Frame2.this.hide();
                  }
            });
            this.getContentPane().add(b);
            this.show();
      }
}

public class Test6 {

      public static void main(String[] args) {
            new Frame1();
      }
}
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet doXXX methods 3 50
Java SE 8u111  Lot of stuff broke 11 69
Running JavaFX on JDeveloper 12C 1 32
Selenium docs api java index 3 19
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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 …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

803 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