📄 roundbutton.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 + -