如何创建生成JButton的方法?

发布于 2025-01-30 05:31:53 字数 1490 浏览 4 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦幻的味道 2025-02-06 05:31:53

您当然可以编写一种为您创建jbutton的方法:

public JButton createButton(String label, ActionListener listener, int x, int y) {
  JButton b = new JButton(label);
  name.addActionListener(listener);
  name.setBounds(x, y, 150, 50);
  return b;
}

然后使用这样的方法:

button19 = createButton("Toiletsager", this, 100, 100);

您当然还可以为每个按钮指定一个ActionListener

button20 = createButton("Toiletsager", e->System.out.println(e) , 100, 100);

You can of course write a method that creates JButton for you:

public JButton createButton(String label, ActionListener listener, int x, int y) {
  JButton b = new JButton(label);
  name.addActionListener(listener);
  name.setBounds(x, y, 150, 50);
  return b;
}

and then use the method like this:

button19 = createButton("Toiletsager", this, 100, 100);

You can of course also specify one ActionListener for each button:

button20 = createButton("Toiletsager", e->System.out.println(e) , 100, 100);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文