Question

Why when executed my frame does not contain what i have added to it? Here is...

Why when executed my frame does not contain what i have added to it?

Here is my code

import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

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

@SuppressWarnings("serial")
public class AddressBook1 extends JFrame implements ActionListener {
   /**
   *
   */
  
   JLabel name = new JLabel("Name: ");
   JLabel address = new JLabel("Address: ");
   JLabel phone = new JLabel("Phone: ");
   JLabel email = new JLabel("Email: ");
  
   JTextField nameField = new JTextField();
   JTextField addressField = new JTextField();
   JTextField phoneField = new JTextField();
   JTextField emailField = new JTextField();
  
   JButton addContact = new JButton("Add Contact");
   JButton saveToFile = new JButton("Save to File");
  
   JTextArea contactsTextArea = new JTextArea(20,50);
  
   JPanel panel = new JPanel();

  
   public AddressBook1() {
      
       panel.add(name);
       panel.add(address);
       panel.add(phone);
       panel.add(email);
       panel.add(nameField);
       panel.add(addressField);
       panel.add(phoneField);
       panel.add(emailField);
       panel.add(addContact);
       panel.add(saveToFile);
       panel.add(contactsTextArea);
      
   //   frame.add(panel);
      
  

       // TODO Auto-generated constructor stub
   }
  
   public void readContactsFromFile() {
      
   }
  

  
   @Override
   public void actionPerformed(ActionEvent e) {
       if(e.getActionCommand().equals("Add Contact")) {
          
       }
       else if(e.getActionCommand().equals("Save to File")) {
          
       }
       // TODO Auto-generated method stub
      
   }
  
   public void writeContactsToFile() {
      
   }
  
   public static void main(String[] args) {
      
       JFrame frame = new JFrame();
      
      
       AddressBook1 addBook = new AddressBook1();
      
      
       addBook.setSize(300,400);
       addBook.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       addBook.setVisible(true);
   }

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

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

@SuppressWarnings("serial")
public class AddressBook1 extends JFrame implements ActionListener {
   /**
   *
   */

   JLabel name = new JLabel("Name: ");
   JLabel address = new JLabel("Address: ");
   JLabel phone = new JLabel("Phone: ");
   JLabel email = new JLabel("Email: ");

   JTextField nameField = new JTextField(10);
   JTextField addressField = new JTextField(10);
   JTextField phoneField = new JTextField(10);
   JTextField emailField = new JTextField(10);

   JButton addContact = new JButton("Add Contact");
   JButton saveToFile = new JButton("Save to File");

   JTextArea contactsTextArea = new JTextArea(20,50);

   JPanel panel = new JPanel();
   JFrame frame;

   public AddressBook1() {

       panel.add(name);
       panel.add(address);
       panel.add(phone);
       panel.add(email);
       panel.add(nameField);
       panel.add(addressField);
       panel.add(phoneField);
       panel.add(emailField);
       panel.add(addContact);
       panel.add(saveToFile);
       panel.add(contactsTextArea);
       frame = new JFrame();


       frame.setSize(300,400);
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       frame.setVisible(true);
       // missed adding panel to the frame
       // as you have created the frame inside the main
       frame.add(panel);

       // TODO Auto-generated constructor stub
   }

   public void readContactsFromFile() {

   }

   @Override
   public void actionPerformed(ActionEvent e) {
       if(e.getActionCommand().equals("Add Contact")) {

       }
       else if(e.getActionCommand().equals("Save to File")) {

       }
       // TODO Auto-generated method stub

   }

   public void writeContactsToFile() {

   }

   public static void main(String[] args) {

       AddressBook1 addBook = new AddressBook1();

   }

}

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

Add a comment
Know the answer?
Add Answer to:
Why when executed my frame does not contain what i have added to it? Here is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • tart from the following code, and add Action Listener to make it functional to do the...

