Question

In: Computer Science

Create a for which will have the following controls. 1. Label for First Name and TextBox...

Create a for which will have the following controls.

1. Label for First Name and TextBox for the First Name

2. Label for Last Name and TextBox for the Last Name

3. Label for bank account balance and TextBox for the bank account balance (assume $1000 in the bank account)

4. Create a button Name. The user will click the button and the first name and last name will be displayed on the label. You will create a label called lblFirstLastName to display the First and last Name.

5. Create a button bankbalance. The user will click the button and the balance will be displayed on the label. You will create a label called lblBankbalance to display the bank balance.

6. Create a Cancel button to cancel the form

------------------------------------------------------------------------------------------------

package swing;
import javax.swing.*;
public class SwingInheritance extends JFrame
{
   private static final long serialVersionUID = 1L;
   SwingInheritance()
   {
       JTextField userName = new JTextField();
       //userName.setBounds(x, y, width, height);
       userName.setBounds(80,100,100, 40);
       userName.setText("Hello");
       JLabel lblText = new JLabel();
       lblText.setBounds(80,150,300, 40);
       lblText.setText("You Entered: " + userName.getText());
       JButton button=new JButton("click");
       //create button
       button.setBounds(80,200,100, 40);
       JButton close = new JButton("Close");
       close.setBounds(80,250,100, 40);
       close.addActionListener(e ->
       {
           dispose();
       });
       //add to JFrame
       add(button);
       add(close);
       add(userName);
       add(lblText);
       //set frame properties
       setSize(400,500);
       setLayout(null);
       setVisible(true);
       }
   public static void main(String[] args)
   {
       new SwingInheritance();
   }
}

Solutions

Expert Solution

/*************** below is the code ***************/

import javax.swing.*;

public class SwingInheritance extends JFrame {
    private static final long serialVersionUID = 1L;

    SwingInheritance() {

        JLabel firstNameLabel = new JLabel("First Name: ");
        JLabel lastNameLabel = new JLabel("Last Name: ");
        JLabel bankBalanceLabel = new JLabel("Account Balance: ");
        firstNameLabel.setBounds(15, 20, 150, 20);
        lastNameLabel.setBounds(15, 45, 150, 20);
        bankBalanceLabel.setBounds(15, 70, 150, 20);

        JTextField lastNameField = new JTextField();
        JTextField firstNameField = new JTextField();
        JTextField bankBalanceField = new JTextField();
        firstNameField.setBounds(175, 20, 200, 20);
        lastNameField.setBounds(175, 45, 200, 20);
        bankBalanceField.setBounds(175, 70, 200, 20);
        

        final String DEFAULT_TEXT = "Click above";

        JLabel lblFirstLastName = new JLabel(DEFAULT_TEXT, JLabel.CENTER);
        JLabel lblBankBalance = new JLabel(DEFAULT_TEXT, JLabel.CENTER);
        lblFirstLastName.setBounds(10, 185, 180, 20);
        lblBankBalance.setBounds(210, 185, 180, 20);

        JButton nameButton = new JButton("Name");
        JButton bankBalanceButton = new JButton("Balance");
        nameButton.setBounds(50, 150, 100, 30);
        bankBalanceButton.setBounds(250, 150, 100, 30);

        JButton close = new JButton("Close");
        
        close.setBounds(140, 280, 100, 40);
        close.addActionListener(e -> {
            dispose();
        });

        nameButton.addActionListener(e -> {
            
            String fName = firstNameField.getText();
            String lName = lastNameField.getText();
            
            if (!fName.equals("") || !lName.equals(""))
                lblFirstLastName.setText(fName + " " + lName);
            else
                lblFirstLastName.setText(DEFAULT_TEXT);
        });

        bankBalanceButton.addActionListener(e -> {
            
            String balance = bankBalanceField.getText();
            
            if (!balance.equals(""))
                lblBankBalance.setText(balance);
            else
                lblFirstLastName.setText(DEFAULT_TEXT);
        });
        

        //add to JFrame
        add(close);
        add(firstNameLabel);
        add(lastNameLabel);
        add(bankBalanceLabel);
        add(firstNameField);
        add(lastNameField);
        add(bankBalanceField);

        add(lblFirstLastName);
        add(lblBankBalance);
        add(nameButton);
        add(bankBalanceButton);

        
        //set frame properties
        setSize(400, 400);
        setLayout(null);
        setVisible(true);
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }

    public static void main(String[] args) {
        new SwingInheritance();
    }
}

/************** Output ***************/

