Create a code to provide the clicklistener class


Discuss the below:

Q: Enhance the ButtonViewer program so that it prints the time at which the button was clicked.

Provide the ClickListener class in your solution.

Use the following class as your main class:

import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;

/**
This program demonstrates how to install an action listener.
*/
public class ButtonViewer
{
private static final int FRAME_WIDTH = 100;
private static final int FRAME_HEIGHT = 60;

public static void main(String[] args)
{
JFrame frame = new JFrame();
JButton button = new JButton("Click me!");
frame.add(button);

ActionListener listener = new ClickListener();
button.addActionListener(listener);

frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Create a code to provide the clicklistener class
Reference No:- TGS01934448

Now Priced at $20 (50% Discount)

Recommended (96%)

Rated (4.8/5)