안녕하세요 저는 게임을 프로그래밍 중이며 둥근 버튼이 멋지다고 생각했지만 궁금한 점은 버튼의 크기를 더 큰 것으로 변경하는 방법입니다. 여기변경 크기가 반올림 된
public JavaApplication3(String label) {
super(label);
Dimension size = getPreferredSize();
size.width = size.height = Math.max(size.width,size.height);
setPreferredSize(size);
setContentAreaFilled(false);
}
protected void paintComponent(Graphics g) {
if (getModel().isArmed()) {
g.setColor(Color.RED);
} else {
g.setColor(Color.yellow);
}
g.fillOval(0, 0, getSize().width-1,getSize().height-1);
super.paintComponent(g);
}
protected void paintBorder(Graphics g) {
g.setColor(getForeground());
g.drawOval(0, 0, getSize().width-1, getSize().height-1);
}
Shape shape;
public boolean contains(int x, int y) {
if (shape == null ||
!shape.getBounds().equals(getBounds())) {
shape = new Ellipse2D.Float(0, 0, getWidth(), getHeight());
}
return shape.contains(x, y);
}
희망의 사람이 당신이 그것을 클릭 할 때마다 사용하여 버튼의 크기를 변경 :
하십시오 여기
몇 가지 작업 코드? – DreadHeadedDeveloper