-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSizedFrameTest.java
More file actions
41 lines (33 loc) · 1.09 KB
/
SizedFrameTest.java
File metadata and controls
41 lines (33 loc) · 1.09 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
package sizedFrame;
import javax.swing.*;
import java.awt.*;
/**
* @author Cay Horstmann
* @version 1.34 2015-06-16
*/
public class SizedFrameTest {
public static void main(String[] args) {
EventQueue.invokeLater(() -> {
JFrame frame = new SizedFrame();
frame.setTitle("SizedFrame");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
});
}
}
class SizedFrame extends JFrame {
public SizedFrame() {
// get screen dimensions
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
int screenHeight = screenSize.height;
int screenWidth = screenSize.width;
// set frame width, height and let platform pick screen location
setSize(screenWidth / 2, screenHeight / 2);
setLocationByPlatform(true);
// set frame icon
// Image img = new ImageIcon("icon.gif").getImage();
Image img = new ImageIcon(ClassLoader.getSystemResource("icon.gif")).getImage();
setIconImage(img);
}
}