• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

populating fields

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is part of a program. Can someone take a look?

JLabel lblId = new JLabel("ID:");
lblId.setBounds(5, 33, 30, 16);
frame.getContentPane().add(lblId);

textField_1 = new JTextField();
textField_1.setBounds(33, 27, 42, 28);
frame.getContentPane().add(textField_1);
textField_1.setColumns(10);

JLabel lblFirstName = new JLabel("First Name: ");
lblFirstName.setBounds(98, 33, 77, 16);
frame.getContentPane().add(lblFirstName);

textField_2 = new JTextField();
textField_2.setBounds(172, 27, 98, 28);
frame.getContentPane().add(textField_2);
textField_2.setColumns(10);

JLabel lblLastName = new JLabel("Last Name: ");
lblLastName.setBounds(304, 33, 77, 16);
frame.getContentPane().add(lblLastName);

textField_3 = new JTextField();
textField_3.setBounds(385, 27, 98, 28);
frame.getContentPane().add(textField_3);
textField_3.setColumns(10);

JLabel lblEmployeeStatus = new JLabel("Employee Status:");
lblEmployeeStatus.setBounds(10, 76, 111, 16);
frame.getContentPane().add(lblEmployeeStatus);

JButton btnAddEmployee = new JButton("Add Employee");
btnAddEmployee.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
String firstName = textField_2.getText(); //get first name
String lastName = textField_3.getText(); //get lastst name
String eID = textField_1.getText(); //get ID

System.out.println(firstName); //debug print statements, nothing prints
System.out.println(lastName);
System.out.println(eID);


Status statusEmployee = Status.HOURLY; checks for HOURLY employ, another program has the enum values for HOURLY AND FULLTIME

int eid = Integer.parseInt(eID); //ocnverting ID string to integer

System.out.println(eid); //debug statement to print ID but nothing prints


if (radioButtonText.toUpperCase().equals("FULLTIME") == true) //check for FULLTIME and HOURLY
{
statusEmployee = Status.FULLTIME;
}
else
{
statusEmployee = Status.HOURLY;
}

if(isValid(firstName, lastName, eID)){
//create record
employees[index] = createEmployee1(eid, firstName, lastName, statusEmployee); //validity check
}
else{
textField_1.setText("Invalid Data Entered: Please reenter");
}
}
});

btnAddEmployee.setBounds(189, 176, 117, 29);
frame.getContentPane().add(btnAddEmployee);


I would appreciate ideas on how I can get those fields not populating to populate.



Janet
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, but I can see some other errors.
  • 1: Never use == true or == false. Thgey are poor style and error‑prone especially if you write = by mistake.
  • 2: You are incorrect about checking for hourly employees. You are using the = sign but that does not check. It is setting the type to hourly.
  • Your code is very difficult to read without code tags and with those long lines.

    You say you have two print statements to check on eID which do not print anything. It is not possible for a println statement not to print anything, even if only a new line. The only way you can get no output from those statements is if they are never called. They don't appear to be in an if‑else or anything, so I must presume they are inside a method which is not being called.

    Don't write
    if (b == true) ...
    It is
    if (b) ...
    Don't write
    if (b == false) ...
    It is
    if (!b) ...
    Similarly for while, etc.
     
    Campbell Ritchie
    Marshal
    Posts: 79180
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    And I presume you are not suffering any Exceptions anywhere.
     
    Janet Heath
    Greenhorn
    Posts: 22
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    When you say code tags, do you mean comments? I put in comments for the areas in question.

    As for the ==, you do need to be careful not to use =. I have been taught and programmed using == throughout school and my programming career. I don't see that as sloppy at all.

    I don't know what lines are too long to figure out. They are just lines of code and they don't wrap around.

    Rather than checking for HOURLY, it initializes the status to HOURLY then checks for HOURLY or FULLTIME

    Yes, I do get exception errors.

    FullTime



    Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at PayRoll$4.actionPerformed(PayRoll.java:161)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)


     
    Campbell Ritchie
    Marshal
    Posts: 79180
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    It would have helped if you had told us about the Exception. It would appear you are trying to read from an empty box and the parseInt method doesn't like text which doesn't correspond exactly to an int.

    Have you tried a Scanner?Warning: if you enter

    1234 Janet

    in the text box, that code will regard the 1234 as a valid int.
     
    Janet Heath
    Greenhorn
    Posts: 22
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Sorry, I was trying to avoid putting a lot of information on the thread.

    I have not tried the Scanner/JOptionPane as I am doing GUI.
     
    Campbell Ritchie
    Marshal
    Posts: 79180
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Use that admittedly obscure use of a Scanner. That way you will not get that Exception. And you will also get a nice box appearing in the middle of your display saying something has gone wrong.
     
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic