I have a little problem, I was able to create about 10 JButtons in a circle using this code below, I set an actionListener on each of them, and I want to find a piece of code I could use to detect if all the buttons have been clicked, then some action is performed... below is my piece of code!
int n = 10;
List <Point> points = new ArrayList<Point> ();
public Beginner() {
int radius = 200;
Point center = new Point (250, 250);
double angle = Math.toRadians(360 / n);
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);
quest.setForeground(Color.BLACK);
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(5,5);
add(panels);
quest.addActionListener(new java.awt.event.ActionListener(){
@Override
public void actionPerformed (ActionEvent p) {
if (point.equals(points.get(0)) {
//some action
}
else if (point.equals(points.get(1)) {
//some action
}
here is the problem.... I want to use a code to detect when all actionListeners have been carried out!... Thanks for the help!
}
}); }
Aucun commentaire:
Enregistrer un commentaire