/************ If you have any questions, you may ask in comments **************/

/********************** Thanks for reading *************************/


Related Solutions

ISYS 350, Assignment 2, Part 1: Create a C# Form with a textbox and a button....
ISYS 350, Assignment 2, Part 1: Create a C# Form with a textbox and a button. The box is for a user to enter a number of seconds. And when the user clicks the button, the program displays the equivalent number of hours, minutes and seconds using a MessageBox. Show method. If the seconds entered is less than 60, your program should only display the seconds; if the seconds is a least 60 and less than 3600, your program should...
c# language Create a class “Person” which included first name, last name, age, gender, salary, and...
c# language Create a class “Person” which included first name, last name, age, gender, salary, and havekids (Boolean) variables. You have to create constructors and prosperities for the class. Create a “MatchingDemo” class. In the main function, the program reads the number of people in the database from the “PersonInfo.txt” file and creates a dynamic array of the object. It also reads the people's information from “PersonInfo.txt” file and save them into the array. Give the user the ability to...
Create the following SQL queries using the lyrics database below 1. List the first name, last...
Create the following SQL queries using the lyrics database below 1. List the first name, last name, and region of members who do not have an email. 2. List the first name, last name, and region of members who do not have an email and they either have a homephone ending with a 2 or a 3. 3. List the number of track titles that begin with the letter 's' and the average length of these tracks in seconds 4....
Create a table ‘StudentInfo’ with following fields: ID First Name Last Name SSN Date of Birth...
Create a table ‘StudentInfo’ with following fields: ID First Name Last Name SSN Date of Birth Create a table ‘ClassInfo’ table: ID Class Name Class Description Create a table ‘RegisteredClasses’ table: StudentID ClassID The RegisteredClasses table should have a foreign key relationship to StudentInfo and ClassInfo tables for the respective IDs. Also the IDs in StudentInfo and ClassInfo need to be primary keys. When you submit the file your email should also contain the following SQL Queries: Query to show...
Create a program that keeps track of the following information input by the user: First Name,...
Create a program that keeps track of the following information input by the user: First Name, Last Name, Phone Number, Age Now - let's store this in a multidimensional array that will hold 10 of these contacts. So our multidimensional array will need to be 10 rows and 4 columns. You should be able to add, display and remove contacts in the array. In Java
Part 1: Create a character array and save your first and last name in it
PROGRAMMING IN C:Part 1:Create a character array and save your first and last name in itNote: You can assign the name directly or you can use the scanf function.Display your name on the screen.Display the address (memory location) in hexadecimal notation of the array. (hint: use %p)Use a for loop to display each letter of your name on a separate line.Part 2:Create a one dimensional array and initialize it with 10 integers of your choice.Create a function and pass the...
JAVA PROGRAMMING Part 1 Create a class Student, with attributes id, first name, last name. (All...
JAVA PROGRAMMING Part 1 Create a class Student, with attributes id, first name, last name. (All the attributes must be String) Create a constructor that accepts first name and last name to create a student object. Create appropriate getters and setters Create another class StudentOperationClient, that contains a main program. This is the place where the student objects are created and other activities are performed. In the main program, create student objects, with the following first and last names. Chris...
1.Which of the following is not a goal of the internal controls implemented by owners and...
1.Which of the following is not a goal of the internal controls implemented by owners and managers? Multiple Choice to safeguard assets to ensure reliability of accounting data to promote compliance with management policies and applicable laws to reduce expenses through the use of efficient processes 2.The three major legal forms of business entity are the sole proprietorship, the partnership, and the __________. Multiple Choice merchandiser corporation service business small business 3.The financial statements submitted to the SEC by a...
create a file in java where you can store the first name, last name and the...
create a file in java where you can store the first name, last name and the grade of the student. this will repeats until the answer of the question "are you done?" is.equals (y). then write another program that you can read from this file the student's information . I have dome most of it but my program stores only 1 student's information. WRITE IN FILE public static void main(String[] args) { System.out.println("Enter the file name"); Scanner keyboard=new Scanner(System.in); String...
JAVA Program Create a class called SoccerPlayer Create 4 private attributes: First Name, Last Name, Games,...
JAVA Program Create a class called SoccerPlayer Create 4 private attributes: First Name, Last Name, Games, and Goals Have two constructors Constructor 1 – default constructor; all values to "NONE" or zero Constructor 2 – accepts input of first name, last name, games and goals. Create get and set methods for each of the four attributes Create a method the returns a double that calculates the average goals per game This method checks for zero games played: If there are...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT