使用JAVA GUI画一个椭圆的代码
时间: 2023-05-12 10:03:12 浏览: 187
java绘图 绘制椭圆 实例代码
下面是使用JAVA GUI画一个椭圆的代码:
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Oval extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.RED);
g.drawOval(50, 50, 100, 200);
}
public static void main(String[] args) {
JFrame frame = new JFrame("Oval");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Oval oval = new Oval();
frame.add(oval);
frame.setSize(300, 300);
frame.setVisible(true);
}
}
阅读全文