-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathErrorDisplayFrame.java
More file actions
55 lines (40 loc) · 1.28 KB
/
ErrorDisplayFrame.java
File metadata and controls
55 lines (40 loc) · 1.28 KB
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
48
49
50
51
52
53
54
55
package com.ggl.error.display.view;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.sql.SQLException;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class ErrorDisplayFrame {
private final JFrame frame;
public ErrorDisplayFrame() {
this.frame = createAndShowGUI();
}
private JFrame createAndShowGUI() {
JFrame frame = new JFrame("Error Display Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(createMainPanel(), BorderLayout.CENTER);
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true);
return frame;
}
private JPanel createMainPanel() {
JPanel panel = new JPanel(new FlowLayout());
panel.setBorder(BorderFactory.createEmptyBorder(5, 100, 5, 100));
JButton button = new JButton("Generate Exception");
button.addActionListener(event -> {
try {
throwException();
} catch (SQLException e) {
new ErrorDisplayDialog(frame, "Error Message Dialog", e);
}
});
panel.add(button, BorderLayout.CENTER);
return panel;
}
private void throwException() throws SQLException {
throw new SQLException("This is a test SQL Exception");
}
}