1 class SizedFrame extends JFrame 2 { 3 public SizedFrame() 4 { 5 // get screen dimensions 6 7 Toolkit kit = Toolkit.getDefaultToolkit(); 8 Dimension screenSize = kit.getScreenSize(); 9 int screenHeight = screenSize.height; 10 int screenWidth = screenSize.width; 11 12 13 // set frame width, height and let platform pick screen location 14 15 setSize(screenWidth / 2, screenHeight / 2); 16 setLocationByPlatform(true); 17 18 // set frame icon 19 20 Image img = new ImageIcon("icon.gif").getImage(); 21 setIconImage(img); 22 23 } 24 }
时间: 2024-10-05 22:12:12