Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.applet.Applet;
- import java.awt.Color;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.util.ArrayList;
- public class Appl extends Applet implements Runnable{
- ArrayList<Kwadrat> lista;
- public int losuj(int a, int b){
- return a+(int)(Math.random() * (b-a));
- }
- public Appl(){
- int N = 3;
- String ile = getParameter("ILE_KWADRATOW");
- if(ile != null){
- try{
- N=Integer.parseInt(ile);
- }catch(NumberFormatException e){
- System.err.println("Błedna wartość " + ile );
- }
- }
- lista = new ArrayList<Kwadrat>(N);
- Dimension d = getSize();
- for (int i = 0; i < N; i++){
- lista.add(new Kwadrat(losuj(20,60),d));
- }
- setBackground(Color.blue);
- new Thread(this).start();
- }
- public void paint(Graphics g){
- for(Kwadrat k : lista)
- k.rysuj(g);
- }
- public void run(){
- while(true){
- try{
- Thread.sleep(300);
- }catch(InterruptedException e){
- }
- for(Kwadrat k : lista)
- k.zmniejsz();
- repaint();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement