Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
Posted
Updated 28-Dec-16 20:11pm
v2
Comments
[no name] 28-Dec-16 15:42pm    
"What should I do?", you should get yourself a decent book on programming and work through the exercises. Or take a class at your local college or university. Trying to learn programming one question at a time is not going to be fruitful.
OnLearn 28-Dec-16 15:47pm    
I go to school and learn programming but I am in the first class and we learn so slow that I want to do something on my own. And now I want to program a little game and because of that I asked this question.
[no name] 28-Dec-16 15:54pm    
"teach me programming" is not a question for this forum. If the learning is slow, that's for a reason. They want you to learn the fundamentals first before you go off like you are, try something that you are not prepared for and get frustrated because you don't have the fundamental knowledge yet and quit. If you want to do this then go ahead and do it. There is nothing stopping you from proceeding except yourself. But you still are not going to learn programming one vague question at a time. Learning how to use google would be a good start as well as reading the FAQ for how to ask a question.

1 solution

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.
 
Share this answer
 
Comments
OnLearn 29-Dec-16 4:28am    
Thank you, it is working!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900