testpattern.java

来自「exploring Java 2ed edition 附带的例子程序」· Java 代码 · 共 43 行

JAVA
43
字号
import java.awt.*;import java.awt.event.*;public class TestPattern extends java.applet.Applet { 	int theta = 45;	public void paint( Graphics g ) {		int Width = size().width;		int Height = size().height;		int width = Width/2;		int height = Height/2;		int x = (Width - width)/2;		int y = (Height- height)/2;		int [] polyx =  { 0, Width/2, Width, Width/2 };		int [] polyy =  { Height/2, 0, Height/2, Height };		Polygon poly = new Polygon( polyx, polyy, 4 );				g.setColor( Color.black );		g.fillRect( 0, 0, size().width, size().height );		g.setColor( Color.yellow );		g.fillPolygon( poly );		g.setColor( Color.red );		g.fillRect( x, y, width, height );		g.setColor( Color.green );		g.fillOval( x, y, width, height );		g.setColor( Color.blue );		int delta = 90;		g.fillArc( x, y, width, height, theta, delta );		g.setColor( Color.white );		g.drawLine( x, y, x+width, x+height );	}	public void init() {		addMouseListener( new MouseAdapter() {			public void mousePressed( MouseEvent e ) {				theta = (theta + 10) % 360;				repaint();			}		} );	}}

⌨️ 快捷键说明

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