Advertisement
Guest User

Untitled

a guest
Feb 1st, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.35 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.util.Random;
  4.  
  5. import javax.swing.*;
  6.  
  7. public class puzzle implements ActionListener {
  8.          Random r ;
  9.         JButton b1, b2, b3, b4,b5,b6,b7,b8,b9;  
  10.         JLabel l1;
  11.        
  12.         double w1, w2, wyn;
  13.         JPanel p;
  14.         public puzzle() {
  15.             r=new Random();
  16.            
  17.            
  18.                 JFrame f = new JFrame();
  19.                 p = new JPanel();
  20.                
  21.                l1=new JLabel();
  22.                
  23.               // przycisk.setLocation(przycisk.getX()+ 5, przycisk.getY() +5); zmiana polozenia;
  24.                
  25.                 b1 = new JButton("losuj");
  26.                 b2 = new JButton("1");
  27.                 b3 = new JButton("2");
  28.                 b4 = new JButton("3");
  29.                 b5 = new JButton("4");
  30.                 b6 = new JButton("5");
  31.                 b7 = new JButton("6");
  32.                 b8 = new JButton("7");
  33.                 b9 = new JButton("8");
  34.                 f.add(p);
  35.              
  36.                
  37.              
  38.                 p.add(b1);
  39.                 p.add(b2);
  40.                 p.add(b3);
  41.                 p.add(b4);
  42.                 p.add(b5);
  43.                 p.add(b6);
  44.                 p.add(b7);
  45.                 p.add(b8);
  46.                 p.add(b9);
  47.                 f.setSize(300, 300);
  48.                 f.setVisible(true);
  49.                
  50.                 b1.addActionListener(this);
  51.                 b2.addActionListener(this);
  52.                 //b3.addActionListener(this);
  53.                // b4.addActionListener(this);
  54.         }
  55.      
  56.         @Override
  57.         public void actionPerformed(ActionEvent e) {
  58.                // w1 = Double.parseDouble(t1.getText());
  59.            //     w2 = Double.parseDouble(t2.getText());
  60.                    
  61.                
  62.             if(e.getSource()==b1)
  63.             {   b2.setLocation(r.nextInt(200),r.nextInt(101));
  64.                 //b3.setLocation(200,200 );
  65.                 //b4.setLocation(150,100 );
  66.             //  b5.setLocation(200,100 );
  67.             //  b6.setLocation(100,150 );
  68.             //  b7.setLocation(100,200 );
  69.             //  b8.setLocation(150,150 );
  70.             //  b9.setLocation(150,200 );
  71.                  
  72.                
  73.                
  74.             }
  75.            
  76.              
  77.         }
  78.        
  79.         public static void main(String[] args) {
  80.                 puzzle o1 = new puzzle();
  81.         }
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement