Solved

Opening one GUI from another

Posted on 2004-08-17
15
195 Views
Last Modified: 2010-03-31
Hi
I've a gui and a command button in there which I want to launch another GUI when user clicks the button....

here's whats in the first GUI.....

ButtonCHOOSE = new JButton("Choose Files...");
ButtonCHOOSE.addActionListener(this);
.
.
.
if(e.getSource() == ButtonCHOOSE)
{
 //  could i put something here so that it would launch a GUI class called 'choose' when the 'choose files' button is clicked??
}

thanks!
0
Comment
Question by:ByrdBrain
[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
  • 7
  • 6
  • 2
15 Comments
 
LVL 35

Assisted Solution

by:girionis
girionis earned 500 total points
ID: 11818123
You could so something like:

if(e.getSource() == ButtonCHOOSE)
{
    GuiClass gc = new GuiClass();
    gc.showGui();
}

Give that your GUI class is called GuiClass.
0
 
LVL 35

Assisted Solution

by:girionis
girionis earned 500 total points
ID: 11818126
Of course the class should be imported and in your classpath if it is in a different package.
0
 
LVL 7

Expert Comment

by:tomboshell
ID: 11818163
It is all classes and methods.  So, you are asking if you can have one class call another and summon a method in that class.  Yes you can.  You are probably already doing it.  Your class summons some buttons and then shows them.  girionis answered that question easily ;)  

What are you really stuck on?  Is it that you are looking for something like: JFileChooser?  Threading?  Or simply looking to move the gui work out of the event handling?  
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ByrdBrain
ID: 11818166
thanks gironis,
one problem though....
D:\java:133: cannot resolve symbol
symbol  : method showGui ()
location: class fileChooser
              gc.showGui();

I've got my class called GUI....could this be why I'm getting the error?
0
 
LVL 35

Assisted Solution

by:girionis
girionis earned 500 total points
ID: 11818186
You have to call a method that does exist in your gui class.
0
 

Author Comment

by:ByrdBrain
ID: 11818208
so if i had

if(e.getSource() == ButtonCHOOSE)
      {
                          fileChooser gc = new fileChooser();
                          gc.showfileChoose();
                  }

i would need...
public showfileChoose()
      {
      // but i would need a return type here??      
      }
0
 
LVL 35

Expert Comment

by:girionis
ID: 11818281
If it void (it does not return anything) you do not need to return something in the method. So you can have:

public void showfileChoose()
{
   // Show gui here
}

0
 

Author Comment

by:ByrdBrain
ID: 11818299
ok, so how do you show the GUI call fileChoose?
what do i need in this method? thanks
0
 
LVL 35

Assisted Solution

by:girionis
girionis earned 500 total points
ID: 11818311
Just have the code that shows the gui. How do you currently use it? Do you call the showfileChooser from inside a class? You need to do the same here, you just need to have the class' reference.
0
 

Author Comment

by:ByrdBrain
ID: 11818430
i've now changed the class name fileChoose because I've already got fileChooser in there and it was confusing...
so from my main gui class i want to call the following....
but i'm not sure what to reference

class commonFiles extends JFrame{
      
      public static void main(String args[]){
            commonFiles mFrame = new commonFiles();
            mFrame.setLocation(300,100);
            mFrame.setVisible(true);
            
      }
      
      private DefaultListModel model = new DefaultListModel();
      private JList source = new JList(model);
      private DefaultListModel targetpane = new DefaultListModel();
      private JList target = new JList(targetpane);
      private JList lCommon;
      private JList lMissing;
      private JList lRemove;
      

      public commonFiles(){

//etc
}
0
 
LVL 35

Accepted Solution

by:
girionis earned 500 total points
ID: 11818445
Try this:

if(e.getSource() == ButtonCHOOSE)
{
          commonFiles mFrame = new commonFiles();
          mFrame.setLocation(300,100);
          mFrame.setVisible(true);
}
0
 

Author Comment

by:ByrdBrain
ID: 11818451
Excellent!
thanks a lot....its working :O)
0
 

Author Comment

by:ByrdBrain
ID: 11818465
Tomboshell....

>>What are you really stuck on?  Is it that you are looking for something like: JFileChooser?  Threading?  Or simply >>looking to move the gui work out of the event handling?  

I'm just creating a sort of template at the moment.....no actual functioning except....if you click on a button that should launch a gui then i want it to do that or select radio buttons, enter text etc......just a basic template for the moment.....I have classes with all my stuff working via command line but i want to develop the gui separately first before applying it...

0
 
LVL 35

Expert Comment

by:girionis
ID: 11818497
Glad to hear problem is solved :)

Good luck with the rest of your classes.
0
 
LVL 7

Expert Comment

by:tomboshell
ID: 11818546
I was just having fun.  Looks like girionis answered you.  
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
fibonacci ten numbers 4 54
Java exception bubble up 2 24
swing controls 2 21
learn programming 8 66
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
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:

763 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