updating JTextField

With this program, I want to update a number in the JTextField when I push this button. Here's a piece of the code:

import java.io.*;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

publicclass GUISetupextends JPanel

{

public GUISetup()

{

//Step Button

step =new JButton("Step");

step.addActionListener(new StepListener());

add(step);

//Labels

counterField =new JTextField(""+numCounter, 2);

counterLabel =new JLabel("PC: ");

add(counterLabel);

add(counterField);

}

class StepListenerimplements ActionListener

{

publicvoid actionPerformed(ActionEvent e)

{

numCounter++;

counterField.repaint();

}

}

privatestaticvoid createAndShowGUI()

{

//Create and set up the window.

JFrame frame =new JFrame("PIPPIN");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Create and set up the content pane.

GUISetup newContentPane =new GUISetup();

newContentPane.setOpaque(true);

frame.setContentPane(newContentPane);

//Display the window.

frame.pack();

frame.setVisible(true);

}

publicstaticvoid main(String[] args)

{

//new GUISetup();

javax.swing.SwingUtilities.invokeLater(new Runnable(){

publicvoid run(){

createAndShowGUI();

}

});

}

JTextField counterField;

JLabel counterLabel;

JButton step;

int numCounter = 0;

}

Now, I just want numCounter on the GUI to go up by one every time I press "Step." However, it is staying at zero whenever I push the button. What am I doing wrong? Or is there a better JComponent I could use for this?

[3487 byte] By [Kingsminda] at [2007-11-27 3:38:11]
# 1
counterField.repaint();this repaints the JTextField alright, but it does not change the value displayed in the JTextField...to do that, you need to call the setText() methods, check the API for more details
MaxxDmga at 2007-7-12 8:41:29 > top of Java-index,Java Essentials,New To Java...
# 2
Ah, that works, thanks.
Kingsminda at 2007-7-12 8:41:29 > top of Java-index,Java Essentials,New To Java...