Solved

Opening one GUI from another

Posted on 2004-08-17
15
193 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
recursion example 16 124
tomcat not starting 6 45
eclipse apache tomcat admin console 52 95
Chrome and Firefox Java 5 26
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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.

808 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