package 第一版;
import java.awt.*;
import javax.swing.*;
import javax.tools.Tool;
public class draw1 extends JFrame{
MyPanel mp = null;
public draw1() {
mp = new MyPanel();
this.add(mp);
this.setSize(400, 300); // 设置框体大小
this.setLocation(400,150); //设置框体显示的位置
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 设置框体退出
this.setVisible(true); // 显示框体
}
public static void main(String[] args) {
draw1 d = new draw1();
}
}
// 我的画板
// Graphics是一个很重要的画图的类,可以理解成一支毛笔
class MyPanel extends Panel{
public void paint(Graphics g){ // 重写paint函数,系统会自动调用函数
// super.paint(g);
// g.drawOval(100, 10, 30, 30); // 画圆
// g.drawLine(30, 50, 40, 70);
// g.drawRect(50, 50, 40, 30); // 画矩形
// g.setColor(Color.blue); // 设置画笔颜色
// g.fillRect(100, 100, 40, 70); // 填充矩形
// try{
// Image im = Toolkit.getDefaultToolkit().getImage(Panel.class.getResource("/2013-10-25-19.jpg"));
// // 图片放在src目录下
// g.drawImage(im, 90, 90, 200, 150, this);
// }catch(Exception e){
// System.out.println("yes");
// }
g.setColor(Color.RED);
g.setFont(new Font("华文彩云",Font.BOLD,30));
g.drawString("祖国万岁!", 100, 100);
}
}
java绘图技术(一)
最新推荐文章于 2023-04-24 15:18:42 发布