Opening a new window

I have 2 windows in two different classes. How do I set it so that when I click the button, the other window opens (the original window is still open though, behind it)Thanks
[188 byte] By [hornetsfan16a] at [2007-11-27 5:28:20]
# 1
maybe you can provide a method in the class that you want to open second that will return the window.. could work :-)
G-Dub_Sama at 2007-7-12 14:50:31 > top of Java-index,Java Essentials,New To Java...
# 2
what kind of method would that be? to return the window
hornetsfan16a at 2007-7-12 14:50:31 > top of Java-index,Java Essentials,New To Java...
# 3

Maybe this will help. Create an instance of the new window in the class which is calling the other class.

Class A{

//the constructor of this class creates a window

}

Class B{

private mouseClicked (MouseEvent evt)

{

A newWindow = new A();

newWindow.setVisible;

}

}

I guess u are more confused now :D

-...icedT...-a at 2007-7-12 14:50:31 > top of Java-index,Java Essentials,New To Java...
# 4
create an instance of 2nd window class in the actionlistener of the button in the 1st class.
b.m.krajua at 2007-7-12 14:50:31 > top of Java-index,Java Essentials,New To Java...
# 5

Hi dude check this code

import javax.swing.*;

import java.awt.event.*;

class Test10 extends JFrame

{

private javax.swing.JButton press = null ;

private javax.swing.JPanel mainPane;

Test10()

{

press = new javax.swing.JButton("Press");

mainPane = new JPanel();

mainPane.add(press);

press.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent ae)

{

doTestBtnAction();

}

});

}

private void createGUI()

{

getContentPane().add(mainPane);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//setSize(,400);

pack();

setVisible(true);

}

private static void createAndShowGUI()

{

Test10 tt = new Test10();

tt.createGUI();

}

private void doTestBtnAction()

{

System.out.println("Test");

new CallWindow();

}

public static void main(String[] args)

{

javax.swing.SwingUtilities.invokeLater(new Runnable()

{

public void run()

{

createAndShowGUI();

}

});

}

}

class CallWindow

{

CallWindow()

{

JFrame jf = new JFrame();

jf.setVisible(true);

jf.setSize(200,200);

}

}

Thanks ,

Sb

sb.majumder_07a at 2007-7-12 14:50:31 > top of Java-index,Java Essentials,New To Java...
# 6
thanks heaps, got it now
hornetsfan16a at 2007-7-12 14:50:31 > top of Java-index,Java Essentials,New To Java...