나는 지금 ......비활성화하는 JButton 첫번째 후 클릭
public class Beginner extends JPanel {
private JButton quest;
public Beginner() {
int n = 10; //no of JButtons
int radius = 200;
Point center = new Point (250, 250);
double angle = Math.toRadians(360/n);
List <Point> points = new ArrayList<Point>();
points.add(center);
for (int i = 0; i < n; i++) {
double theta = i * angle;
int dx = (int) (radius * Math.sin(theta));
int dy = (int) (radius * Math.cos(theta));
Point p = new Point (center.x + dx , center.y + dy);
points.add(p);
}
draw (points);
}
public void draw (List<Point> points) {
JPanel panels = new JPanel();
SpringLayout spring = new SpringLayout();
int count = 1;
for (Point point: points) {
quest = new JButton("Question " + count); //JButton is drawn about 10 times in a circle arragement
quest.setForeground(Color.BLUE);
Font fonte = new Font("Script MT Bold", Font.PLAIN, 20);
quest.setFont(fonte);
add (quest);
count++;
;
spring.putConstraint(SpringLayout.WEST, quest, point.x, SpringLayout.WEST, panels);
spring.putConstraint(SpringLayout.NORTH, quest, point.y, SpringLayout.NORTH, panels);
setLayout(spring);
panels.setOpaque(false);
panels.setVisible(true);
panels.setLocation(10, 10);
add(panels);
}
}
}
를이 코드를 사용하여 원에서 약 11 JButton의를 만들 수 있었다, 나는 각각의 JButton에 대한 ActionListener를 작성해야하고, 그것은이다 그런 각 버튼은 클릭 한 번만 활성화해야합니다. 그 후에 색상은 초록색으로 바뀝니다. 그 방법에 대한 아이디어가 없습니다! 당신의 도움을 주셔서 감사합니다! 버튼의 액션 청취자에
는
[클릭 befor actionPerformed에 단추를 해제 할 수 있습니다] 가능한 중복 복제] (http://stackoverflow.com/questions/17807846/disable-button-on-click-befor-actionperformed-is-competed-java) –