    tart from the following code, and add Action Listener to make it functional to do the temperature conversion in the direction of the arrow that is clicked. . (Need about 10 lines) Note: import javax.swing.*; import java.awt.GridLayout; import java.awt.event.*; import java.text.DecimalFormat; public class temperatureConverter extends JFrame { public static void main(String[] args) {     JFrame frame = new temperatureConverter();     frame.setTitle("Temp");     frame.setSize(200, 100);     frame.setLocationRelativeTo(null);     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     frame.setVisible(true); }    public temperatureConverter() {     JLabel lblC = new...

  • Need help debugging Create a GUI application that accepts student registration data. Specifications: The text box...

    Need help debugging Create a GUI application that accepts student registration data. Specifications: The text box that displays the temporary password should be read-only. The temporary password consists of the user’s first name, an asterisk (*), and the user’s birth year. If the user enters data in the first three fields, display a temporary password in the appropriate text field and a welcome message in the label below the text fields. If the user does not enter data, clear the...

  • Swing File Adder: Build a GUI that contains an input file, text box and Infile button....

    Swing File Adder: Build a GUI that contains an input file, text box and Infile button. It also must contain and output file, text box and Outfile button. Must also have a process button must read the infile and write to the outfile if not already written that is already selected and clear button. It must pull up a JFile chooser that allows us to brows to the file and places the full path name same with the output file.  Program...

  • I have been messing around with java lately and I have made this calculator. Is there...

    I have been messing around with java lately and I have made this calculator. Is there any way that I would be able to get a different sound to play on each different button 1 - 9 like a nokia phone? Thank you. *SOURCE CODE* import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; class Calculator extends JFrame { private final Font BIGGER_FONT = new Font("monspaced",Font.PLAIN, 20); private JTextField textfield; private boolean number = true; private String equalOp = "="; private...

  • I am getting this Error can you please fix my Java code. import java.awt.Dialog; import java.awt.Label;...

    I am getting this Error can you please fix my Java code. import java.awt.Dialog; import java.awt.Label; import java.awt.TextArea; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class Fall_2017 {    public TextArea courseInput;    public Label textAreaLabel;    public JButton addData;    public Dialog confirmDialog;    HashMap<Integer, ArrayList<String>> students;    public Fall_2017(){    courseInput = new TextArea(20, 40);    textAreaLabel = new Label("Student's data:");    addData = new JButton("Add...

  • Add appropriate descriptive comments to each line of code in the project explaining why the code...

    Add appropriate descriptive comments to each line of code in the project explaining why the code is in the application. public class FutureValueFrame extends JFrame { private JTextField investmentField; private JTextField interestRateField; private JComboBox yearsComboBox; private JList futureValueList; private DefaultListModel futureValueModel; public FutureValueFrame() { initComponents(); } private void initComponents() { try { UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { System.out.println(e); } setTitle("Future Value Calculator"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationByPlatform(true); investmentField = new JTextField(); interestRateField = new JTextField();...

  • With the Code below, how would i add a "Back" Button to the bottom of the...

    With the Code below, how would i add a "Back" Button to the bottom of the history page so that it takes me back to the main function and continues to work? import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Scanner; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextField; public class RecipeFinder { public static void main(String[]...

  • Program #2 Write a program to simulate showing an NBA Team on a Basketball court Here...

    Program #2 Write a program to simulate showing an NBA Team on a Basketball court Here is an example of the screenshot when running the program: Tony Parker T. Splitter T. Duncan M. Gineb Player Kame: M Ginobil Player Age 2 Add A Player Ce An example of the JFrame subclass with main method is as follows import java.awt. import java.awt.event." import javax.swing. public class NBA Playoff extends JFrame private JTextField txtName: private JTextField txtAge: private NBATeam spurs private NBAcourtPanel...

  • How can i make the java class seperate into an MVC pattern? public class ChatView implements Acti...

    How can i make the java class seperate into an MVC pattern? public class ChatView implements ActionListener {    public static void main(String[] args)    {        JFrame chatFrame = new JFrame();        JFrame chatFrame1 = new JFrame();        JFrame chatFrame2 = new JFrame();               JPanel chatPanel = new JPanel();        JPanel chatPanel1 = new JPanel();        JPanel chatPanel2 = new JPanel();        chatFrame.setContentPane(chatPanel);        chatFrame1.setContentPane(chatPanel1);        chatFrame2.setContentPane(chatPanel2);        chatFrame.setLayout(new FlowLayout());        chatFrame1.setLayout(new FlowLayout());        chatFrame2.setLayout(new FlowLayout());        JTextField chatWrite = new JTextField();        JTextField chatWrite1 = new JTextField();        JTextField chatWrite2 = new JTextField();        JTextArea chatDisplay...

  • Can you please help me to run this Java program? I have no idea why it...

    Can you please help me to run this Java program? I have no idea why it is not running. import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.text.DecimalFormat; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.ListSelectionModel; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; @SuppressWarnings({"unchecked", "rawtypes"}) public class SmartPhonePackages extends JFrame { private static final long serialVersionID= 6548829860028144965L; private static final int windowWidth = 400; private static final int windowHeight = 200; private static final double SalesTax = 1.06; private static JPanel panel;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT