Skip to content

Commit ca2c410

Browse files
committed
BAEL-5421
1 parent 997a695 commit ca2c410

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

core-java-modules/core-java-jar/src/main/java/com/baeldung/jar/MySampleGUIAppn.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,24 @@
77

88
public class MySampleGUIAppn extends JFrame{
99
public MySampleGUIAppn() {
10-
setSize(300,300);
11-
setTitle("MySampleGUIAppn");
12-
Button b = new Button("Click Me!");
13-
b.setBounds(30,100,80,30);
14-
add(b);
1510
if (!GraphicsEnvironment.isHeadless()) {
11+
setSize(300,300);
12+
setTitle("MySampleGUIAppn");
13+
Button b = new Button("Click Me!");
14+
b.setBounds(30,100,80,30);
15+
add(b);
1616
setVisible(true);
17+
addWindowListener(new WindowAdapter() {
18+
public void windowClosing(WindowEvent e) {
19+
dispose();
20+
System.exit(0);
21+
}
22+
});
23+
24+
}
25+
else {
26+
System.exit(0);
1727
}
18-
addWindowListener(new WindowAdapter() {
19-
public void windowClosing(WindowEvent e) {
20-
dispose();
21-
System.exit(0);
22-
}
23-
});
2428
}
2529
public static void main(String[] args) {
2630
MySampleGUIAppn app=new MySampleGUIAppn();

core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/MySampleGUIAppnUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class MySampleGUIAppnUnitTest {
88

99
@Test
1010
void testMain() throws IOException {
11-
System.setProperty("java.awt.headless", "true");
11+
System.setProperty("java.awt.headless", "false");
1212
MySampleGUIAppn instance = new MySampleGUIAppn();
1313
String [] args = null;
1414
System.exit(0);

0 commit comments

Comments
 (0)