test.java

来自「swing 教程,与大家分享一下,哈哈,希望大家多多指教」· Java 代码 · 共 46 行

JAVA
46
字号
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Test extends JApplet {
	Rectangle r1 = new Rectangle(20,20,150,75);
	Rectangle r2 = new Rectangle(100,40,100,150);
	Rectangle destination;

	public Test() {
		destination = new Rectangle(r2);

		// print out the intersection of r1 and r2 ...

		System.out.println("Intersection:  " + 
			SwingUtilities.computeIntersection(r1.x,r1.y,
							r1.width,r1.height,destination));
		System.out.println();

		// print out the union of r1 and r2 ...

		System.out.println("Union:  " + 
			SwingUtilities.computeUnion(r1.x,r1.y,
							r1.width,r1.height,destination));
		System.out.println();

		// print out the difference of r1 and r2 ...

		Rectangle[] difference =
					SwingUtilities.computeDifference(r1, r2);

		System.out.println("Difference:");

		for(int i=0; i < difference.length; ++i) {
			System.out.println(difference[i]);
		}
	}
	public void paint(Graphics g) {
		g.setColor(Color.red);		
		g.fillRect(r1.x, r1.y, r1.width, r1.height);

		g.setColor(Color.yellow);		
		g.fillRect(r2.x, r2.y, r2.width, r2.height);
	}
}

⌨️ 快捷键说明

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