Advertisement
Guest User

Untitled

a guest
Jan 24th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.13 KB | None | 0 0
  1. import scala.swing._
  2. import scala.swing.event._
  3.  
  4. object Moneta extends SimpleSwingApplication {
  5.   //top method in SimpleSwingApplication is abstract
  6.   def top = new MainFrame { //MainFrame terminates the application when closed
  7.     title = "Moneta";
  8.     preferredSize = new java.awt.Dimension(240, 150);
  9.     private var r=0;
  10.     private var o=0;
  11.     private val reszkaTextField:TextField=new TextField("Liczba reszek: 0",10){editable=false;};
  12.     private val orzelTextField:TextField=new TextField("Liczba orlow: 0",10){editable=false;};
  13.     private val button:Button=new Button("Rzuc moneta"){
  14.        background = java.awt.Color.CYAN
  15.     }
  16.    
  17.     contents = new FlowPanel() {
  18.       contents +=button;
  19.       contents +=orzelTextField;
  20.       contents +=reszkaTextField;
  21.     }
  22.     listenTo(button)
  23.     reactions += {
  24.       case ButtonClicked(b) =>
  25.         {
  26.           if(Math.random() < 0.5)
  27.           {
  28.             r+=1;
  29.             reszkaTextField.text="Liczba reszek: "+r;
  30.           }
  31.           else
  32.           {
  33.             o+=1;
  34.             orzelTextField.text="Liczba orlow: "+o;
  35.           }
  36.         }
  37.     }
  38.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement