Solve the following exercise:   1. Use the following Java code to answer the following: to. Correct the errors that it has b. Add required statements, routines, or modules c. Explain the logic of the program and how it works

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Solve the following exercise:
 

1. Use the following Java code to answer the following:
to. Correct the errors that it has
b. Add required statements, routines, or modules
c. Explain the logic of the program and how it works

 

// Demonstration of the JTextField class.
import java.awt. *;
import java.awt.event. *;
import javax.swing. *;
public class TestTextField extends JFrame
{
  private JTextField textfield1, textfield2, textfield3;
  private JPasswordField password field;
 

  // configure GUI
  public TestTextField ()
{
    super ("Text Entry Test and Password Sample");
 

    Container container = getContentPane ();
    container.setLayout (new FlowLayout ());
 

   // create text field with default size
   textfield1 = new JTextField (10);
   container.add (textfield1);
 

  // create text field with default text
  TextField2 = new JTextField ("                                         ");
   container.add (textfield2);
 

  // create text field with default text,
  // 20 visible elements and no event handler
  Text3 field = new JTextField ("Non-editable text field", 20);
   Field Text3.setEditable (false);
  Text field3.setToolTipText ("This cannot be edited");
   container.add (fieldText3);

  // create password field with default text
  password field = new JPasswordField ("Hidden text");
 container.add (password field);
 

    // register event handlers
    HandlerTextField handle = new HandlerTextField ();
    Field Text1.addActionListener (handler);
    Field Text2.addActionListener (handler);
    Text field3.addActionListener (handler);
    Password field.addActionListener (handler);
  

    setSize (325, 100);
    setVisible (true);
 

} // end of TextFieldTest constructor and start of main method
 

public main (String args [])
{
   TestTextField application = new TestTextField ();
   application.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
}
// private inner class for event handling
private class TextField Handler implements ActionListener
{
   // process text field events
   public void action Performed (ActionEvent event)
   {
     String string = "";
 

    // user pressed Enter on object JTextField textfield1
    if (event.getSource () == textfield1)
       string = "fieldText1:" + event.getActionCommand ();
 

   // user pressed Enter on object JTextField textfield2
   else if (event.getSource () == textfield2)
      string = "fieldText2:" + event.getActionCommand ();
 

   // user pressed Enter on JTextField objectTextField3
   else if (event.getSource () == textField3)
      string = "fieldText3:" + event.getActionCommand ();
 

  // user pressed Enter on object JTextField password field
  else if (event.getSource () == password field) {
    string = "Password field:" +
       new String (password field.getPassword ());
   }
  JOptionPane.showMessageDialog (null,
string, "Results", JOptionPane.CANCEL_OPTION);
 

} // end of actionPerformed method
  

  } // end of private inner classTextFieldHandler

} // end of the TestTextField class 

Expert Solution
steps

Step by step

Solved in 3 steps with 6 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY