1个回答
展开全部
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
public class TwoFrame extends JFrame {
private Button butt;
public TwoFrame() {
setSize(450, 300);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
butt = new Button("点我弹框");
butt.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// 将当前的窗口资源释放掉
dispose();
// 此处最好另开线程来弹框
new Thread(){
@Override
public void run() {
// 弹框出来
new OneFrame();
}
}.start();
}
});
getContentPane().add(butt,BorderLayout.SOUTH);
}
public static void main(String[] args) {
new TwoFrame();
}
}
class OneFrame extends JFrame {
public OneFrame() {
setSize(300, 200);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
}
import java.awt.Button;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
public class TwoFrame extends JFrame {
private Button butt;
public TwoFrame() {
setSize(450, 300);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
butt = new Button("点我弹框");
butt.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// 将当前的窗口资源释放掉
dispose();
// 此处最好另开线程来弹框
new Thread(){
@Override
public void run() {
// 弹框出来
new OneFrame();
}
}.start();
}
});
getContentPane().add(butt,BorderLayout.SOUTH);
}
public static void main(String[] args) {
new TwoFrame();
}
}
class OneFrame extends JFrame {
public OneFrame() {
setSize(300, 200);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询