Explore BrainMass

Creating GUI Applications with JFrame

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

Create a GUI application with JFrame that contains five labels describing reasons that a customer might not buy a specific product (e.g. "too expensive"). Place a JButton on the JFrame, and code its functionality so that every time the user clicks on the button one of the reasons is removed from a label.

© BrainMass Inc. brainmass.com October 25, 2018, 8:57 am ad1c9bdddf

Solution Preview

Following the description given in the question, attached solution (558735-NotBuyReasons.java) displays 5 labels followed by a button. On clicking ...

Solution Summary

Java version "1.7.0_21" was used during development and testing of the attached program.

See Also This Related BrainMass Solution

Java Programming

I need the size of the frame to be set a little bit larger than its content, which is a label. Also, the location could be set so that it could be appeared not at the upper left corner of the screen. And we can set the foreground and background color of the label.

import javax.swing.*;
import java.util.*;

public class helloWorldSwing {

private static void createAndShowGUI() {

//Make sure we have nice window decorations.


//Create and set up the window.

JFrame frame = new JFrame("HelloWorldSwing");

//Add the ubiquitous "Hello World" label.

JLabel label = new JLabel("Hello World");

//Display the window.

public static void main(String[] args) {

//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {

View Full Posting Details