import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class TestSanmo extends JFrame {
public TestSanmo() {
add(new Sanmo());
}
public static void main(String[] args) {
JFrame frame = new TestSanmo();
frame.setTitle("TestSanmo");
frame.setSize(210, 330);
frame.setLocationRelativeTo(null); // Center the frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class Sanmo extends JPanel{
//定义多边形坐标数组
int polygon_x[]={5,20,25,175,180,195,5};
int polygon_y[]={300,270,230,230,270,300,300};
int polygon_pt_num=7;
public void paintComponent(Graphics g){
int red,green,blue;
//画头部,椭圆方法drawOval
g.setColor(Color.black); //setColor用来设置要使用的颜色
g.drawOval(40,40,120,150);
//画眼睛,椭圆方法drawOval
g.drawOval(57,75,30,20);
g.drawOval(110,75,30,20);
//画眼珠,填充椭圆方法fillOval
g.fillOval(68,81,10,10);
g.fillOval(121,81,10,10);
//画鼻子,椭圆方法drawOval
g.drawOval(85,100,30,30);
//画头发,直线方法drawLine,画弧方法drawArc
g.drawLine(100,10,100,60);
g.drawArc(110,20,100,80,90,90);
//drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
g.drawArc(10,30,80,60,0,80);
//画嘴巴,填充画弧方法fillArc
g.setColor(Color.red);
g.fillArc(60,130,80,40,180,180);
//画耳朵,填充椭圆方法fillOval,复制图形方法copyArea
g.setColor(Color.blue);
g.fillOval(25,92,15,30);
g.copyArea(25,92,15,30,136,0); //拷贝某区域的图形至另一区域
//copyArea(int x, int y, int width, int height, int dx, int dy)
//Copies an area of the component by a distance specified by dx and dy.
//136--宽度差dx; 0--高度差dy;
//画脖子,填充矩形方法fillRect
g.setColor(Color.pink);
g.fillRect(85,190,30,40);
//画身体,多边形方法fillPolygon
red=30;
blue=100;
green=200;
g.setColor(new Color(red,green,blue));
g.fillPolygon(polygon_x,polygon_y,polygon_pt_num);
}
}
在面板上“画”三毛(Java)
原创
©著作权归作者所有:来自51CTO博客作者mb614decb9ad0b0的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:算数测试(Java实验)
下一篇:窗体程序计算一元二次方程
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Vue3集成UE5像素流
Vue3集成UE5像素流
vue3 ue5 -
PixelPic - 像素化/像素风格/像素画/像素艺术
PixelPic 是将普通图像转变为令人惊叹的像素艺术杰作的终极工具。非常适合艺术家、设计师和像素艺术爱好者!
图像处理 图形渲染 贴图 用户运营 流量运营