Solved

Opening one GUI from another

Posted on 2004-08-17
15
191 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
  • 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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This video teaches viewers about errors in exception handling.
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.

708 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

13 Experts available now in Live!

Get 1:1 Help Now