delphi动态获取点击的MenuItem

procedure TForm1.OnClick(Sender: TObject);
begin
if Sender is TButton then
begin
if TButton(Sender).Name = ‘button1’ then
.. .
else if TButton(Sender).Name = ‘button2’ then
.. .
end;
end;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现在Java中点击MenuItem打开另一个类的窗口,可以按照以下步骤进行: 1. 创建一个MenuItem对象,并添加到Menu中: ``` MenuItem menuItem = new MenuItem("Open Another Window"); Menu menu = new Menu("File"); menu.getItems().add(menuItem); ``` 2. 给MenuItem添加事件监听器,当MenuItem点击时,创建另一个类的实例并显示: ``` menuItem.setOnAction(event -> { AnotherWindow anotherWindow = new AnotherWindow(); anotherWindow.show(); }); ``` 3. 创建另一个类,继承自Stage,并实现其构造方法和需要的界面元素: ``` import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class AnotherWindow extends Stage { public AnotherWindow() { VBox root = new VBox(); root.getChildren().add(new Label("This is another window!")); Scene scene = new Scene(root, 400, 300); setScene(scene); } } ``` 完整代码示例: ``` import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Menu; import javafx.scene.control.MenuBar; import javafx.scene.control.MenuItem; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class Main extends Application { @Override public void start(Stage primaryStage) throws Exception{ MenuItem menuItem = new MenuItem("Open Another Window"); menuItem.setOnAction(event -> { AnotherWindow anotherWindow = new AnotherWindow(); anotherWindow.show(); }); Menu menu = new Menu("File"); menu.getItems().add(menuItem); MenuBar menuBar = new MenuBar(); menuBar.getMenus().add(menu); VBox root = new VBox(); root.getChildren().add(menuBar); Scene scene = new Scene(root, 800, 600); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } } class AnotherWindow extends Stage { public AnotherWindow() { VBox root = new VBox(); root.getChildren().add(new Label("This is another window!")); Scene scene = new Scene(root, 400, 300); setScene(scene); } } ``` 运行程序,点击菜单栏中的“File” -> “Open Another Window”即可打开另一个类的窗口。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值