JButton, JCheckBox und ähnliche Interaktoren ändern sich optisch nicht

Hier ist ein einfaches Grafikprogramm, das einige Sterne auf dem Bildschirm hinzufügt.

import acm.graphics.*;
import acm.program.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * This program creates a five-pointed star every time the
 * user clicks the mouse on the canvas.
 */

public class DrawStarMap1 extends GraphicsProgram {

    public void init() {
        /* Initializes the mouse listeners */
        addMouseListeners();

        /* The check box starts out in the "on" position */
        fillCheckBox = new JCheckBox("Filled");
        fillCheckBox.setSelected(true);
        add(fillCheckBox, SOUTH);

        /* Clears the screen with a button */
        add(new JButton("Clear"), SOUTH);
        addActionListeners();   
    }

    /* Called whenever the user clicks the mouse.*/
    public void mouseClicked(MouseEvent e) {
        GStar star = new GStar(STAR_SIZE);
        star.setFilled(fillCheckBox.isSelected());
        add (star, e.getX(), e.getY());
    }

    /* Removes all the graphical objects from the canvas */
    public void actionPerformed(ActionEvent e){
        if(e.getActionCommand().equals("Clear")) removeAll();
    }

    /* Private constants */
    private static final double STAR_SIZE = 20;

    private JCheckBox fillCheckBox;
}

Und die GStar-Klasse:

import acm.graphics.*;

/** Defines a new GObject class t:hat appears as a five-pointed star.
*/
public class GStar extends GPolygon {

     /** Creates a new GStar centered at the origin with the specified
     * horizontal width.
     * @param width The width of the star
     */
 public GStar(double width) {
    double dx = width / 2;
    double dy = dx * GMath.tanDegrees(18);
    double edge = width / 2 - dy * GMath.tanDegrees(36);
    addVertex(-dx, -dy);
    int angle = 0;
    for (int i = 0; i < 5; i++) {
        addPolarEdge(edge, angle);
        addPolarEdge(edge, angle + 72);
        angle -= 72;
    }
}
}

Das Programm funktioniert einwandfrei und erstellt mit einem GStar-Klassenkonstruktor einen Stern, wenn der Benutzer mit der Maus auf die Zeichenfläche klickt. Es gibt jedoch ein Problem: "Die JCheckBox und der JButton ändern sich nie visuell!". Wenn ich den "Clear" JButton drücke, wird der Canvas leer, aber der Button scheint nicht umzuschalten. Ebenso zeichnet das Programm sowohl gefüllte als auch leere Sterne, aber die "Gefüllte" JCheckBox bleibt immer ausgewählt, sie ändert sich nicht. Das Problem wird mit dem JSlider, den ich in anderen Programmen verwende, noch größer. Der Schieberegler bleibt immer in der Ausgangsposition, auch wenn er in gewisser Weise funktioniert: sein Wert ändert sich. Ich benutze Eclipse, Version 2011 und die neueste JRE - Bibliothek (v.7u6http://www.oracle.com/technetwork/java/javase/downloads/jre7-downloads-1637588.html). Ich habe im Internet nicht genügend Informationen gefunden. Worin besteht das Problem? Danke für deine Hilfe!! Das acm-Paket kann hier heruntergeladen werdenhttp://jtf.acm.org/acm.jar

Antworten auf die Frage(2)

Ihre Antwort auf die Frage