Guest User

Untitled

a guest
Jan 15th, 2012
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.04 KB | None | 0 0
  1. /**
  2.  * @(#)spel.java
  3.  *
  4.  * spel Applet application
  5.  *
  6.  * @author
  7.  * @version 1.00 2012/1/12
  8.  */
  9. import java.awt.*;
  10. import java.applet.*;
  11. import java.awt.event.*;
  12.  
  13. public class dobbel extends Applet implements ActionListener
  14. {
  15.   Button gooiknop, eersteknop, tweedeknop, derdeknop,vierdeknop, totaalknop, resetknop;
  16.   TextField eerstetekstvak, tweedetekstvak, derdetekstvak, vierdetekstvak, totaaltekstvak, ogentekstvak;
  17.   private int aantalOgen;
  18.   private int aantalOgen2;
  19.   private int aantalOgen3;
  20.   private int totaalOgen;
  21.   private int eindeOgen;
  22.  
  23.  
  24.  public void init()
  25.  {
  26.   setLayout( null );
  27.  
  28.   gooiknop = new Button ( "gooi" );
  29.   gooiknop.setBounds ( 50, 10, 150, 30 );
  30.   add ( gooiknop );
  31.   gooiknop.addActionListener( this );
  32.    
  33.   eersteknop = new Button ( "1x" );
  34.   eersteknop.setBounds ( 50, 60, 100, 20 );
  35.   add ( eersteknop );
  36.   eersteknop.addActionListener(this);
  37.  
  38.   tweedeknop = new Button ( "2x" );
  39.   tweedeknop.setBounds ( 50, 90, 100, 20 );
  40.   add ( tweedeknop );
  41.   tweedeknop.addActionListener(this);
  42.  
  43.   derdeknop = new Button ( "3x" );
  44.   derdeknop.setBounds ( 50, 120, 100, 20 );
  45.   add ( derdeknop );
  46.   derdeknop.addActionListener( this);
  47.    
  48.   vierdeknop = new Button ( "4x" );
  49.   vierdeknop.setBounds (50, 150, 100, 20 );
  50.   add ( vierdeknop );
  51.   vierdeknop.addActionListener(this);
  52.  
  53.   totaalknop = new Button ( "Totaal" );
  54.   totaalknop.setBounds ( 50, 200, 150, 30);
  55.   add ( totaalknop );
  56.   totaalknop.addActionListener(this);
  57.  
  58.   resetknop = new Button( "Opnieuw" );
  59.   resetknop.setBounds( 335, 200, 150, 30);
  60.   add( resetknop );
  61.   resetknop.addActionListener(this);
  62.  
  63.   eerstetekstvak = new TextField ( 10 );
  64.   eerstetekstvak.setBounds (160, 60, 100, 20);
  65.   add( eerstetekstvak );
  66.  
  67.   tweedetekstvak = new TextField ( 10 );
  68.   tweedetekstvak.setBounds ( 160, 90, 100, 20);
  69.   add( tweedetekstvak );
  70.  
  71.   derdetekstvak = new TextField ( 10 );
  72.   derdetekstvak.setBounds ( 160, 120, 100, 20);
  73.   add ( derdetekstvak );
  74.  
  75.   vierdetekstvak = new TextField ( 10 );
  76.   vierdetekstvak.setBounds ( 160, 150, 100, 20);
  77.   add (vierdetekstvak);
  78.  
  79.   totaaltekstvak = new TextField ( 10 );
  80.   totaaltekstvak.setBounds ( 210, 200, 50, 30);
  81.   add ( totaaltekstvak );
  82.  
  83.   ogentekstvak = new TextField( 10 );
  84.   ogentekstvak.setBounds( 300, 100, 50, 40 );
  85.   add(ogentekstvak);
  86.  
  87.  }
  88.  public void paint(Graphics g)
  89.   {
  90.   g.drawRect ( 300, 10, 50, 50 );
  91.   g.drawRect ( 360, 10, 50, 50 );
  92.   g.drawRect ( 420, 10, 50, 50 );
  93.   g.setColor( Color.black );
  94.    
  95.    
  96.     if(this.aantalOgen == 1)
  97.             {
  98.   g.fillOval( 320, 30, 10, 10);
  99.             }
  100.     if(this.aantalOgen2 == 1)
  101.             {
  102.   g.fillOval( 380, 30, 10, 10);
  103.             }
  104.     if(this.aantalOgen3 == 1)
  105.             {
  106.   g.fillOval( 440, 30, 10, 10);
  107.             }  
  108.              
  109.              
  110.              
  111.      if(this.aantalOgen == 2)
  112.             {
  113.   g.fillOval( 335, 15, 10, 10);
  114.   g.fillOval( 305, 45, 10, 10);
  115.             }
  116.     if(this.aantalOgen2 == 2)
  117.             {
  118.   g.fillOval( 395, 15, 10, 10);  
  119.   g.fillOval( 365, 45, 10, 10);
  120.             }
  121.     if(this.aantalOgen3 == 2)
  122.             {
  123.   g.fillOval( 455, 15, 10, 10);
  124.   g.fillOval( 425, 45, 10, 10);
  125.             }
  126.              
  127.              
  128.              
  129.    if(this.aantalOgen == 3)
  130.             {
  131.   g.fillOval( 335, 15, 10, 10);
  132.   g.fillOval( 305, 45, 10, 10);
  133.   g.fillOval( 320, 30, 10, 10);
  134.             }
  135.    if(this.aantalOgen2 == 3)
  136.             {
  137.   g.fillOval( 395, 15, 10, 10);  
  138.   g.fillOval( 365, 45, 10, 10);
  139.   g.fillOval( 380, 30, 10, 10);
  140.             }
  141.    if(this.aantalOgen3 == 3)
  142.             {
  143.   g.fillOval( 455, 15, 10, 10);
  144.   g.fillOval( 425, 45, 10, 10);
  145.   g.fillOval( 440, 30, 10, 10);
  146.             }
  147.              
  148.              
  149.              
  150.      if(this.aantalOgen == 4)
  151.             {
  152.   g.fillOval( 305, 15, 10, 10);
  153.   g.fillOval( 335, 15, 10, 10);
  154.   g.fillOval( 305, 45, 10, 10);
  155.   g.fillOval( 335, 45, 10, 10);
  156.             }
  157.     if(this.aantalOgen2 == 4)
  158.             {
  159.   g.fillOval( 365, 15, 10, 10);  
  160.   g.fillOval( 395, 15, 10, 10);
  161.   g.fillOval( 365, 45, 10, 10);
  162.   g.fillOval( 395, 45, 10, 10);
  163.             }
  164.     if(this.aantalOgen3 == 4)
  165.             {
  166.   g.fillOval( 425, 15, 10, 10);
  167.   g.fillOval( 455, 15, 10, 10);
  168.   g.fillOval( 425, 45, 10, 10);
  169.   g.fillOval( 455, 45, 10, 10);
  170.             }
  171.              
  172.              
  173.              
  174.   if(this.aantalOgen == 5)
  175.             {
  176.   g.fillOval( 305, 15, 10, 10);
  177.   g.fillOval( 335, 15, 10, 10);
  178.   g.fillOval( 305, 45, 10, 10);
  179.   g.fillOval( 335, 45, 10, 10);
  180.   g.fillOval( 320, 30, 10, 10);
  181.             }
  182.     if(this.aantalOgen2 == 5)
  183.             {
  184.   g.fillOval( 365, 15, 10, 10);  
  185.   g.fillOval( 395, 15, 10, 10);
  186.   g.fillOval( 365, 45, 10, 10);
  187.   g.fillOval( 395, 45, 10, 10);
  188.   g.fillOval( 380, 30, 10, 10);  
  189.             }
  190.     if(this.aantalOgen3 == 5)
  191.             {
  192.   g.fillOval( 425, 15, 10, 10);
  193.   g.fillOval( 455, 15, 10, 10);
  194.   g.fillOval( 425, 45, 10, 10);
  195.   g.fillOval( 455, 45, 10, 10);
  196.   g.fillOval( 440, 30, 10, 10);
  197.             }
  198.              
  199.              
  200.              
  201.              
  202.     if(this.aantalOgen == 6)
  203.             {
  204.   g.fillOval( 305, 15, 10, 10);
  205.   g.fillOval( 335, 15, 10, 10);
  206.   g.fillOval( 305, 45, 10, 10);
  207.   g.fillOval( 335, 45, 10, 10);
  208.   g.fillOval( 305, 30, 10, 10);
  209.   g.fillOval( 335, 30, 10, 10);
  210.             }
  211.     if(this.aantalOgen2 == 6)
  212.             {
  213.   g.fillOval( 365, 15, 10, 10);  
  214.   g.fillOval( 395, 15, 10, 10);
  215.   g.fillOval( 365, 45, 10, 10);
  216.   g.fillOval( 395, 45, 10, 10);
  217.   g.fillOval( 395, 30, 10, 10);
  218.   g.fillOval( 365, 30, 10, 10);
  219.             }
  220.     if(this.aantalOgen3 == 6)
  221.             {
  222.   g.fillOval( 425, 15, 10, 10);
  223.   g.fillOval( 455, 15, 10, 10);
  224.   g.fillOval( 425, 45, 10, 10);
  225.   g.fillOval( 455, 45, 10, 10);
  226.   g.fillOval( 425, 30, 10, 10);
  227.   g.fillOval( 455, 30, 10, 10);
  228.             }  
  229.   ogentekstvak.setText( "" + totaalOgen );
  230.  
  231.      }
  232.  
  233.  
  234.  
  235.  public void actionPerformed( ActionEvent e )
  236.  {
  237.   if(e.getSource() == gooiknop )
  238.    {
  239.     this.aantalOgen = gooiDobbelsteen();
  240.     this.aantalOgen2 = gooiDobbelsteen();
  241.     this.aantalOgen3 = gooiDobbelsteen();
  242.     totaalOgen = aantalOgen + aantalOgen2 + aantalOgen3;
  243.     repaint();
  244.    }
  245.    if( e.getSource() == eersteknop )
  246.    {
  247.    eerstetekstvak.setText( "" + totaalOgen );
  248.    eersteknop.setVisible( false );
  249.    }
  250.    
  251.    if( e.getSource() == tweedeknop )
  252.    {
  253.     tweedetekstvak.setText( "" + totaalOgen * 2 );
  254.     tweedeknop.setVisible( false );
  255.    }
  256.    
  257.    if( e.getSource() == derdeknop )
  258.    {
  259.     derdetekstvak.setText( "" + totaalOgen * 3);
  260.     derdeknop.setVisible( false );
  261.    }
  262.    
  263.    if( e.getSource() == vierdeknop )
  264.    {
  265.     vierdetekstvak.setText( "" + totaalOgen * 4);
  266.     vierdeknop.setVisible( false );
  267.    }
  268.    
  269.    if( e.getSource() == resetknop )
  270.    {
  271.     eerstetekstvak.setText( "" );
  272.     tweedetekstvak.setText( "" );
  273.     derdetekstvak.setText( "" );
  274.     vierdetekstvak.setText( "" );
  275.     totaaltekstvak.setText( "" );
  276.     ogentekstvak.setText( "" );
  277.     eersteknop.setVisible( true );
  278.     tweedeknop.setVisible( true );
  279.     derdeknop.setVisible( true );
  280.     vierdeknop.setVisible( true );
  281.    }
  282.    
  283.    if( e.getSource() == totaalknop )
  284.    {
  285.     String invoerstring;
  286.     int getal1, getal2, getal3, getal4, eindeOgen;
  287.     invoerstring = eerstetekstvak.getText();
  288.     getal1 = Integer.parseInt( invoerstring );
  289.    
  290.     invoerstring = tweedetekstvak.getText();
  291.     getal2 = Integer.parseInt( invoerstring );
  292.    
  293.     invoerstring = derdetekstvak.getText();
  294.     getal3 = Integer.parseInt( invoerstring );
  295.    
  296.     invoerstring = vierdetekstvak.getText() ;
  297.     getal4 = Integer.parseInt( invoerstring );
  298.    
  299.     eindeOgen = getal1 + getal2 + getal3 + getal4;
  300.     totaaltekstvak.setText( "" + eindeOgen );
  301.    }
  302.    
  303.  }
  304. public int gooiDobbelsteen()
  305. {  
  306.          double t;  
  307.          t = Math.random();  
  308.          t *= 6;  
  309.          t += 1;  
  310.          return ( int) t;      
  311. }
  312.  
  313. }
Advertisement
Add Comment
Please, Sign In to add comment