mybutton.java

来自「扫雷的源代码,包结构采用经典的MVC模式,包括模型、控制、视图三部分」· Java 代码 · 共 52 行

JAVA
52
字号
/*
 * Created on Mar 25, 2005
 *
 * TODO add a coordinate to a JLabel as a button, to mark the location of this button
 */
package view;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;

import model.Location;

import javax.swing.JLabel;

/**
 * @author mqqqvpppm
 * 
 * TODO add a coordinate to a JLabel as a button, to mark the location of this
 * button
 */
public class MyButton extends JLabel {
	private Location location;

	public Location getMyLocation() {
		return location;
	}

	MyButton(Location aLocation) {
		super();
		this.location = aLocation;
	}

	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		if (image != null) {
			Graphics2D g2 = (Graphics2D) g;
			g2.drawImage(image, 0, 0, getWidth(), getHeight(), null);
		}
	}
	
	public void draw(Image image){
		this.image = image;
		repaint();
	}

	MyButton(int x, int y) {
		super();
		location = new Location(x, y);
	}
	private Image image;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?