Java绘图:绘制红色圆形和黄色直线
import java.awt.Color; import java.awt.Graphics; import javax.swing.JFrame; import javax.swing.JPanel;
public class DrawCircleAndLine extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g); // 画红色圆 g.setColor(Color.RED); g.fillOval(100, 100, 50, 50); // 画黄色直线 g.setColor(Color.YELLOW); g.drawLine(50, 50, 200, 200); }
public static void main(String[] args) { JFrame frame = new JFrame('DrawCircleAndLine'); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300, 300); DrawCircleAndLine panel = new DrawCircleAndLine(); frame.add(panel); frame.setVisible(true); } }
原文地址: https://www.cveoy.top/t/topic/nPVN 著作权归作者所有。请勿转载和采集!