0

" array dimension missing
TextField dsplNameField = new TextField[];"

What we are trying to do is allow user to input id and that will match to ids in the array and coresponding name

1
Contributor
1
Reply
2
Views
10 Years
Discussion Span
Last Post by korbynlehr
0

Here is the code I have, the problems I would like help with is as follows. I am unable to enter the id on the ID box and have it pull up the name of the person it coresponds to and the last window close does not fucntion properly.

Any help is appreciated.

import java.awt.*;
 import java.awt.event.*;
 import javax.swing.*;
 import java.text.*;
 import java.util.*;
 import javax.swing.JOptionPane;
 
 public class LTB_Screen extends Frame
 {
 Color slateGrey = new Color(185, 211, 238);
 Color royalBlue = new Color(67, 110, 238);

 int[]id = {123456789, 234567891, 345678912};
   String[] name = {"David", "Thomas", "Mark"};
 int i = 0;
 Date now = new Date();
 SimpleDateFormat FormatDate = new SimpleDateFormat("MM/dd/yy");

 Panel     dsplPanel     = new Panel();
 Label     dsplLabel     = new Label("Employee ID: ");
 TextField dsplNameField = new TextField (40);
 Panel     inputPanel   = new Panel();
 Label     empDateLabel = new Label("Date: " );
 JTextField empDateField= new JTextField(FormatDate.format(now));
 Label     empSSNLabel  = new Label("Employee Name: ");
 TextField empSSNField  = new TextField(8);
 Label     empSickLabel = new Label("Sick Time: ");
 TextField empSickField = new TextField(2);
 Label     empTimeLabel = new Label("Time off: ");
 TextField empTimeField = new TextField(3);
 Panel    buttonPanel = new Panel();
 Button   enterButton = new Button("Enter");

 Panel     hoursPanel = new Panel();
 TextArea  hoursDisplay[] = new TextArea[12];
 Label     empInLabel = new Label("IN");
 Label     empOutLabel = new Label("OUT");
 TextField empTime  = new TextField(5);
 

  public LTB_Screen()
  {
   //set Layouts for frame and three panels
   this.setLayout(new BorderLayout());
   dsplPanel.setLayout(new FlowLayout());
   inputPanel.setLayout(new GridLayout(4,2));
   buttonPanel.setLayout(new FlowLayout());
   hoursPanel.setLayout(new GridLayout(8,2,1,1));
        //add the components to the display only panel
        dsplPanel.add(dsplLabel);
        dsplPanel.add(dsplNameField);
   //add components to input panel
   inputPanel.add(empDateLabel);
   inputPanel.add(empDateField);
   inputPanel.add(empSSNLabel);
   inputPanel.add(empSSNField);
   inputPanel.add(empSickLabel);
   inputPanel.add(empSickField);
   inputPanel.add(empTimeLabel);
   inputPanel.add(empTimeField);
   //add components to button panel
   buttonPanel.add(enterButton);

        //add components to hours panel
        hoursPanel.add(empInLabel);
        hoursPanel.add(empOutLabel);
   for (int i=0; i<12; i++)
   {
    hoursDisplay[i] = new TextArea("",1,5,3);
    hoursDisplay[i].setEditable(false);
    hoursDisplay[i].setBackground(slateGrey);
    hoursPanel.add(hoursDisplay[i]);
   }
   //add panels to frame
   add(dsplPanel,   BorderLayout.NORTH);
   add(inputPanel,  BorderLayout.WEST);
   add(buttonPanel, BorderLayout.SOUTH);
   add(hoursPanel,  BorderLayout.CENTER);
 
 } //end of constructor method
 public static void main(String[] args)
 {
 //JFrame f = new JFrame("Employee Time Sheet");
 LTB_Screen f = new LTB_Screen();
 f.setBounds(250,250,500,300);
 f.setTitle("Employee Time Sheet");
 f.setVisible(true);
 //f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 } //end of main
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.