首页 > 其他 > 详细

设计模式 - 模板方法模式(template method pattern) JFrame 详解

时间:2014-06-22 21:35:38      阅读:334      评论:0      收藏:0      [点我收藏+]

模板方法模式(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");
	}

}

输出:

bubuko.com,布布扣





bubuko.com,布布扣


设计模式 - 模板方法模式(template method pattern) JFrame 详解,布布扣,bubuko.com

设计模式 - 模板方法模式(template method pattern) JFrame 详解

原文:http://blog.csdn.net/caroline_wendy/article/details/32718135

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!