1.AWT和Swing中框架和组件类的继承层次。
2.组件类的很多方法是以获取或设置方法对形式出现的。
public String getTitle(); public void setTitle(Stirng title);
public boolean isLocationByPlatform(); public void setLocationByPlatform(boolean b);
5.Toolkit类中有获取屏幕大小的方法。
Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screenSize = kit.getScreenSize(); int screenHeight = screenSize.height; int screenWidth = screenSize.width;
Image img = new ImageIcon("icon.gif").getImage(); setIconImage(img);
8.如果编写一个使用多个显示屏的应用程序,可以利用GraphicsEnvironment和GraphicsDevice类来获得显示屏的大小。
实例代码
测试类
import java.awt.EventQueue; import javax.swing.JFrame; public class test { public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { JFrame frame = new SizeFrame(); frame.setTitle("测试一下"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }); } }
import java.awt.Dimension; import java.awt.Image; import java.awt.Toolkit; import javax.swing.ImageIcon; import javax.swing.JFrame; public class SizeFrame extends JFrame{ public SizeFrame() { Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screenSize = kit.getScreenSize(); int screenHeight = screenSize.height; int screenWidth = screenSize.width; setSize(screenWidth / 2,screenHeight / 2); setLocationByPlatform(true); Image img = new ImageIcon("icon.gif").getImage(); setIconImage(img); } }
原文地址:http://blog.csdn.net/zhurui_idea/article/details/44925941