Java--->奥运五环
原创
©著作权归作者所有:来自51CTO博客作者飝鱻?的原创作品,请联系作者获取转载授权,否则将追究法律责任
Java--->奥运五环
import javax.swing.*;
import java.awt.*;
public class Exam3 extends JFrame {
int HEIGHT = 150;
int WEIGHT = 150;
Color [] color ={Color.BLUE,Color.black,Color.RED, Color.YELLOW, Color.GREEN};
int [] x = {100,250,400,175,325};
int [] y = {100,100,100,200,200};
public void paint(Graphics g){
Graphics2D g1 = (Graphics2D)g;
BasicStroke basicStroke = new BasicStroke(3);
g1.setStroke(basicStroke);
for (int i=0;i<5;i++){
g1.setColor(color[i]);
g1.drawOval(x[i],y[i],HEIGHT,WEIGHT);
}
// g1.setColor(color[0]);
// g1.drawOval(100,100,HEIGHT,WEIGHT);
}
public Exam3() {
this.setSize(900, 700);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main(String[] args) {
new Exam3();
}
}
-
效果图