Solved

Opening one GUI from another

Posted on 2004-08-17
15
196 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy 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 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.
Suggested Courses

752 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