Question

In: Computer Science

I need to add variables such as name, address and phone into a Jpanel in the...

I need to add variables such as name, address and phone into a Jpanel in the constructor called AddressBook. I then need to add that panel into a Jframe and call it in the main method how would i do that in java.

Solutions

Expert Solution


import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Sample {
   JFrame frame;
   Sample(){
       //creating jpanel
               JPanel panel = new JPanel();
               frame = new JFrame("JFrame Example");
               panel.setLayout(null);
               //creating labels
               final JLabel label3 = new JLabel("Name: ");
               label3.setBounds(200, 15, 500, 30);
               JLabel label1 = new JLabel("Address: ");
               label1.setBounds(200, 50, 300, 30);

               final JTextField adult = new JTextField(10);
               adult.setBounds(400, 50, 100, 30);
               //creating labels
               JLabel label2 = new JLabel("Phone : ");
               label2.setBounds(200, 100, 250, 30);
               // password field
               final JTextField children = new JTextField(10);
               children.setBounds(400, 100, 100, 30);
               //adding to Jpanel
               panel.add(label1);
               panel.add(label2);
               panel.add(label3);
               panel.add(adult);
               panel.add(children);
               //adding JPanel to frame
               frame.add(panel);

               frame.setSize(600, 300);
               frame.setLocationRelativeTo(null);
               frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
               frame.setVisible(true);
   }
   public static void main(String s[]) {
           new Sample();
   }
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me


Related Solutions

Create a class called Student. Include the following instance variables: name, address, phone, gpa Create all...
Create a class called Student. Include the following instance variables: name, address, phone, gpa Create all of the methods required for a standard user defined class: constructors, accessors, mutators, toString, equals Create the client for testing the Student class Create another class called CourseSection Include instance variables for: course name, days and times course meets (String), description of course, student a, student b, student c (all of type Student) Create all of the methods required for a standard user defined...
Given the following 7 relations: MIScompany (name, address, phone, email, FedTaxId, StaTaxId) branch (branchId, name, address,...
Given the following 7 relations: MIScompany (name, address, phone, email, FedTaxId, StaTaxId) branch (branchId, name, address, phone, email, FedTaxId, StaTaxId) employee (empId, driverId, ssno, name, branchId) customer (custId, name, address, driverId, ssno, FedTaxId, StaTaxId) equipment (equipId, name, type, upc, purchaseDate, year, manufacturId, cost, rentFee, branchId ) manufacturer (manufacturId, name, FedTaxId, StaTaxId, phone, email) rental (rentalId, equipId, custId, rentDate&time, returnDate&time, empId) Use relational algebra to retrieve every customer that has not rented any equipment in September 2020. The report should contain...
Given the following 7 relations: MIScompany (name, address, phone, email, FedTaxId, StaTaxId) branch (branchId, name, address,...
Given the following 7 relations: MIScompany (name, address, phone, email, FedTaxId, StaTaxId) branch (branchId, name, address, phone, email, FedTaxId, StaTaxId) employee (empId, driverId, ssno, name, branchId) customer (custId, name, address, driverId, ssno, FedTaxId, StaTaxId) equipment (equipId, name, type, upc, purchaseDate, year, manufacturId, cost, rentFee, branchId ) manufacturer (manufacturId, name, FedTaxId, StaTaxId, phone, email) rental (rentalId, equipId, custId, rentDate&time, returnDate&time, empId) 1) Use relational algebra to list every manufacturer that only makes electric cleaning tool (type of equipment). The report should...
JAVA/Netbeans •Design a class named Person with fields for holding a person’s name, address and phone...
JAVA/Netbeans •Design a class named Person with fields for holding a person’s name, address and phone number (all Strings) –Write a constructor that takes all the required information. –Write a constructor that only takes the name of the person and uses this to call the first constructor you wrote. –Implement the accessor and mutator methods. Make them final so subclasses cannot override them –Implement the toString() method •Design a class named Customer, which extends the Person class. It should have...
Problem: Read the following tables and answer the following questions: Customers Customer ID Name Address Phone...
Problem: Read the following tables and answer the following questions: Customers Customer ID Name Address Phone Email 9087 John Doe 204 University Ave. 987-098-9087 [email protected] 2098 Bill Lawrence 123 Jones St 717-387-3387 Business 2398 Laura Smith 0900 West Blvd. 901-234-4567 Information Transactions Customer ID Account Number Date of Last Transaction 9087 375 01/31/98 2098 123 03/09/97 2398 375 09/21/97 2098 375 12/31/97 2398 123 02/01/98 Accounts Account Number Balance Account Type 375 234.45 Checking 123 056.90 Savings 1. Who owns...
I need to add this checkpoint to an existing code that i have in python Checkpoint...
I need to add this checkpoint to an existing code that i have in python Checkpoint 1: Once you have created and tested the Bank Account Class create subclasses to the BankAccount class. There should be two subclasses, CheckingAccount and SavingsAccount. You should add interest_rate to the parent BankAccount class. To the CheckingAccount add variables called per_check_fee default to false and allow_overdraft default to True. To SavingsAccount add the variable transactions_per_month, default it to 5. Create instances of CheckingAccount and...
I need a presentation on THE EFFECT OF MOBILE PHONE USAGE ON STUDENT GRADE.
I need a presentation on THE EFFECT OF MOBILE PHONE USAGE ON STUDENT GRADE.
Make a java program of Mickey I have the starter program but I need to add...
Make a java program of Mickey I have the starter program but I need to add eyes and a smile to it. import java.awt.Canvas; import java.awt.Color; import java.awt.Graphics; import java.awt.Rectangle; import javax.swing.JFrame; public class Mickey extends Canvas { public static void main(String[] args) { JFrame frame = new JFrame("Mickey Mouse"); Canvas canvas = new Mickey(); canvas.setSize(400, 400); canvas.setBackground(Color.white); frame.add(canvas); frame.pack(); frame.setVisible(true); } public void paint(Graphics g) { Rectangle bb = new Rectangle(100, 100, 200, 200); mickey(g, bb); } public void...
create a project charter GENERAL PROJECT INFORMATION Project Name: Project Sponsor: Project Manager: Email Address: Phone...
create a project charter GENERAL PROJECT INFORMATION Project Name: Project Sponsor: Project Manager: Email Address: Phone Number: Organizational Unit: Process Impacted: Expected Start Date: Expected Completion Date: Expected Savings: Estimated Costs: PROBLEM, ISSUE, GOALS, OBJECTIVES, DELIVERABLES Problem or Issue: Purpose of Project: Business Case: Goals/Metrics: Expected Deliverables: PROJECT SCOPE & SCHEDULE Within Scope Outside of Scope PROJECT RESOURCES & COSTS Project Team Support Resources Special Needs PROJECT BENEFITS & CUSTOMERS Process Owner Key Stakeholders Final Customers Expected Benefits PROJECT RISKS,...
I have this MIPS code and I need to find: add f,g,h add f,f,i sub f,f,j...
I have this MIPS code and I need to find: add f,g,h add f,f,i sub f,f,j a. How many bits does it take to encode ? b. How many bits needed in register file to store the data?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT