Solved

Simple Gui question........

Posted on 2004-04-30
3
211 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSum6 challenge 6 77
JDeveloper 12c for 32 bit 4 71
micro services vs rest web services 16 87
eclipse java  build path 6 45
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…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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…
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.

867 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

12 Experts available now in Live!

Get 1:1 Help Now