一個簡單的對話方塊JDialog
阿新 • • 發佈:2019-02-07
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
public class ChooserSuccessDialog extends JDialog {
public static ChooserSuccessDialog instance;
initialize();
}
public static ChooserSuccessDialog instance(){
if(null == instance){
instance = new ChooserSuccessDialog();
}
return instance;
}
private void initialize() {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int x = 300;
int y = 200;
setBounds(screenSize.width/2-x/2, screenSize.height/2-y/2, x, y);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setResizable(false);
setVisible(true);
Container c = getContentPane();
c.setLayout(null);
JLabel label = new JLabel("匯入成功" );
label.setBounds(x/2-40, y/2-100, 100, 100);
label.setFont(new Font(Font.DIALOG,Font.BOLD,15));
JButton button = new JButton("確定");
button.setBounds(115, 100, 60, 30);
c.add(label);
c.add(button);
button.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
dispose();
}
});
}
public static void main(String[] args) {
ChooserSuccessDialog.instance();
}