Explore BrainMass
Share

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 17, 2018, 11:56 am ad1c9bdddf
https://brainmass.com/computer-science/java/creating-gui-applications-jframe-558735

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.

$2.19
Similar Posting

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.

JFrame.setDefaultLookAndFeelDecorated(true);

//Create and set up the window.

JFrame frame = new JFrame("HelloWorldSwing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Add the ubiquitous "Hello World" label.

JLabel label = new JLabel("Hello World");
frame.getContentPane().add(label);

//Display the window.
frame.pack();
frame.setVisible(true);
}

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() {
createAndShowGUI();
}
});
}
}

View Full Posting Details