|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Multiple windows
I'm very new to Java so forgive me the simplicity of the question.
I'm currently working on a school assignment for which i have to program an application. My simple problem is that i don't know how to create multiple windows in java. I've looked everywhere but can't seem to find it. I hope there is a very simple way to do this. I just want a button, with an actionlistener to set the window another applet. Thank you! |
|
#2
|
|||
|
|||
|
What you mean is that you want a window with a button with an actionlistener and when you push the button a new window to appear? Or do you mean a multi-windowed windows application?
|
|
#3
|
|||
|
|||
|
I don't know which is easier. I'd rather want one window, with multiple screens yeah.
But if it's easier for new windows to appear that's okay too. Whathever is easier. Thank you ![]() |
|
#4
|
|||
|
|||
|
The easier is to create a window with a button that activates a new window when clicked! I'll see what can I do!
|
|
#5
|
|||
|
|||
|
Sorry for not answering earlier but there was a problem with my compiler. Well, here's an example of how to make a window with a button, when pressed show another window:
Here's the code of the main window: Code:
import javax.swing.*;
import javax.swing.JMenuBar;
import java.awt.*;
import java.awt.event.*;
public class test extends JFrame implements ActionListener
{
JButton butt1 = new JButton("Test"); // new button
JPasswordField pass = new JPasswordField(20); // new password field
JMenu mnu = new JMenu("File"); // new menu
JMenuItem mnu_1 = new JMenuItem("...."); // new menu Item
JMenuBar bar = new JMenuBar(); // new menu Bar -- to put the menu in
newWindow test2; // variable of the other window
public test() // constructor
{
super("Test"); // title
setSize(300,100); // size
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pass.setEchoChar('*');
mnu.add(mnu_1); // add the menu items in the menu
bar.add(mnu); // add the menu in the menu bar
JPanel panel = new JPanel(); // new Panel
butt1.addActionListener(this); // add ActionListener to the button
setJMenuBar(bar); // set the Menu Bar
panel.add(pass); // add the Password Field
panel.add(butt1); // add the button
setContentPane(panel);
}
public static void main(String args[]) // main function
{
JFrame ts = new test(); // new object of the class "test"
ts.show();
}
public void actionPerformed(ActionEvent evt) // function to control the ActionListener
{
Object src = evt.getSource();
if(src == butt1)
{
setVisible(false);
test2 = new newWindow();
test2.show();
}
}
}
Hope I helped!! Costas |
|
#6
|
|||
|
|||
|
thank's
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > Multiple windows |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|