/* generelancers.java - jpq - 05/02/00 - 01/03/00
 * modification et ajout de main() le 07/02/18
 * JFrame, JPanel et modifications le 26/02/21
 * génère n résultats F ou P avec les probabilités 1/2
 */

import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.util.*;

public class generelancers extends JPanel implements ActionListener {
  static final long serialVersionUID = 210226L;
  TextArea ta;
  Button ok;
  Random r;
  TextField tn;
  int n = 100;

  public generelancers() {
	setLayout (new FlowLayout());
    setBackground (Color.lightGray);
	add (tn = new TextField ("100"));
    add (ok = new Button ("Lancers"));
    ok.addActionListener (this);
    add (ta = new TextArea ("", 7, 50, TextArea.SCROLLBARS_BOTH));
    r = new Random ();
  }

  public void actionPerformed (ActionEvent e) {
	if (e.getSource () == ok) {
	  ta.setText ("");
	  int nn = n;
	  try {
	    nn = Integer.parseInt (tn.getText());
      }
	  catch (NumberFormatException nfe) {}
	  if (nn >= 0)
	    n = nn;
	  tn.setText (Integer.toString (n));
      for (int j = 0; j < n; j ++)
      { int cote = (int)(r.nextDouble () * 2.0);
        if (cote == 0) ta.append ("P"); else ta.append ("F");
        if (j % 20 == 19) ta.append ("\n");
      }
    }
  }

////////////////////////////////////////////////////////////////////////////////

	public static void main (String [] args) {
		generelancers a = new generelancers();

		JFrame f = new JFrame ("generelancers");
		f.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
		f.add (a);
		f.setSize (400, 200);
		f.setVisible (true);
    }

}
