JPalle - Palle.java
Cerca
 











Palle.java

Caricato da: Paoloricciuti
Scarica il programma completo

  1. package frame;
  2.  
  3. import java.awt.event.MouseAdapter;
  4. import java.awt.event.MouseEvent;
  5. import javax.swing.JFrame;
  6. import javax.swing.JLabel;
  7.  
  8. /**
  9.  *
  10.  * @author Paolo
  11.  */
  12. public class Palle extends JFrame{
  13.    
  14.     private JLabel lab;
  15.     private JLabel lab2;
  16.  
  17.     private class Mouse extends MouseAdapter{
  18.  
  19.         private int angolo;
  20.  
  21.         public Mouse(){
  22.             this.angolo=0;
  23.         }
  24.  
  25.         @Override
  26.         public void mouseClicked(MouseEvent e) {
  27.             int random=(int) (Math.random()*360);
  28.             int vel=(int) (Math.random()*20);
  29.             vel+=2;
  30.             lab2.setText("Ultima velocità/angolo: "+vel+"/"+random);
  31.             Palla p= new Palla(new Angle(random), vel);
  32.             add(p);
  33.             p.start();
  34.             this.angolo++;
  35.             lab.setText("Conto palle: "+this.angolo);
  36.         }
  37.  
  38.     }
  39.  
  40.     public Palle() {
  41.         super("Palle");
  42.         this.setResizable(false);
  43.         this.setLayout(null);
  44.         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  45.         this.setBounds(100, 100, 400, 400);
  46.         this.lab= new JLabel("Conto palle: 0");
  47.         this.lab.setBounds(0, 0, 100, 16);
  48.         this.lab.setVisible(true);
  49.         this.add(this.lab);
  50.         this.lab2= new JLabel("Ultima velocità/angolo: 0/0");
  51.         this.lab2.setBounds(0, 16, 200, 16);
  52.         this.lab2.setVisible(true);
  53.         this.add(this.lab2);
  54.         this.addMouseListener(new Mouse());
  55.     }
  56.  
  57.     public static void main(String... args) {
  58.         new Palle().setVisible(true);
  59.     }
  60. }
 

Creative Commons License
Il layout di questo sito è concesso sotto licenza Creative Commons.
Per maggiori informazioni sulle licenze dei contenuti del sito, clicca.