Purchase Solution

Writing a Java GUI displaying time when button clicked

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.

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);
}
}

You need to supply the following class in your solution:
ClickListener

Do not modify the following:

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

This solution helps write a Java GUI that displays time when a button was clicked.

Purchase this Solution


Free BrainMass Quizzes
Basic Networking Questions

This quiz consists of some basic networking questions.

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 Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

C# variables and classes

This quiz contains questions about C# classes and variables.