Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import java.util.Random;
- import javax.swing.*;
- public class puzzle implements ActionListener {
- Random r ;
- JButton b1, b2, b3, b4,b5,b6,b7,b8,b9;
- JLabel l1;
- double w1, w2, wyn;
- JPanel p;
- public puzzle() {
- r=new Random();
- JFrame f = new JFrame();
- p = new JPanel();
- l1=new JLabel();
- // przycisk.setLocation(przycisk.getX()+ 5, przycisk.getY() +5); zmiana polozenia;
- b1 = new JButton("losuj");
- b2 = new JButton("1");
- b3 = new JButton("2");
- b4 = new JButton("3");
- b5 = new JButton("4");
- b6 = new JButton("5");
- b7 = new JButton("6");
- b8 = new JButton("7");
- b9 = new JButton("8");
- f.add(p);
- p.add(b1);
- p.add(b2);
- p.add(b3);
- p.add(b4);
- p.add(b5);
- p.add(b6);
- p.add(b7);
- p.add(b8);
- p.add(b9);
- f.setSize(300, 300);
- f.setVisible(true);
- b1.addActionListener(this);
- b2.addActionListener(this);
- //b3.addActionListener(this);
- // b4.addActionListener(this);
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- // w1 = Double.parseDouble(t1.getText());
- // w2 = Double.parseDouble(t2.getText());
- if(e.getSource()==b1)
- { b2.setLocation(r.nextInt(200),r.nextInt(101));
- //b3.setLocation(200,200 );
- //b4.setLocation(150,100 );
- // b5.setLocation(200,100 );
- // b6.setLocation(100,150 );
- // b7.setLocation(100,200 );
- // b8.setLocation(150,150 );
- // b9.setLocation(150,200 );
- }
- }
- public static void main(String[] args) {
- puzzle o1 = new puzzle();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement