用java编写在界面中画圆_用java语言编写画随机的圆 十万火急 求大神帮忙!!!...
时间: 2024-03-14 10:48:06 浏览: 18
好的,我可以为您提供一些参考代码来在Java界面中画圆。
以下是一个简单的Java程序,它使用Java Swing库中的Graphics2D类来画圆:
```java
import java.awt.*;
import javax.swing.*;
public class DrawCircle extends JFrame {
public DrawCircle() {
setTitle("Draw Circle");
setSize(400, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.RED);
int x = (int) (Math.random() * 350);
int y = (int) (Math.random() * 350);
int size = (int) (Math.random() * 50);
g2d.fillOval(x, y, size, size);
}
public static void main(String[] args) {
new DrawCircle();
}
}
```
这个程序创建了一个窗口,并在其中画了一个随机大小和位置的圆。
希望这可以帮助到您!