Purchase Solution

Java ButtonViewer and ClickListener classes

Not what you're looking for?

Ask Custom Question

Enhance the ButtonViewer program so that it prints the time at which the button was clicked.
Please 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);
}
}

Purchase this Solution

Solution Summary

As nothing is specified about whether the clicked-on time should be printed via a dialog box or on the console, this solution prints the clicked-on time at console.

Solution Preview

Please rename the attached 470532-ButtonViewer.java as ButtonViewer.java before compiling and executing the program.

As nothing is specified about whether the clicked-on time should be printed via a dialog box or on the console, this solution prints the clicked-on time at console.

Sample output on console would look like following.

$ java ButtonViewer
Clicked on Fri Apr 06 16:51:45 IST 2012
Clicked on ...

Purchase this Solution


Free BrainMass Quizzes
Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

Basic Networking Questions

This quiz consists of some basic networking questions.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Javscript Basics

Quiz on basics of javascript programming language.