import javax.swing.*; import java.awt.*; public class Example runnian extends JFrame //当前类继承自JFrame,可生成框架 { public Example runnian() { Pan p=new Pan(); //框架中加载面板 this.add(p); } public static void main(String[] args) { Example runnian t=new Example runnian(); //生成框架对象 t.setSize(400,400); //设定大小 t.setVisible(true);; //设定可视 t.setDefaultCloseOperation(t.EXIT_ON_CLOSE);//设置右上角关闭图标 } } class Pan extends JPanel { public void paint(Graphics g) //显示各种图形的paint()方法 { g.drawLine(50,50,100,100); //绘制直线 g.fillOval(100,100,50,50); //绘制椭圆 g.drawRect(300,200,50,100); //绘制矩形 g.fillRoundRect(200,100,100,50,10,20);//绘制圆角矩形 g.fillArc(200,200,100,200,100,100);//椭圆弧框 } }
评论