Im having a lot of trouble trying to figure out something that seems like it would be easy.

For my final project I have to create a GUI application. I got it set up and working where when you click the button it will display some text depending on what button you press.
What I'm trying to figure out is how to make it where when you click a button, a seperate new GUI window will open.
When i add my code and click the button, it just adds the new buttons onto the GUI I already have open and everytime you click it, it adds more.
This is not what i want!
Here is an example of my working code to display the text.

  private class ButtonListener implements ActionListener
   {
      public void actionPerformed(ActionEvent e)
      {
         // Get the action command.
         String actionCommand = e.getActionCommand();

         // Determine which button was clicked and display
         // a message.
         if (actionCommand.equals("Button 1"))
         {
            JOptionPane.showMessageDialog(null, "You clicked " +
                                          "the first button.");
         }
         else if (actionCommand.equals("Button 2"))
         {
            JOptionPane.showMessageDialog(null, "You clicked " +
                                          "the second button.");
         }
         else if (actionCommand.equals("Button 3"))
         {
            JOptionPane.showMessageDialog(null, "You clicked " +
                                          "the third button.");
         }

Instead of it saying "You clicked the first button" when i click button 1, I want it to open up a new GUI.
How can I do this??
Thanks guys and sorry Im such a noob!

e it where when you click a button, a seperate new GUI window will open.
When i add my code and click the button, it just adds the new buttons onto the GUI I already have open

I am confused about what you are trying to achieve, it looks like you have multiple buttons on your gui correct?
And when you click one of those buttons you want a new seperate window to pop up?

If this is the case, you want to instantiate a new Jframe window on the event of your button click like so :

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class JWindowDemo extends JWindow
    {
         public JWindowDemo(){
         setBounds(60,60,100,100);
         setVisible(true);
    }


 if (actionCommand.equals("Button 1"))
         {
         new JWindowDemo();
         }

I havent tested this, but that is roughly the idea, create a window class and instantiate it when a button is clicked. There are a number of other classes with presets that are smaller to implement but youve obviously discovered the already. Let me know whether this is what you want to achieve or still have questions :)

nal project I have to create a GUI application. I got it set up and working where when you click the button it will display some text depending on what button you press.
What I'm trying to figure out is how to make it where when you click a button, a seperate new GUI window will open.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.