⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 globe.java

📁 java2图形设计卷1:awt 源码
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;

public class Globe extends Frame {
	Image globe;
	Toolkit tk = Toolkit.getDefaultToolkit();

	public static void main(String args[]) {
		Frame f = new Globe();
		f.show();
	}
	public Globe() {
		super("globe");
		globe = tk.getImage("globe.gif");

		try {
			MediaTracker mt = new MediaTracker(this);
			mt.addImage(globe,0);
			mt.waitForID(0);
		}
		catch(Exception e) { e.printStackTrace(); }

		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent event) {
				dispose();
				System.exit(0);
			}
		});
	}
	public void addNotify() {
		super.addNotify(); // this instantiates the peer

		Insets 	  insets = getInsets();
		Dimension scrnsz = tk.getScreenSize();
		Dimension globesz = new Dimension(globe.getWidth(this), 
											globe.getHeight(this));

		setBounds((scrnsz.width/2) - (globesz.width/2),
				  (scrnsz.height/2) - (globesz.height/2),
				  globesz.width + insets.left + insets.right, 
				  globesz.height + insets.top + insets.bottom);
	}
	public boolean imageUpdate(Image image, int flags, 
								int x, int y, int w, int h) {
		if((flags & FRAMEBITS) != 0) {
			try {
				Thread.currentThread().sleep(500);
			}
			catch(Exception e) {
				e.printStackTrace();
			}
			repaint();
		}
	  	return true;
	}
	public void paint(Graphics g) {
		Insets insets = getInsets();
	  	g.drawImage(globe,insets.left,insets.top,this);
	}
	public void update(Graphics g) {
		paint(g);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -