Java SE (2)之 Graphics 画图工具
2024-10-12 21:01:12
Graphics 绘图类: 提供两个方法。Paint (绘图,被系统自动调用) repaint(重绘)
Paint 调用原理(1.窗口最大化,再最小化
- 窗口的大小发生变化
- Repaint函数被调用)
package com.sunzhiyan;
import java.awt.*;
import javax.swing.*; public class Demo_5 extends JFrame{
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Demo_5 demo5 = new Demo_5();
}
public Demo_5() {
//将面板实例化加载到窗体里面
Mypanel panel = new Mypanel();
this.add(panel); this.setTitle("draw");
this.setLocation(400, 200);
this.setSize(400, 400);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
//super();
// TODO Auto-generated constructor stub
}
}
//定义一个面板,用来画图
class Mypanel extends JPanel{
//定义一个画笔工具
public void paint (Graphics g){
//兼容写法
super.paint(g);
g.drawRect(40, 40, 40, 40);
//填充矩形
g.fillRect(20, 20, 40, 40);
//写文字 g.setFont(new Font("华文彩云",Font.BOLD,30)); g.drawString("你好", 60, 60);
}
}
最新文章
- emulator control无法使用问题
- gulp使用
- Java:多态(向上转型)
- 记录第一次搭建svn服务器
- 使用commons-fileupload包进行大文件上传注意事项
- WPF ListView展示层叠信息
- WPF+WEB+WinForm->;>;表现层共用类
- [转]概率基础和R语言
- mongodb replica set(副本集)设置步骤
- CentOS 安裝 VMware Workstation / VMware Player
- 谈谈android反编译和防止反编译的方法(转)
- 面试中的DNS
- HDU - 3391 C - Mahjong
- bitmap 合并图片
- [luogu5004]专心OI - 跳房子【矩阵加速+动态规划】
- 【html+css3】在一张jpg图片上,显示多张透明的png图片
- Jlink使用技巧之虚拟串口功能
- PHP iconv 解决utf-8和gb2312编码转换问题
- luogu P4342 [IOI1998]Polygon
- 试水Spring Cloud Hystrix
热门文章
- git使用的常见命令(一)
- UVA_393_Doors_(计算几何基础+最短路)
- POJ_3176_Cow_Bowling_(数字三角形)_(动态规划)
- AHOI2006文本编辑器editor
- android 中对apache httpclient及httpurlconnection的选择
- 判斷作業系統為 64bit 或 32bit z
- 在windows下编辑shell脚本注意点
- TCP三次握手和连接关闭过程详解
- Kia's Calculation(HDU 4267)
- JavaScript高级程序设计44.pdf