Concept explainers
a.
Explanation of Solution
Program:
File name: “JFrameDisableButton.java”
//Import necessary header files
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
//Define a class named JFrameDisableButton
public class JFrameDisableButton extends JFrame implements ActionListener
{
//Declare a variable and initialize the value
final int SIZE = 180;
//Retrieves the content pane layer
Container con = getContentPane();
//Create a JButton with the text "Press Me"
JButton button = new JButton("Press Me");
//Define a default constructor JFrameDisableButton
public JFrameDisableButton()
{
//Set the title and layout to the frame
super("Frame");
con.setLayout(new FlowLayout());
//Set the dimensions and visibility to the frame
setSize(SIZE, SIZE);
setVisible(true);
//Add the button to the frame
con...
b.
Explanation of Solution
Program:
File name: “JFrameDisableButton2.java”
//Import necessary header files
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
//Define a class named JFrameDisableButton2
public class JFrameDisableButton2 extends JFrame implements ActionListener
{
//Declare a variable and initialize the value
final int SIZE = 180;
//Retrieves the content pane layer
Container con = getContentPane();
//Create a JButton with the text "Press Me"
JButton button = new JButton("Press Me");
//Declare the variables and initialize the value
int count = 0;
final int MAX = 8;
//Create a label with the text "That's enough!"
JLabel label = new JLabel("That's enough!");
//Define a default constructor JFrameDisableButton2
public JFrameDisableButton2()
{
//Set the title and layout to the frame
super("Frame");
con.setLayout(new FlowLayout());
//Set the dimensions and visibility to the frame
setSize(SIZE, SIZE);
setVisible(true);
//Add the button to the frame
con.add(button);
//Add the label to the frame
con...
Want to see the full answer?
Check out a sample textbook solutionChapter 14 Solutions
EBK JAVA PROGRAMMING
- Write a JavaFX GUI application that allows the user to pick a set of pizza toppings using a set of check boxes. Assuming each topping cost 50 cents, and a plain pizza costs $10, display the cost of the pizza. Note that, once a topping is checked or unchecked, the cost of pizza should update automatically. Your application should closely resemble the following output format in the attached image, although the choice of toppings could be different:arrow_forwardWrite an application that displays a JFrame containing the opening sentence from A Christmas Carol. Add a button to the frame in the JBookQuote program. When the user clicks the button, display the title of the book that contains the quote in the available JLabel using the setText() method. import javax.swing.*; import java.awt.*; import java.awt.event.*; public class JBookQuote extends JFrame { FlowLayout flow = new FlowLayout(); JLabel msg1 = new JLabel("To begin with,"); JLabel msg2 = new JLabel("Marley was dead."); JButton button = new JButton("Click for source"); JLabel msg3 = new JLabel(); String title = "** A Christmas Carol **"; public JBookQuote() { // Write your code here } @Override public void actionPerformed(ActionEvent e) { // your code here } public static void main(String[] args) { JBookQuote aFrame = new JBookQuote(); aFrame.setSize(300, 150); aFrame.setVisible(true); }…arrow_forwardCreate a JavaFX application with at least six labels that contain facts about your favorite topic—for example, the French Revolution or astronomy. Every time the user clicks a Button, remove one of the Labels and add a different one.arrow_forward
- You are required to create above frame, Create a class HelloFrame and extend it from JFrame Inside HelloFrame declare 3 textfields for taking string input for name, email and number variables 1 textarea to write a message. Create a button “Submit” which should submit the form. Now create a public constructor for HelloFrame inside which You should call super("Hello Java"); //used to set title of the frame setSize(700, 400); //set length and width of the frame create a label which should display the method "Contact US Panel" similarly create labels for showing name, email, number. Add textfields and button to JFrame. Run the code and make sure the output should be as above frame.arrow_forwardCreate a JavaFX application that uses a TextField to get a message and encode or decode it using the classes described in Programming Project 5. Use buttons to control the kind of cipher used and to specify whether to encode or decode the message. Also use a TextField to get the number used in the constructor for the ciphers.arrow_forwardUsing JavaFX, create a user interface that has a top bar that includes a menu. The menu should have four items. When the user selects the first menu option, then the date and time should be printed in a text box. When the user selects the second menu option, then the text box contents should be written to a text file named "log.txt." When the user selects the third menu item then the frame background color changes to random color hue of the color green. The menu option should display the initial random hue each time selected for a single execution of the program. See https://www.w3schools.com/colors/colors_picker.aspLinks to an external site. When the user selects the fourth menu option then the program exits.arrow_forward
- Analyze the following JavaFX program and complete the missing code based on the comments. The Program should show window like this. public class EmployeeInterface extends Application{ @Override public void start(Stage stage) throws Exception { 1- // Create a boreder Pane object 2- // create HBox object 3- // create the two command button objectsarrow_forwardWrite the application JFrameDisableButton that instantiates a JFrame that contains a JButton. Modify the JFrameDisableButton program so that the JButton is not disabled until the user has clicked at least eight times. At that point, display a JLabel that indicates “That’s enough!”. import java.awt.*; import javax.swing.*; import java.awt.event.*; public class JFrameDisableButton extends JFrame implements ActionListener { final int SIZE = 180; Container con = getContentPane(); JButton button = new JButton("Press Me"); int count = 0; final int MAX = 8; JLabel label = new JLabel("That's enough!"); public JFrameDisableButton() { // Write your code here } @Override public void actionPerformed(ActionEvent e) { // Write your code here } public static void main(String[] args) { JFrameDisableButton frame = new JFrameDisableButton(); } }arrow_forwardAnalyze the following JavaFX program and complete the missing code based on the comments. The Program should show window like this. public class EmployeeInterface extends Application{ @Override public void start(Stage stage) throws Exception { 7- // create the label and TextField for the Major and add them in the first row in the grid pane 8- // Put the commands in the buttom of the BorderPane 9- // Put the GridPane which contain student information in the center of BorderPanearrow_forward
- Write Java (Swing) statements to create the following: 1) A statement that creates a JPanel object named accountPanel. 2) A statement that assigns the BorderLayout manager to the JPanel object named accountPanel. 3) A statement that creates a JButton object named save with an appropriate label. 4) A statement that creates an action listener for the JButton object named save.arrow_forwardCreate a program that has a simple graphical interface using "Kivy", an environment cross-platform by Python. When this program starts up, it will load a file (“users.csv”) that for each line will have a user and the SHA1 of the password, with the following format:"user": "passwordinSHA1"The graphical interface will have only two text fields, "username" and "password" (in plain text, but hidden when typing) and a "check" button. If the user exists and the password is correct, it will display an "OK" message. Otherwise, an "ERROR" message.arrow_forwardI need help moding this Java code to follow the picture. import java.awt.event.*; import javax.swing.*; class Main { public static void main(String args[]) { JFrame myframe= new JFrame("Hello App"); JLabel lblMessage=new JLabel(); lblMessage.setBounds(100,50, 250,12); myframe.add(lblMessage); JTextField txtBox1; txtBox1=new JTextField("Enter your first name"); txtBox1.setBounds(100,88, 150,30); myframe.add(txtBox1); JButton btnSubmit=new JButton("Submit"); btnSubmit.setBounds(100,170, 88,30); myframe.add(btnSubmit); btnSubmit.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ String msg="Hello "+txtBox1.getText(); lblMessage.setText(msg); } }); JButton btnReset=new JButton("Reset"); btnReset.setBounds(244,170, 88,30); myframe.add(btnReset); btnReset.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ lblMessage.setText(""); txtBox1.setText("Enter your first name"); } });…arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage