假如有兩個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(); }}