boolean reset=false;

double x=100,y=100;

int liczbasukcesów=0,liczbalosowań=0;

String wartośćoszacowana;

NumberFormat f=new DecimalFormat("0.###");

double x1, y1, x2, y2;

rysunek rys=new rysunek();

/** Creates new form zaadd(rys);danie11d */

public zadanie11d() {

initComponents();

add(rys);

}

public void strzal(){

boolean sukces=false;

for(int i=0;i<2;i++){

x=Math.random();

y=Math.random();

if(x<=0.3||y<=0.4){sukces=true;}

rys.repaint();

}

liczbalosowań++;

if(sukces){liczbasukcesów++;}

wartośćoszacowana=f.format((double)liczbasukcesów/liczbalosowań);

jTextField1.setText(liczbalosowań+"");

jTextField2.setText(liczbasukcesów+"");

jTextField3.setText(wartośćoszacowana);

}

boolean sukces(){

return true;

}

public class rysunek extends JPanel

{

public rysunek(){

setBounds(20,20,150,150);

setBorder(BorderFactory.createLineBorder(Color.black));

}

public void paintComponent(Graphics g){

int x1,y1;

g.setColor(Color.BLACK);

g.drawOval(24, 24, 110, 110);

if(reset){

g.clearRect(0, 0, 400, 400);

g.drawOval(24, 24, 110, 110);

reset=false;

}

else{

if(x<=0.3){

x1=(int)(150*Math.random());

y1=(int)(150*Math.random());

while(((75-x1)*(75-x1)+(85-y1)*(85-y1))>2500){

x1=(int)(150*Math.random());

y1=(int)(150*Math.random());

}

g.setColor(Color.red);

g.fillOval(x1, y1, 5, 5);

}

else{x1=(int)(150*Math.random());

y1=(int)(150*Math.random());

while(((75-x1)*(75-x1)+(85-y1)*(85-y1))<2500){

x1=(int)(150*Math.random());

y1=(int)(150*Math.random());

}

g.setColor(Color.red);

g.fillOval(x1, y1, 5, 5);}

if(y<=0.4){x1=(int)(150*Math.random());

y1=(int)(150*Math.random());

while(((75-x1)*(75-x1)+(85-y1)*(85-y1))>2500){

x1=(int)(150*Math.random());

y1=(int)(150*Math.random());

}

g.setColor(Color.BLUE);

g.fillOval(x1, y1, 5,5);

}

else{x1=(int)(150*Math.random());

y1=(int)(150*Math.random());

while(((75-x1)*(75-x1)+(85-y1)*(85-y1))<2500){

x1=(int)(150*Math.random());

y1=(int)(150*Math.random());

}

g.setColor(Color.BLUE);

g.fillOval(x1, y1, 5,5);}}

}

}

/** This method is called from within the constructor to

* initialize the form.

* WARNING: Do NOT modify this code. The content of this method is

* always regenerated by the Form Editor.

*/

@SuppressWarnings("unchecked")

private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {

}

private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {

}

private void strzaly(java.awt.event.ActionEvent evt) {

strzal();

}

private void reset(java.awt.event.ActionEvent evt) {

liczbasukcesów=0;

liczbalosowań=0;

wartośćoszacowana=0+"";

jTextField1.setText(liczbalosowań+"");

jTextField2.setText(liczbasukcesów+"");

jTextField3.setText(wartośćoszacowana);

reset=true;

rys.repaint();

}

/**

* @param args the command line arguments

*/

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new zadanie11d().setVisible(true);

}

});