Here's a simple implementation of what you want:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class RandomNumber extends JFrame implements ActionListener {
private JButton button;
private JTextField valuesTextField, resultTextField, meanTextField;
private Random random;
private int total = 0;
private int count = 0;
public static void main(String[] args) {
RandomNumber frame = new RandomNumber();
frame.setSize(200,150);
frame.createGUI();
frame.show();
}
private void createGUI() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container window = getContentPane();
window.setLayout(new FlowLayout());
button = new JButton("Generate");
window.add(button);
button.addActionListener(this);
valuesTextField = new JTextField(14);
window.add(valuesTextField);
meanTextField = new JTextField(14);
window.add(meanTextField);
random = new Random();
}
public void actionPerformed(ActionEvent event) {
int r;
count+=1;
r = 200 + random.nextInt(200);
total+=r;
valuesTextField.setText("Number: " + Integer.toString(r));
meanTextField.setText("Mean: " + Double.toString((double)total/count));
}
} You just have to add variables that will keep track of the total and count and add a text box to display the mean.