Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import scala.swing._
- import scala.swing.event._
- object Moneta extends SimpleSwingApplication {
- //top method in SimpleSwingApplication is abstract
- def top = new MainFrame { //MainFrame terminates the application when closed
- title = "Moneta";
- preferredSize = new java.awt.Dimension(240, 150);
- private var r=0;
- private var o=0;
- private val reszkaTextField:TextField=new TextField("Liczba reszek: 0",10){editable=false;};
- private val orzelTextField:TextField=new TextField("Liczba orlow: 0",10){editable=false;};
- private val button:Button=new Button("Rzuc moneta"){
- background = java.awt.Color.CYAN
- }
- contents = new FlowPanel() {
- contents +=button;
- contents +=orzelTextField;
- contents +=reszkaTextField;
- }
- listenTo(button)
- reactions += {
- case ButtonClicked(b) =>
- {
- if(Math.random() < 0.5)
- {
- r+=1;
- reszkaTextField.text="Liczba reszek: "+r;
- }
- else
- {
- o+=1;
- orzelTextField.text="Liczba orlow: "+o;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement