如何在java awt中使用具有相同标题的多个按钮 [英] How to use multiple buttons with same caption in java awt
本文介绍了如何在java awt中使用具有相同标题的多个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
i want to use same caption for multiple buttons.
what i exactly want is that i will create multiple buttons with same caption and add these all buttons to same event listener class.
how will i know from which button event has been triggered?
我尝试了什么:
i没有尝试任何东西。我很困惑,我应该从哪里开始。
What I have tried:
i haven't tried anything. I'm confused from where should i start.
推荐答案
当你创建按钮时,你应该在某个地方保留它的引用,这样你就可以测试它在处理程序中的哪个按钮。
When you create the button you should keep its reference somewhere so you can test which button it is in the handler.
Button FoodButton = new Button("DoIt")
Button DrinkButton = new Button("DoIt")
这篇关于如何在java awt中使用具有相同标题的多个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文