我现在用Slick2D在Java中创建自己的窗口系统,并且我想将按钮添加到我的窗口中!事情是,我不知道事件或这样的事情......我看到的每个地方都是JFrames的事件,但我想自己做。这里是我如何用我的窗口......Personlick在Slick2D中执行Java事件
Window win = new Window("Window title", 0, 0, 300, 100);
的,那么这是我在哪里,现在,在我的类从Window类继承:
@Override
public void initializeComponents() {
Button button1 = new Button("Button caption", 0, 0, 50, 20);
button1.setBackColor(Color.lightGray); // just an example of a set I'd use
button1.setOnClickEvent(button1_OnClick); // this is where I can't get it to work!
this.addComponent(button1);
}
public void button1_OnClick() {
System.out.println("button1 was pressed");
}
我用来做C#和我与代表做了类似的事情,它的工作,但现在Java没有任何代表我读过(我可能是错的)。我基本上想知道是否有一个很好的方法来实现这个,所以我可以这样使用它。
非常感谢!
您不能通过* *只是一个方法。您必须使用其中的方法创建包装器“回调”类。 – Supericy 2013-05-08 01:52:48