当大约100个buttens应该具有相同的代码时,我应该如何编程jframe [英] How should I program a jframe when approximately 100 buttens should have the same code
本文介绍了当大约100个buttens应该具有相同的代码时,我应该如何编程jframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想编制一个小游戏。在这个游戏中我使用大约100个按钮。如果单击这些按钮,则始终相同。我确信有一个更好的选择,然后为每个按钮编写一个自己的事件。我该怎么办?
我的尝试:
我不能尝试任何东西,因为我没有任何经验,也不知道怎么做。
Hi,
I want to programm a little game. In this game I use approximately 100 buttons. If you click on these buttons always happens the same. I am sure that there is a better option then programming an own event for each button. What shoud I do?
What I have tried:
I can't try anything because I don't have any experience and no idea how to do it.
推荐答案
阅读:
< a href =https://docs.oracle.com/javase/tutorial/uiswing/components/button.html>如何使用按钮,复选框和单选按钮(Java™教程>使用JFC创建GUI / Swing>使用Swing组件) [ ^ ]
基本上你需要做的就是:
1.选择你的布局经理>
2.创建按钮
3.设置按钮属性
4.添加动作监听器
5.并提供每个按钮需要的操作。
Read this:
How to Use Buttons, Check Boxes, and Radio Buttons (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)[^]
Basically all you need to do is to:
1. select your layout manager
2. create your button
3. set your buttons properties
4. add action listener
5. and provide the action you need in each button.
这篇关于当大约100个buttens应该具有相同的代码时,我应该如何编程jframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文