Explanation of Solution
Modified program:
The below highlighted lines are the modified statements in the Listing 6.22.
//import necessary header files
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
//define the class "ButtonIconDemo"
public class ButtonIconDemo extends JApplet implements ActionListener
{
//define the method "init()"
public void init( )
{
//create an object for "Container" class
Container contentPane = getContentPane( );
//set the background color
contentPane.setBackground(Color.WHITE);
//set the layout
contentPane.setLayout(new FlowLayout( ));
//create a button and give name to the button
JButton sunnyButton = new JButton("Sunny");
//Create object for "ImageIcon"
ImageIcon smileyFaceIcon = new ImageIcon("smiley.gif");
//set the icon
sunnyButton.setIcon(smileyFaceIcon);
//add the button to the window
contentPane.add(sunnyButton);
//add the action to the button
sunnyButton.addActionListener(this);
//create a button and give name to the button
JButton cloudyButton = new JButton("Cloudy");
//Create object for "ImageIcon"
ImageIcon nastyFaceIcon = new ImageIcon("nasty.gif");
//set the icon
cloudyButton...
Want to see the full answer?
Check out a sample textbook solutionChapter 6 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education