Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Sean Luava
- * 4/24/17
- */
- import javax.swing.*;
- import java.awt.*;
- public class Keypads
- {
- private ImageIcon symbolList = new ImageIcon("SLIST.jpg");
- private JLabel label = new JLabel();
- private JFrame f1 = new JFrame();
- private int[][] slist =
- {
- {1, 2, 3, 4, 5, 6, 7},
- {8, 1, 7, 9, 10, 6, 11},
- {12, 13, 9, 14, 15, 3, 10},
- {16, 17, 18, 5, 14, 11, 19},
- {20, 19, 18, 21, 17, 22, 23},
- {16, 8, 24, 25, 20, 26, 27}
- };
- public Keypads()
- {
- label.setIcon(symbolList);
- f1.setLayout(new BorderLayout());
- f1.add(label);
- f1.pack();
- }
- public void run()
- {
- f1.setVisible(true);
- String input = JOptionPane.showInputDialog("Enter all the numbers that matches the symbols you have (spaces):");
- f1.setVisible(false);
- String[] convert = input.split(" ");
- int[] symbols = new int[convert.length];
- for(int aa = 0; aa < convert.length; aa++)
- {
- symbols[aa] = Integer.parseInt(convert[aa]);
- }
- symbols = order(symbols);
- String[] images = getImages(symbols);
- ImageIcon i1 = new ImageIcon(images[0]);
- ImageIcon i2 = new ImageIcon(images[1]);
- ImageIcon i3 = new ImageIcon(images[2]);
- ImageIcon i4 = new ImageIcon(images[3]);
- JLabel l1 = new JLabel();
- JLabel l2 = new JLabel();
- JLabel l3 = new JLabel();
- JLabel l4 = new JLabel();
- l1.setIcon(i1);
- l2.setIcon(i2);
- l3.setIcon(i3);
- l4.setIcon(i4);
- JFrame f2 = new JFrame();
- f2.setLayout(new GridLayout(1, 4));
- f2.add(l1);
- f2.add(l2);
- f2.add(l3);
- f2.add(l4);
- f2.pack();
- f2.setVisible(true);
- JOptionPane.showMessageDialog(null, "Press the symbols in this order:");
- f2.setVisible(false);
- }
- private int[] order(int[] s)
- {
- int[] order = new int[s.length];
- int row = 100;
- int best = 0;
- for(int aa = 0; aa < 6; aa++)
- {
- for(int bb = 0; bb < 7; bb++)
- {
- for(int cc = 0; cc < 4; cc++)
- {
- if(slist[aa][bb] == s[cc])
- {
- best++;
- }
- }
- }
- if(best == 4)
- {
- row = aa;
- break;
- }
- best = 0;
- }
- int items = 0;
- for(int dd = 0; dd < 7; dd++)
- {
- for(int ee = 0; ee < 4; ee++)
- {
- if(slist[row][dd] == s[ee])
- {
- order[items] = s[ee];
- items++;
- }
- }
- }
- return order;
- }
- private String[] getImages(int[] s)
- {
- String[] ima = new String[4];
- for(int aa = 0; aa < 4; aa++)
- {
- switch(s[aa])
- {
- case 1:
- ima[aa] = "S1.jpg";
- break;
- case 2:
- ima[aa] = "S2.jpg";
- break;
- case 3:
- ima[aa] = "S3.jpg";
- break;
- case 4:
- ima[aa] = "S4.jpg";
- break;
- case 5:
- ima[aa] = "S5.jpg";
- break;
- case 6:
- ima[aa] = "S6.jpg";
- break;
- case 7:
- ima[aa] = "S7.jpg";
- break;
- case 8:
- ima[aa] = "S8.jpg";
- break;
- case 9:
- ima[aa] = "S9.jpg";
- break;
- case 10:
- ima[aa] = "S10.jpg";
- break;
- case 11:
- ima[aa] = "S11.jpg";
- break;
- case 12:
- ima[aa] = "S12.jpg";
- break;
- case 13:
- ima[aa] = "S13.jpg";
- break;
- case 14:
- ima[aa] = "S14.jpg";
- break;
- case 15:
- ima[aa] = "S15.jpg";
- break;
- case 16:
- ima[aa] = "S16.jpg";
- break;
- case 17:
- ima[aa] = "S17.jpg";
- break;
- case 18:
- ima[aa] = "S18.jpg";
- break;
- case 19:
- ima[aa] = "S19.jpg";
- break;
- case 20:
- ima[aa] = "S20.jpg";
- break;
- case 21:
- ima[aa] = "S21.jpg";
- break;
- case 22:
- ima[aa] = "S22.jpg";
- break;
- case 23:
- ima[aa] = "S23.jpg";
- break;
- case 24:
- ima[aa] = "S24.jpg";
- break;
- case 25:
- ima[aa] = "S25.jpg";
- break;
- case 26:
- ima[aa] = "S26.jpg";
- break;
- case 27:
- ima[aa] = "S27.jpg";
- break;
- }
- }
- return ima;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement