用Java编写一个绘制8个同心圆的程序
编写一个绘制8个同心圆的程序。相邻各圆之间相隔10个像素。提示:使用Graphics类的drawOval方法。...
编写一个绘制8个同心圆的程序。相邻各圆之间相隔10个像素。提示:使用Graphics类的drawOval方法。
展开
1个回答
展开全部
*********************MultiCircle.java************************
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
public class MultiCircle extends JPanel {
private BufferedImage bi = new BufferedImage(320, 240,
BufferedImage.TYPE_INT_BGR);
public MultiCircle() {
setPreferredSize(new Dimension(320, 240));
}
public void paintComponent(Graphics g) {
int radius = 50;
g.setColor(Color.red);
for (int i = 1; i <= 5; i++) {
g.drawOval(150 - (radius + 10 * i), 150 - (radius + 10 * i),
(radius + 10 * i) * 2, (radius + 10 * i) * 2);
}
}
public static void main(String[] args) {
JFrame frame = new JFrame("MultiCircle");
frame.add(new MultiCircle());
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
public class MultiCircle extends JPanel {
private BufferedImage bi = new BufferedImage(320, 240,
BufferedImage.TYPE_INT_BGR);
public MultiCircle() {
setPreferredSize(new Dimension(320, 240));
}
public void paintComponent(Graphics g) {
int radius = 50;
g.setColor(Color.red);
for (int i = 1; i <= 5; i++) {
g.drawOval(150 - (radius + 10 * i), 150 - (radius + 10 * i),
(radius + 10 * i) * 2, (radius + 10 * i) * 2);
}
}
public static void main(String[] args) {
JFrame frame = new JFrame("MultiCircle");
frame.add(new MultiCircle());
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询