I tried the code as you have it below. But instead of diaplying the number in the textbox next to the number of users it replaces the username.
CODE
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class logonTracking extends JFrame implements ActionListener
{
//Declaring variables
String users;
boolean success;
//Construct variables
String userArray[] = {"dbrine", "bbrine", "mbrine", "kbrine"};
//construct a panel for the fields and buttons
JPanel userPanel = new JPanel();
JPanel buttonPanel = new JPanel();
JPanel numberOfUsersPanel = new JPanel();
//construct labels and text boxes
JLabel userLabel = new JLabel("User: ");
JTextField user = new JTextField(10);
JLabel numOfUsersLabel = new JLabel("Number of Users: ");
JTextField NumoUs = new JTextField(4);
//construct buttons
JButton logonButton = new JButton("Logon");
JButton logoffButton = new JButton("Logoff");
public static void main(String[] args)
{
logonTracking f = new logonTracking();
f.setSize(200,125);
f.setTitle("User Tracking");
f.setResizable(false);
f.setLocation(200,200);
f.setVisible(true);
}
public logonTracking()
{
//add user panel to content panel
JPanel userPanel= new JPanel(new BorderLayout());
userPanel.add(userLabel,BorderLayout.WEST);
userPanel.add(user,BorderLayout.EAST);
//add button panel to content panel
JPanel buttonPanel= new JPanel(new FlowLayout());
buttonPanel.add(logonButton);
buttonPanel.add(logoffButton);
//add number of users panel
JPanel numberOfUsersPanel= new JPanel(new BorderLayout());
numberOfUsersPanel.add(numOfUsersLabel,BorderLayout.WEST);
numberOfUsersPanel.add(NumoUs,BorderLayout.EAST);
//add content panel to frame
JPanel contentPanel= new JPanel(new FlowLayout());
contentPanel.add(userPanel);
contentPanel.add(buttonPanel);
contentPanel.add(numberOfUsersPanel);
setContentPane(contentPanel);
logonButton.addActionListener(this);
logoffButton.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
Integer NumoUs = new Integer(0);
users = user.getText();//users id name
success = false; //assumes failed login
//Sequential search
for (int i = 0; i < userArray.length; i++)
if((userArray[i].compareTo(users)==0))
success = true;
{
if(success == true)
{
NumoUs++;
user.setText(NumoUs.toString());
NumoUs = Integer.getInteger(user.getText());
}
else if(success == false)
{
NumoUs--;
JOptionPane.showMessageDialog(this,"UserName not Found", "Invalid username. Try again.", JOptionPane.ERROR_MESSAGE);
clearFields();
}
}
}
//clears the login and password if incorrect
public void clearFields()
{
user.setText("");
user.requestFocus();
}
}
QUOTE(keems21 @ 19 May, 2007 - 04:10 PM)

QUOTE(dbrine @ 19 May, 2007 - 01:11 PM)

thanks. I tried that but it changes the username to a number. I need to display the number of logged on users in the textbox, then I will have to make it uneditable by the user.
By making the int to an Integer though, you're making it into an Object. That way you can change it from a number to a String just by using the toString() method on it.
As for making the textField uneditable, use this method:
textFieldName.setEditable(false);
That should do the trick.