Facebook
From Beefy Zebra, 4 Years ago, written in Java.
Embed
Download Paste or View Raw
Hits: 151
  1.  
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import javax.swing.*;
  5. import javax.swing.JOptionPane;
  6. public class puzzle2 extends Frame implements ActionListener{
  7.         JButton b1,b2,b3,b4,b5,b6,b7,b8,b9,sample,starB;
  8.         Icon star;
  9.         Icon ic0 = new ImageIcon("pic/startB0.jpg");
  10.         Icon ic10 = new ImageIcon("pic/startB10.jpg");
  11.         Icon ic20 = new ImageIcon("pic/startB20.jpg");
  12.         Icon samicon1 = new ImageIcon("pic/main.jpg");
  13.         Icon samicon2 = new ImageIcon("pic/main2.jpg");
  14.         Icon samicon3 = new ImageIcon("pic/main3.jpg");
  15.        
  16.         Icon ic1 = new ImageIcon("pic/1.jpg");
  17.         Icon ic2 = new ImageIcon("pic/5.jpg");
  18.         Icon ic3 = new ImageIcon("pic/2.jpg");
  19.         Icon ic4 = new ImageIcon("pic/7.jpg");
  20.         Icon ic5 = new ImageIcon("pic/4.jpg");
  21.         Icon ic6 = new ImageIcon("pic/6.jpg");
  22.         Icon ic7 = new ImageIcon("pic/8.jpg");
  23.         Icon ic8 = new ImageIcon("pic/9.jpg");
  24.         Icon ic9 = new ImageIcon("pic/3.jpg");
  25.  
  26.         Icon ic11 = new ImageIcon("pic/12.jpg");
  27.         Icon ic12 = new ImageIcon("pic/13.jpg");
  28.         Icon ic13 = new ImageIcon("pic/16.jpg");
  29.         Icon ic14 = new ImageIcon("pic/11.jpg");
  30.         Icon ic15 = new ImageIcon("pic/14.jpg");
  31.         Icon ic16 = new ImageIcon("pic/19.jpg");
  32.         Icon ic17 = new ImageIcon("pic/17.jpg");
  33.         Icon ic18 = new ImageIcon("pic/15.jpg");
  34.         Icon ic19 = new ImageIcon("pic/18.jpg");
  35.  
  36.         Icon ic21 = new ImageIcon("pic/24.jpg");
  37.         Icon ic22 = new ImageIcon("pic/25.jpg");
  38.         Icon ic23 = new ImageIcon("pic/21.jpg");
  39.         Icon ic24 = new ImageIcon("pic/27.jpg");
  40.         Icon ic25 = new ImageIcon("pic/23.jpg");
  41.         Icon ic26 = new ImageIcon("pic/29.jpg");
  42.         Icon ic27 = new ImageIcon("pic/28.jpg");
  43.         Icon ic28 = new ImageIcon("pic/22.jpg");
  44.         Icon ic29 = new ImageIcon("pic/26.jpg");
  45.  
  46.  
  47.         puzzle2(){
  48.                 super("Pic Puzzle by Zhandos");
  49.                 b1 =new JButton(ic1);
  50.                 b1.setBounds(10,80,100,100);
  51.                 b2 = new JButton(ic2);
  52.                 b2.setBounds(110,80,100,100);
  53.                 b3 = new JButton(ic3);
  54.                 b3.setBounds(210,80,100,100);
  55.                 b4 = new JButton(ic4);
  56.                 b4.setBounds(10,180,100,100);
  57.                 b5 = new JButton(ic5);
  58.                 b5.setBounds(110,180,100,100);
  59.                 b6 = new JButton(ic6);
  60.                 b6.setBounds(210,180,100,100);
  61.                 b7 = new JButton(ic7);
  62.                 b7.setBounds(10,280,100,100);
  63.                 b8 = new JButton(ic8);
  64.                 b8.setBounds(110,280,100,100);
  65.                 b9 = new JButton(ic9);
  66.                 b9.setBounds(210,280,100,100);
  67.                 sample = new JButton(samicon1);
  68.                 sample.setBounds(380,100,200,200);
  69.                 JLabel l1 = new JLabel("Пример:");
  70.                 l1.setBounds(330,200,70,20);
  71.                 JLabel l2 = new JLabel("Заметка: выбери это изображение =>");
  72.                 l2.setBounds(5,15,500,20);
  73.                 JLabel l3 = new JLabel("Нажми для смены изображения!")
  74.                 l3.setBounds(380,320,200,20);
  75.                 l3.setForeground(Color.red);
  76.  
  77.                 starB = new JButton(ic0);
  78.                 starB.setBounds(330,5,50,50);
  79.                 star = b9.getIcon();
  80.  
  81.  
  82.  
  83.            
  84.         }
  85.  
  86.         public void actionPerformed(ActionEvent e){
  87.                 if(e.getSource() == b1){
  88.                         String label = b1.getLabel();
  89.                         if(b2.getLabel().equals("")){
  90.                                 b2.setLabel(label);
  91.                                 b1.setLabel("");
  92.                         }
  93.                         if(b4.getLabel().equals("")){
  94.                                 b4.setLabel(label);
  95.                                 b1.setLabel("");
  96.                         }
  97.  
  98.                 }
  99.                 if(e.getSource() == b2){
  100.                         String label = b2.getLabel();
  101.                         if(b1.getLabel().equals("")){
  102.                                 b1.setLabel(label);
  103.                                 b2.setLabel("");
  104.                         }
  105.                         if(b3.getLabel().equals("")){
  106.                                 b3.setLabel(label);
  107.                                 b2.setLabel("");
  108.                         }
  109.                         if(b5.getLabel().equals("")){
  110.                                 b5.setLabel(label);
  111.                                 b2.setLabel("");
  112.                         }              
  113.                 }
  114.                 if(e.getSource() == b3){
  115.                         String label = b3.getLabel();
  116.                         if(b2.getLabel().equals("")){
  117.                                 b2.setLabel(label);
  118.                                 b3.setLabel("");
  119.                         }
  120.                         if(b6.getLabel().equals("")){
  121.                                 b6.setLabel(label);
  122.                                 b3.setLabel("");
  123.                         }
  124.                 }
  125.                 if(e.getSource() == b4){
  126.                         String label = b4.getLabel();
  127.                         if(b1.getLabel().equals("")){
  128.                                 b1.setLabel(label);
  129.                                 b4.setLabel("");
  130.                         }
  131.                         if(b7.getLabel().equals("")){
  132.                                 b7.setLabel(label);
  133.                                 b4.setLabel("");
  134.                         }
  135.                         if(b5.getLabel().equals("")){
  136.                                 b5.setLabel(label);
  137.                                 b4.setLabel("");
  138.                         }
  139.                 }
  140.                 if(e.getSource() == b5){
  141.                         String label = b5.getLabel();
  142.                         if(b2.getLabel().equals("")){
  143.                                 b2.setLabel(label);
  144.                                 b5.setLabel("");
  145.                         }
  146.                         if(b6.getLabel().equals("")){
  147.                                 b6.setLabel(label);
  148.                                 b5.setLabel("");
  149.                         }
  150.                         if(b4.getLabel().equals("")){
  151.                                 b4.setLabel(label);
  152.                                 b5.setLabel("");
  153.                         }
  154.                         if(b8.getLabel().equals("")){
  155.                                 b8.setLabel(label);
  156.                                 b5.setLabel("");
  157.                         }
  158.                 }
  159.                 if(e.getSource()==b6){  
  160.         String label=b6.getLabel();  
  161.         if(b9.getLabel().equals("")){  
  162.             b9.setLabel(label);  
  163.             b6.setLabel("");  
  164.         }  
  165.         if(b3.getLabel().equals("")){  
  166.             b3.setLabel(label);  
  167.             b6.setLabel("");  
  168.         }  
  169.         if(b5.getLabel().equals("")){  
  170.             b5.setLabel(label);  
  171.             b6.setLabel("");  
  172.         }  
  173.     }  
  174.     if(e.getSource()==b7){  
  175.         String label=b7.getLabel();  
  176.         if(b4.getLabel().equals("")){  
  177.             b4.setLabel(label);  
  178.             b7.setLabel("");  
  179.         }  
  180.         if(b8.getLabel().equals("")){  
  181.             b8.setLabel(label);  
  182.             b7.setLabel("");  
  183.         }  
  184.     }  
  185.     if(e.getSource()==b8){  
  186.         String label=b8.getLabel();  
  187.         if(b9.getLabel().equals("")){  
  188.             b9.setLabel(label);  
  189.             b8.setLabel("");  
  190.         }  
  191.         if(b7.getLabel().equals("")){  
  192.             b7.setLabel(label);  
  193.             b8.setLabel("");  
  194.         }  
  195.         if(b5.getLabel().equals("")){  
  196.             b5.setLabel(label);  
  197.             b8.setLabel("");  
  198.         }  
  199.     }  
  200.     if(e.getSource()==b9){  
  201.         String label=b9.getLabel();  
  202.         if(b6.getLabel().equals("")){  
  203.             b6.setLabel(label);  
  204.             b9.setLabel("");  
  205.         }  
  206.         if(b8.getLabel().equals("")){  
  207.             b8.setLabel(label);  
  208.             b9.setLabel("");  
  209.         }  
  210.     }
  211.     if(b1.getLabel().equals("1")&&b2.getLabel().equals("2")&&b3.getLabel()
  212.         .equals("3")&&b4.getLabel().equals("4")&&b5.getLabel().equals("5")&&b6.getLabel()
  213.         .equals("6")&&b7.getLabel().equals("7")&&b8.getLabel().equals("8")&&b9.getLabel().equals("")){
  214.         JOptionPane.showMessageDialog(this,"Ураа! Ты выиграл!");
  215.     }
  216.  
  217.         }
  218.         public static void main(String[] args) {
  219.                 new Puzzle();
  220.         }
  221.  
  222. }