📄 insure.java
字号:
package OS;
import java.awt.*;
import javax.swing.*;
import java.awt.Dimension;
import java.awt.BorderLayout;
import java.awt.Rectangle;
import java.math.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2008</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class Insure
extends JFrame {
int x[] = {
70, 390, 390};
int y[] = {
270, 150, 270};
JPanel contentPane;
MyCanvas c;
JButton jButton1 = new JButton();
public Insure() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
}
catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
c = new MyCanvas();
c.setBackground(Color.white);
setSize(new Dimension(800, 700));
setLayout(null);
c.setBackground(Color.white);
c.setVisible(true);
c.setBounds(new Rectangle(0, 0, 700, 700));
jButton1.setBounds(new Rectangle(701, 324, 76, 28));
jButton1.setText("重组");
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
contentPane.add(c, null);
contentPane.add(jButton1);
}
public void jButton1_actionPerformed(ActionEvent e) {
c.draw(c.getGraphics(), 5, 6, x, y, Color.red);
}
}
class MyCanvas
extends Canvas {
Image buffer;
Graphics pic;
int w, h, k = 1;
int x[] = {
70, 390, 390};
int y[] = {
270, 150, 270};
int a[] = {
390, 590, 590};
int b[] = {
150, 70, 150};
int c[] = {
390, 590, 590, 470, 470, 390};
int d[] = {
150, 150, 190, 190, 230, 230};
int e[] = {
390, 470, 470, 590, 590, 390};
int f[] = {
230, 230, 190, 190, 270, 270};
int x1[] = {
270, 590, 590};
int y1[] = {
510, 390, 510};
int a1[] = {
70, 270, 270};
int b1[] = {
590, 510, 590};
int c1[] = {
270, 470, 470, 350, 350, 270};
int d1[] = {
510, 510, 550, 550, 590, 590};
int e1[] = {
390, 470, 470, 590, 590, 390};
int f1[] = {
550, 550, 510, 510, 590, 590};
public MyCanvas() {
}
public void paint(Graphics g) {
if (k == 1) {
init(g);
w = getWidth();
h = getHeight();
buffer = this.createImage(w, h);
pic = buffer.getGraphics();
init(pic);
k = 2;
}
else {
g.drawImage(buffer, 0, 0, this);
}
}
public static void pause() {
try {
Thread.sleep(200);
}
catch (InterruptedException ex) {
}
}
public void draw(Graphics gg, int offsetx, int offsety, int[] m, int[] n,Color color) {
Graphics2D g = (Graphics2D) gg;
int mode = AlphaComposite.SRC_OVER;
float alpha =0.5f;
AlphaComposite ac = AlphaComposite.getInstance(mode, alpha);
g.setComposite(ac);
for (int i = 0; i < Math.abs(offsety) * 8; i++) {
this.pause();
for (int j = 0; j < n.length; j++) {
n[j] += (int) (5 * offsety / Math.abs(offsety));
}
g.setColor(color);
g.fillPolygon(m, n, n.length);
g.setColor(Color.BLACK);
g.drawPolygon(m, n, n.length);
this.paint(g);
}
for (int i = 0; i < Math.abs(offsetx) * 8; i++) {
for (int j = 0; j < m.length; j++) {
m[j] += (int) (5 * offsetx / Math.abs(offsetx));
}
this.pause();
g.setColor(color);
g.fillPolygon(m, n, m.length);
g.setColor(Color.BLACK);
g.drawPolygon(m, n, m.length);
this.paint(g);
}
g.setColor(color);
g.fillPolygon(m, n, m.length);
g.setColor(Color.BLACK);
g.drawPolygon(m, n, m.length);
}
public void update(Graphics g) {
paint(g);
}
public void init(Graphics g) {
g.setColor(Color.red);
g.fillPolygon(x, y, 3);
g.fillPolygon(x1, y1, 3);
g.setColor(Color.blue);
g.fillPolygon(a, b, 3);
g.fillPolygon(a1, b1, 3);
g.setColor(Color.orange);
g.fillPolygon(c, d, 6);
g.fillPolygon(c1, d1, 6);
g.setColor(Color.green);
g.fillPolygon(e, f, 6);
g.fillPolygon(e1, f1, 6);
g.setColor(Color.black);
g.drawPolygon(x, y, 3);
g.drawPolygon(a, b, 3);
g.drawPolygon(c, d, 6);
g.drawPolygon(e, f, 6);
g.drawPolygon(x1, y1, 3);
g.drawPolygon(a1, b1, 3);
g.drawPolygon(c1, d1, 6);
g.drawPolygon(e1, f1, 6);
for (int i = 0; i < 17; i++) {
g.drawLine(30, 30 + i * 40, 670, 30 + i * 40);
if (i > 0) {
g.drawString(i + "", 27 + 40 * i, 685);
}
}
for (int j = 0; j < 17; j++) {
g.drawLine(30 + j * 40, 30, 30 + j * 40, 670);
if (j < 10) {
g.drawString(" " + j, 10, 670 - j * 40);
}
else {
g.drawString(j + "", 10, 677 - j * 40);
}
}
g.setColor(Color.red);
g.drawLine(70,270,590,70);
g.drawLine(70,590,590,390);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -