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");
    	}
    
    }
    

    输出:








  • 相关阅读:
    Codeforces 716C[数论][构造]
    HDU 5808[数位dp]
    Codeforces 611d [DP][字符串]
    Codeforces 404D [DP]
    HDU 5834 [树形dp]
    HDU 5521 [图论][最短路][建图灵感]
    矩阵
    kruskal 处理最短路 问题 A: 还是畅通工程
    Dijastra最短路 + 堆优化 模板
    CodeForces
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/5093052.html
Copyright © 2011-2022 走看看