ITPub博客

首页 > 应用开发 > > java窗口跳转

java窗口跳转

作者:coyan 时间:2019-08-14 10:39:48 0 删除 编辑

假如有两个frame,分别为frame1,frame2,frame1加个按钮实现跳转.frame1代码如下 

import java.awt.event.ActionEvent; 

import java.awt.event.ActionListener; 

import javax.swing.JButton; 

import javax.swing.JFrame; 

public class frame1 extends JFrame implements ActionListener{ 

/** 

* @param args 

*/ 

private JButton jb; 

public frame1() 

{ 

this.setSize(300, 200); 

this.setLocation(300, 400); 

jb=new JButton("跳转"); 

this.add(jb); 

jb.addActionListener(this);//加入事件监听 

this.setVisible(true); 

} 

public static void main(String[] args) { 

// TODO Auto-generated method stub 

frame1 frame=new frame1(); 

} 

@Override 

public void actionPerformed(ActionEvent e) { 

// TODO Auto-generated method stub 

if(e.getSource()==jb) 

{ 

this.dispose();//点击按钮时frame1销毁,new一个frame2 

new frame2(); 

} 

} 

} 

frame2是个单纯的 界面 

import javax.swing.JButton; 

import javax.swing.JFrame; 

public class frame2 extends JFrame{ 

/** 

* @param args 

*/ 

public frame2() 

{ 

this.setSize(300, 200); 

this.setLocation(300, 400); 

this.setVisible(true); 

} 

public static void main(String[] args) { 

// TODO Auto-generated method stub 

frame2 frame=new frame2(); 

} 

}

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2236/viewspace-3170051/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-07-11

  • 博文量
    271
  • 访问量
    16164