Here is a tutorial illustrating javax.swing.JButton class in Java used to create buttons.
getContentPane(): By default, we cannot apply background to a JFrame so we use this method to get the container of the JFrame and paint the background on it.
ActionListener(){}: An anonymous inner class is written for ease because only we've got two buttons.
javax.swing.*: Import everything from swing package, including JFrame, JButton
java.awt.event.*: Everything to handle the events. Here ActionListener and ActionEvent
java.awt.*: For Color and FlowLayout class here.
-----------------------------------
Output
-----------------------------------
getContentPane(): By default, we cannot apply background to a JFrame so we use this method to get the container of the JFrame and paint the background on it.
ActionListener(){}: An anonymous inner class is written for ease because only we've got two buttons.
javax.swing.*: Import everything from swing package, including JFrame, JButton
java.awt.event.*: Everything to handle the events. Here ActionListener and ActionEvent
java.awt.*: For Color and FlowLayout class here.
-----------------------------------
Output
-----------------------------------
No comments:
Post a Comment