Explore BrainMass
Share

Writing a Java GUI displaying time when button clicked

This content was STOLEN from BrainMass.com - View the original, and get the already-completed solution here!

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

© BrainMass Inc. brainmass.com October 17, 2018, 12:22 pm ad1c9bdddf
https://brainmass.com/computer-science/graphics/writing-java-gui-displaying-time-button-clicked-575038

Solution Summary

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

$2.19
Similar Posting

Java Inventory Button issue

1. Modify the Program to include an Add button, a Delete button, and a Modify (buttons have been added!!) button on the GUI. These buttons should allow the user to perform the corresponding actions on the item name, the number of units in stock, and the price of each unit. An item added to the inventory should have an item number one more than the previous last item.
2. Add a Save button to the GUI that saves the inventory to a C:datainventory.dat file. (button added already)
3. Use exception handling to create the directory and file if necessary.
4. Add a search button to the GUI that allows the user to search for an item in the inventory by the product name. If the product is not found, the GUI should display an appropriate message. If the product is found, the GUI should display that product's information in the GUI. (Again button Added)

View Full Posting Details