可以考虑多画几个 import java.awt.*; import javax.swing.*;public class Test extends JFrame { public Test() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setPreferredSize(new Dimension(800, 600)); pack(); setVisible(true); }
public void drawOval(Graphics g, int x, int y, int w, int h, int num) { for(int i = 0; i < num; i++) { g.drawOval(x + i, y + i, w - 2 * i, h - 2 * i); } }
import java.awt.*;
import javax.swing.*;public class Test extends JFrame
{
public Test()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setPreferredSize(new Dimension(800, 600));
pack();
setVisible(true);
}
public void drawOval(Graphics g, int x, int y, int w, int h, int num)
{
for(int i = 0; i < num; i++)
{
g.drawOval(x + i, y + i, w - 2 * i, h - 2 * i);
}
}
public void paint(Graphics g)
{
drawOval(g, 100, 100, 100, 200, 3);
drawOval(g, 300, 300, 100, 100, 1);
}
public static void main(String[] args)
{
new Test();
}
}
public void paintComponent(Graphics g) {
Graphics2D gg = (Graphics2D)g;
gg.setStroke(new BasicStroke(15.0f));
gg.drawOval(.....);
}