Java GUI 开发中窗口的调用
package NewWin;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.AbstractButton;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingConstants;
public class Mywin extends JFrame{
/**
*
*/
private static final long serialVersionUID = -6945210587575165235L;
private static JFrame jFrame;
public Mywin() {
super("title");//设置标题,可以用setTitle()方法
// TODO Auto-generated constructor stub
final JFrame jFrame=new JFrame();
jFrame.setSize(500,200);//设置窗口大小
jFrame.setLocation(100, 100);//设置窗口左上角的位置
jFrame.setUndecorated(true);//去除窗口装饰
jFrame.getRootPane().setWindowDecorationStyle(1);//设置窗口样式1-8
JButton jButton=new JButton("第一个窗口");
jButton.setBounds(10, 10, 50, 50);
jFrame.add(jButton);
jButton.addActionListener(new ActionListener() {//为jButton添加事件监听
@Override
public void actionPerformed(ActionEvent e) {//点击执行
// TODO Auto-generated method stub
newwindow(jFrame); //打开第二个窗口后将第一个设置为不可见
jFrame.setVisible(false);
}
});
ImageIcon imageicon_1=new ImageIcon("iQq.png");//设置窗口图标
Image image1=imageicon_1.getImage();
jFrame.setIconImage(image1);
jFrame.setVisible(true);//设置窗口可见
}
public static void newwindow(JFrame relatenewwin) {
final JFrame newFrame=new JFrame("第二个窗口");
newFrame.setBounds(110,110,200,200);
newFrame.setVisible(true);
final JButton jButton=new JButton("前往第三个窗口");
newFrame.add(jButton);
jButton.setSize(200,200);
jButton.setBounds(200,200,200,200);
jButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
name();
newFrame.setVisible(false);
}
});
}
public static void name() {
JFrame jFrame=new JFrame("第三个窗口");
jFrame.setBounds(120, 120, 400, 400);
jFrame.setVisible(true);
}
public static void main(String[] args) {
new Mywin();
}
}