1
刪除對象,我挖的文件,看看是否有一個remove方法,我只是得到該鏈接,每當我谷歌 http://www.coderanch.com/t/580998/JavaFX/java/remove-node從現場的JavaFX
有一個簡單的刪除選項 如:.getChildren()刪除(物體)
它似乎不適合我!
刪除對象,我挖的文件,看看是否有一個remove方法,我只是得到該鏈接,每當我谷歌 http://www.coderanch.com/t/580998/JavaFX/java/remove-node從現場的JavaFX
有一個簡單的刪除選項 如:.getChildren()刪除(物體)
它似乎不適合我!
您提供的代碼適用於我。
加圓圈ALT +點擊,並通過簡單地點擊他們刪除它們。
我用ALT鍵爲加入圈子的原因是因爲在下面的代碼,無論是現場和圓處理鼠標點擊。因此,代碼必須知道事件來自哪裏。當然,這只是一個例子。
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
public class ChangeListenerSample extends Application {
public static void main(final String[] args) {
launch(args);
}
@Override
public void start(final Stage primaryStage) throws Exception {
final Group root = new Group();
primaryStage.setResizable(false);
final Scene scene = new Scene(root, 400,80);
primaryStage.setScene(scene);
scene.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
@Override public void handle(final MouseEvent event)
{
if (!event.isAltDown())
return;
final Circle circle = new Circle(event.getSceneX(), event.getSceneY(),30);
circle.setFill(Color.YELLOW);
root.getChildren().add(circle);
circle.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
@Override public void handle(final MouseEvent arg0)
{
root.getChildren().remove(circle);
}
});
}
});
primaryStage.show();
}
}
能否請您提供更多信息?例如源代碼 – GGrec
@GGrec,以下是代碼: http://stackoverflow.com/questions/22677110/putting-an-object-on-a-stage-when-mouse-clicked/22678406#22678406 – Pgram