2个回答
展开全部
package com.wdy.test;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
public class TestFrame extends JFrame {
private static final long serialVersionUID = 1L;
private JDialog dialog;
public TestFrame() {
setSize(350, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
setLayout(new FlowLayout());
JButton button = new JButton("Click");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
showDialog();
}
});
getContentPane().add(button);
dialog = new JDialog();
dialog.setSize(100, 200);
dialog.setLocationRelativeTo(null);
}
/**
* 显示对话框
*/
public void showDialog() {
dialog.setVisible(true);
}
public static void main(String[] args) {
new TestFrame();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询