나는 명백한 대답이 필요 없다. 이 문제를 어떻게 해결할 수 있을지에 대한 제안. 내 기본 클래스에서 수행 된 작업을 호출 할 수 있도록 MyButton에 동작 수신기를 추가하려고합니다.사용자 정의 Button 클래스 (Java)가있는 ActionListener
이것은 구성된 버튼입니다. 그들은 나타나고 actionListener를 제외한 모든 것이 작동합니다.
upButton = new MyButton(upStaticImageLocation, upRolledImageLocation, upClickedImageLocation);
upButton.addActionListener(this);
downButton = new MyButton(downStaticImageLocation, downRolledImageLocation, downClickedImageLocation);
downButton.addActionListener(this);
이것은 작업 수신기 메서드가있는 MyButton 클래스입니다.
downButton.addActionListener(this);
사용합니다 :
downButton.addActionListener(downButton);
당신이 어딘가에 외부 액션 청취자를 추가하려고하기 때문에
public class MyButton extends JComponent implements MouseListener {
private Dimension size = new Dimension(32, 32);
private Image staticImage;
private Image rolledImage;
private Image clickedImage;
private ArrayList<ActionListener> listeners = new ArrayList<ActionListener>();
public MyButton(String staticImage, String rolledImage, String clickedImage) {
super();
this.staticImage = new ImageIcon(staticImage).getImage();
this.rolledImage = new ImageIcon(rolledImage).getImage();
this.clickedImage = new ImageIcon(clickedImage).getImage();
enableInputMethods(true);
addMouseListener(this);
setSize(size.width, size.height);
setFocusable(true);
}
* 메인 클래스에서 수행 된 작업을 * 호출하는 것은 무엇을 의미합니까? –
@Forager 질문은 FX가 아닌 스윙과 관련이 있습니다 – MadProgrammer
아, 죄송합니다. 나는 그것을 알아야했다. – Forager