import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class TwoWindow
{
public static void main(String[] args)
{
TwoWindowFrame frame=new TwoWindowFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}class TwoWindowFrame
extends JFrame
{
public TwoWindowFrame()
{
setTitle("Pop window");
setSize(300,300); JButton button=new JButton("Pop it");
button.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
p.show();
}
}); Container contentPane=getContentPane();
contentPane.add(button,BorderLayout.NORTH);
} PopWindow p=new PopWindow();
}class PopWindow
extends JFrame
{
public PopWindow()
{
setTitle("I am a pop window");
setSize(100,100);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
show();
}
}
//好像不能把窗体放进cache!!!
import java.awt.event.*;
import javax.swing.*;public class TwoWindow
{
public static void main(String[] args)
{
TwoWindowFrame frame=new TwoWindowFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}class TwoWindowFrame
extends JFrame
{
public TwoWindowFrame()
{
setTitle("Pop window");
setSize(300,300); JButton button=new JButton("Pop it");
button.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
p.show();
}
}); Container contentPane=getContentPane();
contentPane.add(button,BorderLayout.NORTH);
} PopWindow p=new PopWindow();
}class PopWindow
extends JFrame
{
public PopWindow()
{
setTitle("I am a pop window");
setSize(100,100);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
show();
}
}
//好像不能把窗体放进cache!!!
public void windowClosing(java.awt.event.WindowEvent evt) {
//这里写入你想要进行的动作
}
});
pack();
If you just simply want to realize what you require in the topic, then it's simply as followed,TwoWindowFrame.setvisible(true);as stated by newman0708.
问问题先,窗体之间的传值怎么做?