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?

