zoukankan      html  css  js  c++  java
  • 设计模式

    模板方法模式(template method pattern) JFrame 具体解释


    本文地址: http://blog.csdn.net/caroline_wendy


    參考模板方法模式(template method pattern): http://blog.csdn.net/caroline_wendy/article/details/32159455


    模板方法模式(template method pattern), Java的JFrame使用模板方法模式, paint()是能够覆盖的方法, 

    覆盖paint()方法, 能够定制JFrame的显示画面.


    代码:

    /**
     * @time 2014年6月20日
     */
    package template_method.jframe;
    
    import java.awt.Graphics;
    
    import javax.swing.JFrame;
    
    /**
     * @author C.L.Wang
     *
     */
    public class MyFrame extends JFrame {
    
    	public MyFrame(String title) {
    		// TODO Auto-generated constructor stub
    		super(title);
    		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		
    		this.setSize(300, 300);
    		this.setVisible(true);
    	}
    	
    	public void paint(Graphics graphics) {
    		super.paint(graphics);
    		String msg = "I am a girl! ";
    		graphics.drawString(msg, 100, 100);
    	}
    	
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		MyFrame myFrame = new MyFrame("Head First Design Patterns");
    	}
    
    }
    

    输出:








  • 相关阅读:
    luogu_1414 又是毕业季II
    luogu_1372 又是毕业季I
    luogu_1313 计算系数
    luogu_1134 阶乘问题
    luogu_1514 引水入城
    luogu_1120 小木棍
    文件操作
    快速排序
    c oth
    ANSI C与C89、C99、C11区别差异
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/5093052.html
Copyright © 2011-2022 走看看