Java programming course: 14.5 JButton


JButton

The JButton class displays a clickable button component with the text you specify:  

JButton button = new JButton("Please click me");
panel.add(button);
 

The above code result in:.

JButton

Note that although you can click on the button and it gives the visual feedback of being pressed and released, nothing actually happens until you attach a listener object to the button, so it knows what action to perform. You saw how to do this in Section 13.



Print
×
Stay Informed

When you subscribe, we will send you an e-mail whenever there are new updates on the site.

Related Posts

 

Comments

No comments made yet. Be the first to submit a comment
Thursday, 11 December 2025

Captcha Image