⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 roundbutton.java

📁 connectN 网络游戏。内含server and client端源程序
💻 JAVA
字号:
package client;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Shape;
import java.awt.geom.Ellipse2D;

import javax.swing.*;

class RoundButton extends JButton {
	private static final long serialVersionUID = 1L;

	//     draw backgrond and label
	public RoundButton() {
		super();
		Dimension size = getPreferredSize();
		size.width = Math.max(size.width, size.height);
		size.height = size.width / 3;
		setPreferredSize(size);
		setContentAreaFilled(false);
	}

	protected void paintComponent(Graphics g) {
		g.setColor(this.getBackground());
		g.fillOval(2, 2, getSize().width - 4, getSize().height - 4);
	}

	//    draw the boundary of button
	protected void paintBorder(Graphics g) {
		g.setPaintMode();
	}
	
	Shape shape;
	public boolean contains(int x, int y) {
		//     change the size of button if possible
		if (shape == null || !shape.getBounds().equals(getBounds())) {
			shape = new Ellipse2D.Float(2, 2, getWidth() - 4, getHeight() - 4);
		}
		return shape.contains(x, y);
	}
}

⌨️ 快捷键说明

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