-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWarningDialog.java
47 lines (40 loc) · 1.38 KB
/
WarningDialog.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author 15002
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class WarningDialog extends JPanel {
private boolean willDisplay = true;
public WarningDialog(String text) {
JButton confirmBtn = new JButton("Confirm");
confirmBtn.addActionListener(this::confirmAction);
JCheckBox dontAskMeAgain= new JCheckBox("Don't ask me again");
dontAskMeAgain.addItemListener(this::doNotDisplay);
setLayout(new BorderLayout());
add(new JLabel(text));
JPanel subPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
subPanel.add(dontAskMeAgain);
add(subPanel,BorderLayout.SOUTH);
}
public void doNotDisplay(ItemEvent evt){
willDisplay = !(evt.getStateChange() == 1);
}
private void confirmAction(ActionEvent evt){
setVisible(false);
}
public int showConfirmDialog(Component parent) {
int result = JOptionPane.YES_OPTION;
if(willDisplay)
result = JOptionPane.showConfirmDialog(parent, this,
"WARNING",
JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE);
return result;
}
}