Graphics 绘图类: 提供两个方法。Paint (绘图,被系统自动调用)    repaint(重绘)

Paint 调用原理(1.窗口最大化,再最小化

  1. 窗口的大小发生变化
  2. 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);
	}
}

最新文章

  1. emulator control无法使用问题
  2. gulp使用
  3. Java:多态(向上转型)
  4. 记录第一次搭建svn服务器
  5. 使用commons-fileupload包进行大文件上传注意事项
  6. WPF ListView展示层叠信息
  7. WPF+WEB+WinForm->>表现层共用类
  8. [转]概率基础和R语言
  9. mongodb replica set(副本集)设置步骤
  10. CentOS 安裝 VMware Workstation / VMware Player
  11. 谈谈android反编译和防止反编译的方法(转)
  12. 面试中的DNS
  13. HDU - 3391 C - Mahjong
  14. bitmap 合并图片
  15. [luogu5004]专心OI - 跳房子【矩阵加速+动态规划】
  16. 【html+css3】在一张jpg图片上,显示多张透明的png图片
  17. Jlink使用技巧之虚拟串口功能
  18. PHP iconv 解决utf-8和gb2312编码转换问题
  19. luogu P4342 [IOI1998]Polygon
  20. 试水Spring Cloud Hystrix

热门文章

  1. git使用的常见命令(一)
  2. UVA_393_Doors_(计算几何基础+最短路)
  3. POJ_3176_Cow_Bowling_(数字三角形)_(动态规划)
  4. AHOI2006文本编辑器editor
  5. android 中对apache httpclient及httpurlconnection的选择
  6. 判斷作業系統為 64bit 或 32bit z
  7. 在windows下编辑shell脚本注意点
  8. TCP三次握手和连接关闭过程详解
  9. Kia's Calculation(HDU 4267)
  10. JavaScript高级程序设计44.pdf