2个回答
展开全部
import javax.swing.*;
import java.awt.*;
public class ex1_shapes extends JFrame{
/**
* @param args
*/
public ex1_shapes(){
super("实验一:直线、圆弧、多边形");
setSize(500,500);
show();
}
public void paint(Graphics g){
super.paint(g);
//直线演示
g.setColor(Color.BLUE);
g.drawLine(10, 10, 80, 150);
g.drawString("直线演示",50,50);
// 圆弧演示 显示“CS”
g.setColor(Color.green);
g.drawArc(180, 50, 50, 90, 30, 300); //c
g.drawArc(250, 50, 50, 45, 30,250); g.drawArc(250, 95, 50, 45, 90, -270); //S
g.drawString("圆弧演示",330,50);
//多边形 五角星
g.setColor(Color.RED);
int[] xpoints1={100,120,200,136,160,100,40,64,0,80};
int[] ypoints1={210,270,270,326,410,357,410,326,270,270};
g.drawPolygon(xpoints1, ypoints1, 10);
g.drawString("折线段演示",80,440);
//填充五角星
int[] xpoints2={350,370,450,386,410,350,290,314,250,330};
int[] ypoints2={210,270,270,326,410,357,410,326,270,270};
g.fillPolygon(xpoints2, ypoints2, 10);
g.drawString("填充图演示",330,440);
}
public static void main(String[] args) {
ex1_shapes demo=new ex1_shapes();
demo.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
// TODO 自动生成方法存根
}
}
刚做过的实验 上面代码可以运行
第一部分就是画直线的 顺便圆弧的也贴出来了 有注释 把BLUE改成GREEN就可以了
就是用Graphics类的draoLine()方法
g.drawLine(10, 10, 80, 150); 也可以用Graphics2D的方法~
import java.awt.*;
public class ex1_shapes extends JFrame{
/**
* @param args
*/
public ex1_shapes(){
super("实验一:直线、圆弧、多边形");
setSize(500,500);
show();
}
public void paint(Graphics g){
super.paint(g);
//直线演示
g.setColor(Color.BLUE);
g.drawLine(10, 10, 80, 150);
g.drawString("直线演示",50,50);
// 圆弧演示 显示“CS”
g.setColor(Color.green);
g.drawArc(180, 50, 50, 90, 30, 300); //c
g.drawArc(250, 50, 50, 45, 30,250); g.drawArc(250, 95, 50, 45, 90, -270); //S
g.drawString("圆弧演示",330,50);
//多边形 五角星
g.setColor(Color.RED);
int[] xpoints1={100,120,200,136,160,100,40,64,0,80};
int[] ypoints1={210,270,270,326,410,357,410,326,270,270};
g.drawPolygon(xpoints1, ypoints1, 10);
g.drawString("折线段演示",80,440);
//填充五角星
int[] xpoints2={350,370,450,386,410,350,290,314,250,330};
int[] ypoints2={210,270,270,326,410,357,410,326,270,270};
g.fillPolygon(xpoints2, ypoints2, 10);
g.drawString("填充图演示",330,440);
}
public static void main(String[] args) {
ex1_shapes demo=new ex1_shapes();
demo.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
// TODO 自动生成方法存根
}
}
刚做过的实验 上面代码可以运行
第一部分就是画直线的 顺便圆弧的也贴出来了 有注释 把BLUE改成GREEN就可以了
就是用Graphics类的draoLine()方法
g.drawLine(10, 10, 80, 150); 也可以用Graphics2D的方法~
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询