zoukankan      html  css  js  c++  java
  • Java SE (2)之 Graphics 画图工具

    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);
    	}	
    }
    
  • 相关阅读:
    manacher(求最大回文串并返回)
    编程求一个后缀表达式的值
    栈的简单使用
    云计算的概念
    乐优商城
    四大函数型接口
    Stream流计算
    JWT实现无状态登录
    Thymeleaf模板引擎
    elasticSearch的使用
  • 原文地址:https://www.cnblogs.com/sunxun/p/3833621.html
Copyright © 2011-2022 走看看