import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class FrameWork extends JFrame {
private static final double pi = Math.acos(-1.0);
private static final int Width = 1100;
private static final int Height = 650;
private static JFrame frame = null;
private static int the_time = -1095;
public FrameWork() {
frame = new JFrame("Frame");
frame.setLocationRelativeTo(null);
frame.setSize(Width, Height);
frame.setLocation(100, 30);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
for(int i=0;i<1000;i++) {
JPanel panel = new ImagePanel();
panel.setBounds(0, 0, Width, Height);
frame.getContentPane().add(panel);
frame.setVisible(true);
the_time +=5;
}
}
class ImagePanel extends JPanel {
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.WHITE);
g.fillRect(0, 0, Width, Height);
if(the_time < 0) {
g.setColor(Color.BLACK);
g.setFont(new Font("MS UI Gothic", Font.PLAIN, 50));
g.drawString(""+(-the_time/100), 50, 50);
}
int[] x = {500, 550, 150, 300, 800, 850, 950, 100};
int[] y = {500, 250, 200, 100, 190, 300, 450, 420};
g.setColor(Color.GRAY);
for(int i=0;i<8;i++)
for(int j=i+1;j<8;j++) {
g.drawLine(x[i], y[i], x[j], y[j]);
}
int[][] d = new int[8][8];
for(int i=0;i<8;i++)
for(int j=0;j<8;j++)
d[i][j] = (int)Math.sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
int[] start = new int[8];
start[0] = 0;
for(int i=1;i<=4;i++) start[i] = start[i-1] + d[i-1][i];
int d_long = 0;
for(int i=1;i<8;i++) if(d[0][i] > d_long) d_long = d[0][i];
int end_time = start[4] + d[0][4] + d_long;
if(the_time <= 0) g.setColor(Color.YELLOW);
else if(the_time > end_time-d_long) g.setColor(Color.RED);
else g.setColor(Color.ORANGE);
g.fillRect(x[0]-15, y[0]-30, 30, 30);
g.setColor(Color.BLACK);
g.drawRect(x[0]-15, y[0]-30, 30, 30);
if(the_time <= 0) g.setColor(Color.YELLOW);
else if(the_time > end_time-d_long) g.setColor(Color.RED);
else g.setColor(Color.ORANGE);
g.fillOval(x[0]-30, y[0]-20, 60, 40);
g.setColor(Color.BLACK);
g.drawOval(x[0]-30, y[0]-20, 60, 40);
for(int i=1;i<=4;i++) {
if(the_time <= start[i]) g.setColor(Color.BLUE);
else g.setColor(Color.darkGray);
g.fillRect(x[i]-15, y[i]-15, 30, 30);
g.setColor(Color.BLACK);
g.drawRect(x[i]-15, y[i]-15, 30, 30);
}
for(int i=5;i<8;i++) {
g.setColor(Color.GREEN);
g.fillOval(x[i]-15, y[i]-15, 30, 30);
g.setColor(Color.BLACK);
g.drawOval(x[i]-15, y[i]-15, 30, 30);
}
for(int i=0;i<5;i++) {
if(the_time > start[i]) {
int left_time = the_time - start[i];
for(int j=0;j<8;j++) {
if(i == j) continue;
if(d[i][j] > left_time) {
int xx = x[i] + (int)((double)(x[j]-x[i])*left_time/(double)d[i][j]);
int yy = y[i] + (int)((double)(y[j]-y[i])*left_time/(double)d[i][j]);
g.setColor(Color.CYAN);
g.fillOval(xx-5, yy-5, 10, 10);
}
}
}
}
if(the_time>end_time-d_long) {
for(int i=1;i<8;i++) {
int left_time = the_time - end_time + d_long;
if(left_time > d[0][i]) {
if(i>4) {
g.setColor(Color.RED);
g.fillOval(x[i]-15, y[i]-15, 30, 30);
g.setColor(Color.BLACK);
g.drawOval(x[i]-15, y[i]-15, 30, 30);
} else {
g.setColor(Color.RED);
g.fillRect(x[i]-15, y[i]-15, 30, 30);
g.setColor(Color.BLACK);
g.drawRect(x[i]-15, y[i]-15, 30, 30);
}
} else {
int xx = x[0] + (int)((double)(x[i]-x[0])*left_time/(double)d[0][i]);
int yy = y[0] + (int)((double)(y[i]-y[0])*left_time/(double)d[0][i]);
g.setColor(Color.RED);
g.fillOval(xx-5, yy-5, 10, 10);
}
}
}
g.setColor(Color.WHITE);
g.setFont(new Font("MS UI Gothic", Font.PLAIN, 30));
for(int i=1;i<=4;i++) {
g.drawString(""+i, x[i]-7, y[i]+7);
}
}
}
public static void main(String[] args) {
new FrameWork();
}
}
posted on 2015-06-08 01:55
marchalex 阅读(234)
评论(0) 编辑 收藏 所属分类:
java小程序