Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Opening one GUI from another

Posted on 2004-08-17
15
Medium Priority
?
198 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 2000 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 2000 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
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 

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

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.

Question has a verified solution.

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

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

721 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