Menu
  • HOME
  • TAGS

(Java)How to change picture(War Card Game)

Tag: java,swing,user-interface,war,playing-cards

Ok what im trying to do is make a image called hidden and it will be a card face down. Now I want to make it so the image will change to a face up card and what i tried to do was make a image for six cards three for each team. "p1, p2, p3" and "o1, o2, o3" those are the names I gave the cards face down and i want the hidden JLabel to change or equal those and then change to a face up card I only put this part of the code because i thought thats all you need but if you need to see more of the code i can put it here. Any help would be appreciated.

public class Cards {

static int[] fullDeck = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
    15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 52, 51, 50, 49, 48,
    47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31,
    30, 29, 28, 27, };
static int oDeck;
static int pDeck;
static int pTurn;
static int oTurn;

private JFrame frame;

/**
 * Launch the application.
 */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                Cards window = new Cards();
                window.frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the application.
 */
public Cards() {
    initialize();
}

/**
 * Initialize the contents of the frame.
 */
private void initialize() {
    frame = new JFrame();
    frame.setBounds(100, 100, 450, 300);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(null);
    JLabel hidden = new JLabel("");

    JLabel p1 = new JLabel("New label");
    p1.setBounds(47, 24, 82, 82);
    frame.getContentPane().add(p1);

    JLabel p2 = new JLabel("New label");
    p2.setBounds(139, 24, 82, 82);
    frame.getContentPane().add(p2);

    JLabel p3 = new JLabel("New label");
    p3.setBounds(211, 24, 82, 82);
    frame.getContentPane().add(p3);

    JLabel o1 = new JLabel("New label");
    o1.setBounds(47, 95, 82, 82);
    frame.getContentPane().add(o1);

    JLabel o2 = new JLabel("New label");
    o2.setBounds(139, 95, 82, 82);
    frame.getContentPane().add(o2);

    JLabel o3 = new JLabel("New label");
    o3.setBounds(211, 95, 82, 82);
    frame.getContentPane().add(o3);

    //This creates the players hand and the opponents hand
            ArrayList<Integer> playerDeck = new ArrayList<>();
            ArrayList<Integer> opponentDeck = new ArrayList<>();

            for (int i = 0; i <= fullDeck.length; i++) {
                if (i % 2 == 0) {
                    playerDeck.add(i);
                } else {
                    opponentDeck.add(i);
                }
                Collections.shuffle(playerDeck);
                Collections.shuffle(opponentDeck);

    JButton btnNewButton = new JButton("New button");
    btnNewButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {for (int i = 0; i < 4; i++) {
            /*if (i == 1){
                pDeck = playerDeck.get(1);
             hidden = p1;
            hidden.setBounds(20, 200, 106, 61);
            System.out.println("Check1");
            }
            else if (i == 2){
                pDeck = playerDeck.get(2);
                hidden = p2;
                hidden.setBounds(162, 200, 106, 61);
                System.out.println("Check2");
            }
            else if (i == 3){
                pDeck = playerDeck.get(3);
                hidden = p3;
                System.out.println("Check3");
            }*/
            pDeck = playerDeck.get(1);
             hidden = p1;
            switch (pDeck) {
            case 1:
                Image img = new ImageIcon(this.getClass()
                        .getResource("/bin/1.png")).getImage();
                hidden.setIcon(new ImageIcon(img));
                pTurn = 14;
                break;
            case 2:
                Image img2 = new ImageIcon(this.getClass()
                        .getResource("/bin/2.png")).getImage();
                hidden.setIcon(new ImageIcon(img2));
                pTurn = 14;
                break;
            case 3:
                Image img3 = new ImageIcon(this.getClass()
                        .getResource("/bin/3.png")).getImage();
                hidden.setIcon(new ImageIcon(img3));
                pTurn = 14;
                break;
            case 4:
                Image img4 = new ImageIcon(this.getClass()
                        .getResource("/bin/4.png")).getImage();
                hidden.setIcon(new ImageIcon(img4));
                pTurn = 14;
                break;
            case 5:
                Image img5 = new ImageIcon(this.getClass()
                        .getResource("/bin/5.png")).getImage();
                hidden.setIcon(new ImageIcon(img5));
                pTurn = 13;
                break;
            case 6:
                Image img6 = new ImageIcon(this.getClass()
                        .getResource("/bin/6.png")).getImage();
                hidden.setIcon(new ImageIcon(img6));
                pTurn = 13;
            case 7:
                Image img7 = new ImageIcon(this.getClass()
                        .getResource("/bin/7.png")).getImage();
                hidden.setIcon(new ImageIcon(img7));
                pTurn = 13;
                break;
            case 8:
                Image img8 = new ImageIcon(this.getClass()
                        .getResource("/bin/8.png")).getImage();
                hidden.setIcon(new ImageIcon(img8));
                pTurn = 13;
                break;
            case 9:
                Image img9 = new ImageIcon(this.getClass()
                        .getResource("/bin/9.png")).getImage();
                hidden.setIcon(new ImageIcon(img9));
                pTurn = 12;
                break;
            case 10:
                Image img10 = new ImageIcon(this.getClass()
                        .getResource("/bin/10.png")).getImage();
                hidden.setIcon(new ImageIcon(img10));
                pTurn = 12;
                break;
            case 11:
                Image img11 = new ImageIcon(this.getClass()
                        .getResource("/bin/11.png")).getImage();
                hidden.setIcon(new ImageIcon(img11));
                pTurn = 12;
                break;
            case 12:
                Image img12 = new ImageIcon(this.getClass()
                        .getResource("/bin/12.png")).getImage();
                hidden.setIcon(new ImageIcon(img12));
                pTurn = 12;
                break;
            case 13:
                Image img13 = new ImageIcon(this.getClass()
                        .getResource("/bin/13.png")).getImage();
                hidden.setIcon(new ImageIcon(img13));
                pTurn = 11;
                break;
            case 14:
                Image img14 = new ImageIcon(this.getClass()
                        .getResource("/bin/14.png")).getImage();
                hidden.setIcon(new ImageIcon(img14));
                pTurn = 11;
                break;
            case 15:
                Image img15 = new ImageIcon(this.getClass()
                        .getResource("/bin/15.png")).getImage();
                hidden.setIcon(new ImageIcon(img15));
                pTurn = 11;
                break;
            case 16:
                Image img16 = new ImageIcon(this.getClass()
                        .getResource("/bin/16.png")).getImage();
                hidden.setIcon(new ImageIcon(img16));
                pTurn = 11;
                break;
            case 17:
                Image img17 = new ImageIcon(this.getClass()
                        .getResource("/bin/17.png")).getImage();
                hidden.setIcon(new ImageIcon(img17));
                pTurn = 10;
                break;
            case 18:
                Image img18 = new ImageIcon(this.getClass()
                        .getResource("/bin/18.png")).getImage();
                hidden.setIcon(new ImageIcon(img18));
                pTurn = 10;
                break;
            case 19:
                Image img19 = new ImageIcon(this.getClass()
                        .getResource("/bin/19.png")).getImage();
                hidden.setIcon(new ImageIcon(img19));
                pTurn = 10;
                break;
            case 20:
                Image img20 = new ImageIcon(this.getClass()
                        .getResource("/bin/20.png")).getImage();
                hidden.setIcon(new ImageIcon(img20));
                pTurn = 10;
                break;
            case 21:
                Image img21 = new ImageIcon(this.getClass()
                        .getResource("/bin/21.png")).getImage();
                hidden.setIcon(new ImageIcon(img21));
                pTurn = 9;
                break;
            case 22:
                Image img22 = new ImageIcon(this.getClass()
                        .getResource("/bin/22.png")).getImage();
                hidden.setIcon(new ImageIcon(img22));
                pTurn = 9;
                break;
            case 23:
                Image img23 = new ImageIcon(this.getClass()
                        .getResource("/bin/23.png")).getImage();
                hidden.setIcon(new ImageIcon(img23));
                pTurn = 9;
                break;
            case 24:
                Image img24 = new ImageIcon(this.getClass()
                        .getResource("/bin/24.png")).getImage();
                hidden.setIcon(new ImageIcon(img24));
                pTurn = 9;
                break;
            case 25:
                Image img25 = new ImageIcon(this.getClass()
                        .getResource("/bin/25.png")).getImage();
                hidden.setIcon(new ImageIcon(img25));
                pTurn = 8;
                break;
            case 26:
                Image img26 = new ImageIcon(this.getClass()
                        .getResource("/bin/26.png")).getImage();
                hidden.setIcon(new ImageIcon(img26));
                pTurn = 8;
                break;
            case 27:
                Image img27 = new ImageIcon(this.getClass()
                        .getResource("/bin/27.png")).getImage();
                hidden.setIcon(new ImageIcon(img27));
                pTurn = 8;
                break;
            case 28:
                Image img28 = new ImageIcon(this.getClass()
                        .getResource("/bin/28.png")).getImage();
                hidden.setIcon(new ImageIcon(img28));
                pTurn = 8;
                break;
            case 29:
                Image img29 = new ImageIcon(this.getClass()
                        .getResource("/bin/29.png")).getImage();
                hidden.setIcon(new ImageIcon(img29));
                pTurn = 7;
                break;
            case 30:
                Image img30 = new ImageIcon(this.getClass()
                        .getResource("/bin/30.png")).getImage();
                hidden.setIcon(new ImageIcon(img30));
                pTurn = 7;
                break;
            case 31:
                Image img31 = new ImageIcon(this.getClass()
                        .getResource("/bin/31.png")).getImage();
                hidden.setIcon(new ImageIcon(img31));
                pTurn = 7;
                break;
            case 32:
                Image img32 = new ImageIcon(this.getClass()
                        .getResource("/bin/32.png")).getImage();
                hidden.setIcon(new ImageIcon(img32));
                pTurn = 7;
                break;
            case 33:
                Image img33 = new ImageIcon(this.getClass()
                        .getResource("/bin/33.png")).getImage();
                hidden.setIcon(new ImageIcon(img33));
                pTurn = 6;
                break;
            case 34:
                Image img34 = new ImageIcon(this.getClass()
                        .getResource("/bin/34.png")).getImage();
                hidden.setIcon(new ImageIcon(img34));
                pTurn = 6;
                break;
            case 35:
                Image img35 = new ImageIcon(this.getClass()
                        .getResource("/bin/35.png")).getImage();
                hidden.setIcon(new ImageIcon(img35));
                pTurn = 6;
                break;
            case 36:
                Image img36 = new ImageIcon(this.getClass()
                        .getResource("/bin/36.png")).getImage();
                hidden.setIcon(new ImageIcon(img36));
                pTurn = 6;
                break;
            case 37:
                Image img37 = new ImageIcon(this.getClass()
                        .getResource("/bin/37.png")).getImage();
                hidden.setIcon(new ImageIcon(img37));
                pTurn = 5;
                break;
            case 38:
                Image img38 = new ImageIcon(this.getClass()
                        .getResource("/bin/38.png")).getImage();
                hidden.setIcon(new ImageIcon(img38));
                pTurn = 5;
                break;
            case 39:
                Image img39 = new ImageIcon(this.getClass()
                        .getResource("/bin/39.png")).getImage();
                hidden.setIcon(new ImageIcon(img39));
                pTurn = 5;
                break;
            case 40:
                Image img40 = new ImageIcon(this.getClass()
                        .getResource("/bin/40.png")).getImage();
                hidden.setIcon(new ImageIcon(img40));
                pTurn = 5;
                break;
            case 41:
                Image img41 = new ImageIcon(this.getClass()
                        .getResource("/bin/41.png")).getImage();
                hidden.setIcon(new ImageIcon(img41));
                pTurn = 4;
                break;
            case 42:
                Image img42 = new ImageIcon(this.getClass()
                        .getResource("/bin/42.png")).getImage();
                hidden.setIcon(new ImageIcon(img42));
                pTurn = 4;
                break;
            case 43:
                Image img43 = new ImageIcon(this.getClass()
                        .getResource("/bin/43.png")).getImage();
                hidden.setIcon(new ImageIcon(img43));
                pTurn = 4;
                break;
            case 44:
                Image img44 = new ImageIcon(this.getClass()
                        .getResource("/bin/44.png")).getImage();
                hidden.setIcon(new ImageIcon(img44));
                pTurn = 4;
                break;
            case 45:
                Image img45 = new ImageIcon(this.getClass()
                        .getResource("/bin/45.png")).getImage();
                hidden.setIcon(new ImageIcon(img45));
                pTurn = 3;
                break;
            case 46:
                Image img46 = new ImageIcon(this.getClass()
                        .getResource("/bin/46.png")).getImage();
                hidden.setIcon(new ImageIcon(img46));
                pTurn = 3;
                break;
            case 47:
                Image img47 = new ImageIcon(this.getClass()
                        .getResource("/bin/47.png")).getImage();
                hidden.setIcon(new ImageIcon(img47));
                pTurn = 3;
                break;
            case 48:
                Image img48 = new ImageIcon(this.getClass()
                        .getResource("/bin/48.png")).getImage();
                hidden.setIcon(new ImageIcon(img48));
                pTurn = 3;
                break;
            case 49:
                Image img49 = new ImageIcon(this.getClass()
                        .getResource("/bin/49.png")).getImage();
                hidden.setIcon(new ImageIcon(img49));
                pTurn = 2;
                break;
            case 50:
                Image img50 = new ImageIcon(this.getClass()
                        .getResource("/bin/50.png")).getImage();
                hidden.setIcon(new ImageIcon(img50));
                pTurn = 2;
                break;
            case 51:
                Image img51 = new ImageIcon(this.getClass()
                        .getResource("/bin/51.png")).getImage();
                hidden.setIcon(new ImageIcon(img51));
                pTurn = 2;
                break;
            case 52:
                Image img52 = new ImageIcon(this.getClass()
                        .getResource("/bin/52.png")).getImage();
                hidden.setIcon(new ImageIcon(img52));
                pTurn = 2;
                break;

            default:
            }
            if (i == 1){
                oDeck = opponentDeck.get(1);
                JLabel hidden = o1;
                }
                else if (i == 2){
                    oDeck = opponentDeck.get(2);
                    JLabel hidden = o2;
                }
                else if (i == 3){
                    oDeck = opponentDeck.get(3);
                    JLabel hidden = o3;
                }


            switch (oDeck) {
            case 1:
                Image img = new ImageIcon(this.getClass()
                        .getResource("/bin/1.png")).getImage();
                hidden.setIcon(new ImageIcon(img));
                oTurn = 14;
                break;
            case 2:
                Image img2 = new ImageIcon(this.getClass()
                        .getResource("/bin/2.png")).getImage();
                hidden.setIcon(new ImageIcon(img2));
                oTurn = 14;
                break;
            case 3:
                Image img3 = new ImageIcon(this.getClass()
                        .getResource("/bin/3.png")).getImage();
                hidden.setIcon(new ImageIcon(img3));
                oTurn = 14;
                break;
            case 4:
                Image img4 = new ImageIcon(this.getClass()
                        .getResource("/bin/4.png")).getImage();
                hidden.setIcon(new ImageIcon(img4));
                oTurn = 14;
                break;
            case 5:
                Image img5 = new ImageIcon(this.getClass()
                        .getResource("/bin/5.png")).getImage();
                hidden.setIcon(new ImageIcon(img5));
                oTurn = 13;
                break;
            case 6:
                Image img6 = new ImageIcon(this.getClass()
                        .getResource("/bin/6.png")).getImage();
                hidden.setIcon(new ImageIcon(img6));
                oTurn = 13;
            case 7:
                Image img7 = new ImageIcon(this.getClass()
                        .getResource("/bin/7.png")).getImage();
                hidden.setIcon(new ImageIcon(img7));
                oTurn = 13;
                break;
            case 8:
                Image img8 = new ImageIcon(this.getClass()
                        .getResource("/bin/8.png")).getImage();
                hidden.setIcon(new ImageIcon(img8));
                oTurn = 13;
                break;
            case 9:
                Image img9 = new ImageIcon(this.getClass()
                        .getResource("/bin/9.png")).getImage();
                hidden.setIcon(new ImageIcon(img9));
                oTurn = 12;
                break;
            case 10:
                Image img10 = new ImageIcon(this.getClass()
                        .getResource("/bin/10.png")).getImage();
                hidden.setIcon(new ImageIcon(img10));
                oTurn = 12;
                break;
            case 11:
                Image img11 = new ImageIcon(this.getClass()
                        .getResource("/bin/11.png")).getImage();
                hidden.setIcon(new ImageIcon(img11));
                oTurn = 12;
                break;
            case 12:
                Image img12 = new ImageIcon(this.getClass()
                        .getResource("/bin/12.png")).getImage();
                hidden.setIcon(new ImageIcon(img12));
                oTurn = 12;
                break;
            case 13:
                Image img13 = new ImageIcon(this.getClass()
                        .getResource("/bin/13.png")).getImage();
                hidden.setIcon(new ImageIcon(img13));
                oTurn = 11;
                break;
            case 14:
                Image img14 = new ImageIcon(this.getClass()
                        .getResource("/bin/14.png")).getImage();
                hidden.setIcon(new ImageIcon(img14));
                oTurn = 11;
                break;
            case 15:
                Image img15 = new ImageIcon(this.getClass()
                        .getResource("/bin/15.png")).getImage();
                hidden.setIcon(new ImageIcon(img15));
                oTurn = 11;
                break;
            case 16:
                Image img16 = new ImageIcon(this.getClass()
                        .getResource("/bin/16.png")).getImage();
                hidden.setIcon(new ImageIcon(img16));
                oTurn = 11;
                break;
            case 17:
                Image img17 = new ImageIcon(this.getClass()
                        .getResource("/bin/17.png")).getImage();
                hidden.setIcon(new ImageIcon(img17));
                oTurn = 10;
                break;
            case 18:
                Image img18 = new ImageIcon(this.getClass()
                        .getResource("/bin/18.png")).getImage();
                hidden.setIcon(new ImageIcon(img18));
                oTurn = 10;
                break;
            case 19:
                Image img19 = new ImageIcon(this.getClass()
                        .getResource("/bin/19.png")).getImage();
                hidden.setIcon(new ImageIcon(img19));
                oTurn = 10;
                break;
            case 20:
                Image img20 = new ImageIcon(this.getClass()
                        .getResource("/bin/20.png")).getImage();
                hidden.setIcon(new ImageIcon(img20));
                oTurn = 10;
                break;
            case 21:
                Image img21 = new ImageIcon(this.getClass()
                        .getResource("/bin/21.png")).getImage();
                hidden.setIcon(new ImageIcon(img21));
                oTurn = 9;
                break;
            case 22:
                Image img22 = new ImageIcon(this.getClass()
                        .getResource("/bin/22.png")).getImage();
                hidden.setIcon(new ImageIcon(img22));
                oTurn = 9;
                break;
            case 23:
                Image img23 = new ImageIcon(this.getClass()
                        .getResource("/bin/23.png")).getImage();
                hidden.setIcon(new ImageIcon(img23));
                oTurn = 9;
                break;
            case 24:
                Image img24 = new ImageIcon(this.getClass()
                        .getResource("/bin/24.png")).getImage();
                hidden.setIcon(new ImageIcon(img24));
                oTurn = 9;
                break;
            case 25:
                Image img25 = new ImageIcon(this.getClass()
                        .getResource("/bin/25.png")).getImage();
                hidden.setIcon(new ImageIcon(img25));
                oTurn = 8;
                break;
            case 26:
                Image img26 = new ImageIcon(this.getClass()
                        .getResource("/bin/26.png")).getImage();
                hidden.setIcon(new ImageIcon(img26));
                oTurn = 8;
                break;
            case 27:
                Image img27 = new ImageIcon(this.getClass()
                        .getResource("/bin/27.png")).getImage();
                hidden.setIcon(new ImageIcon(img27));
                oTurn = 8;
                break;
            case 28:
                Image img28 = new ImageIcon(this.getClass()
                        .getResource("/bin/28.png")).getImage();
                hidden.setIcon(new ImageIcon(img28));
                oTurn = 8;
                break;
            case 29:
                Image img29 = new ImageIcon(this.getClass()
                        .getResource("/bin/29.png")).getImage();
                hidden.setIcon(new ImageIcon(img29));
                oTurn = 7;
                break;
            case 30:
                Image img30 = new ImageIcon(this.getClass()
                        .getResource("/bin/30.png")).getImage();
                hidden.setIcon(new ImageIcon(img30));
                oTurn = 7;
                break;
            case 31:
                Image img31 = new ImageIcon(this.getClass()
                        .getResource("/bin/31.png")).getImage();
                hidden.setIcon(new ImageIcon(img31));
                oTurn = 7;
                break;
            case 32:
                Image img32 = new ImageIcon(this.getClass()
                        .getResource("/bin/32.png")).getImage();
                hidden.setIcon(new ImageIcon(img32));
                oTurn = 7;
                break;
            case 33:
                Image img33 = new ImageIcon(this.getClass()
                        .getResource("/bin/33.png")).getImage();
                hidden.setIcon(new ImageIcon(img33));
                oTurn = 6;
                break;
            case 34:
                Image img34 = new ImageIcon(this.getClass()
                        .getResource("/bin/34.png")).getImage();
                hidden.setIcon(new ImageIcon(img34));
                oTurn = 6;
                break;
            case 35:
                Image img35 = new ImageIcon(this.getClass()
                        .getResource("/bin/35.png")).getImage();
                hidden.setIcon(new ImageIcon(img35));
                oTurn = 6;
                break;
            case 36:
                Image img36 = new ImageIcon(this.getClass()
                        .getResource("/bin/36.png")).getImage();
                hidden.setIcon(new ImageIcon(img36));
                oTurn = 6;
                break;
            case 37:
                Image img37 = new ImageIcon(this.getClass()
                        .getResource("/bin/37.png")).getImage();
                hidden.setIcon(new ImageIcon(img37));
                oTurn = 5;
                break;
            case 38:
                Image img38 = new ImageIcon(this.getClass()
                        .getResource("/bin/38.png")).getImage();
                hidden.setIcon(new ImageIcon(img38));
                oTurn = 5;
                break;
            case 39:
                Image img39 = new ImageIcon(this.getClass()
                        .getResource("/bin/39.png")).getImage();
                hidden.setIcon(new ImageIcon(img39));
                oTurn = 5;
                break;
            case 40:
                Image img40 = new ImageIcon(this.getClass()
                        .getResource("/bin/40.png")).getImage();
                hidden.setIcon(new ImageIcon(img40));
                oTurn = 5;
                break;
            case 41:
                Image img41 = new ImageIcon(this.getClass()
                        .getResource("/bin/41.png")).getImage();
                hidden.setIcon(new ImageIcon(img41));
                oTurn = 4;
                break;
            case 42:
                Image img42 = new ImageIcon(this.getClass()
                        .getResource("/bin/42.png")).getImage();
                hidden.setIcon(new ImageIcon(img42));
                oTurn = 4;
                break;
            case 43:
                Image img43 = new ImageIcon(this.getClass()
                        .getResource("/bin/43.png")).getImage();
                hidden.setIcon(new ImageIcon(img43));
                oTurn = 4;
                break;
            case 44:
                Image img44 = new ImageIcon(this.getClass()
                        .getResource("/bin/44.png")).getImage();
                hidden.setIcon(new ImageIcon(img44));
                oTurn = 4;
                break;
            case 45:
                Image img45 = new ImageIcon(this.getClass()
                        .getResource("/bin/45.png")).getImage();
                hidden.setIcon(new ImageIcon(img45));
                oTurn = 3;
                break;
            case 46:
                Image img46 = new ImageIcon(this.getClass()
                        .getResource("/bin/46.png")).getImage();
                hidden.setIcon(new ImageIcon(img46));
                oTurn = 3;
                break;
            case 47:
                Image img47 = new ImageIcon(this.getClass()
                        .getResource("/bin/47.png")).getImage();
                hidden.setIcon(new ImageIcon(img47));
                oTurn = 3;
                break;
            case 48:
                Image img48 = new ImageIcon(this.getClass()
                        .getResource("/bin/48.png")).getImage();
                hidden.setIcon(new ImageIcon(img48));
                oTurn = 3;
                break;
            case 49:
                Image img49 = new ImageIcon(this.getClass()
                        .getResource("/bin/49.png")).getImage();
                hidden.setIcon(new ImageIcon(img49));
                oTurn = 2;
                break;
            case 50:
                Image img50 = new ImageIcon(this.getClass()
                        .getResource("/bin/50.png")).getImage();
                hidden.setIcon(new ImageIcon(img50));
                oTurn = 2;
                break;
            case 51:
                Image img51 = new ImageIcon(this.getClass()
                        .getResource("/bin/51.png")).getImage();
                hidden.setIcon(new ImageIcon(img51));
                oTurn = 2;
                break;
            case 52:
                Image img52 = new ImageIcon(this.getClass()
                        .getResource("/bin/52.png")).getImage();
                hidden.setIcon(new ImageIcon(img52));
                oTurn = 2;
                break;
            default:
            }
        }

        }
    });
    btnNewButton.setBounds(171, 227, 89, 23);
    frame.getContentPane().add(btnNewButton);




}

} }

Best How To :

From your code, I am guessing you have a hidden instance variable declared and in your switch statement, you are adding icon to this JLabel.

But in your if condition, you are not using this hidden variable, but creating a new one.

Fix: Inside your for loop, search for all JLabel hidden strings and replace it just with hidden and see if your problem is solved.

SOAP Client, Following an example

java,soap,saaj

Actually you can generate class with soap ui. And your program can easily call the service using the class created without construct your own request header and body But you need some library. Example java jdk comes with jax-ws lib tutorial: http://www.soapui.org/soap-and-wsdl/soap-code-generation.html...

@RestController throws HTTP Status 406

java,spring,rest,maven

The issue is with the dependencies that you have in pom.xml file. In Spring 4.1.* version the pom.xml dependency for Jackson libraries should include these: <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.4.1</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.4.1.1</version> </dependency> You...

Java dice roll with unexpected random number

java,if-statement

else { System.out.println(diceNumber); } You are printing the address of diceNumber by invoking its default toString() function in your else clause. That is why you are getting the [email protected] The more critical issue is why it gets to the 'else' clause, I believe that is not your intention. Note: In...

error: cannot find symbol class AsyncCallWS Android

java,android,web-services

On the link you post, I see a class like below. Create this class in your project before using it. private class AsyncCallWS extends AsyncTask<String, Void, Void> { @Override protected Void doInBackground(String... params) { Log.i(TAG, "doInBackground"); getFahrenheit(celcius); return null; } @Override protected void onPostExecute(Void result) { Log.i(TAG, "onPostExecute"); tv.setText(fahren +...

BitmapFont class does not have getBound(String) method

java,android,libgdx

After the API 1.5.6 we have a different way to get the String bound. try this GlyphLayout layout = new GlyphLayout(); layout.setText(bitmapFont,"text"); float width = layout.width; float height = layout.height; and it's not recommended to create new GlyphLayout on each frame, create once and use it. ...

Dynamic creation of objects vs storing them as fields

java,performance,object

There won't be any difference, since you've only changed the scope of the variables. Since you're not using the variables outside of the scope, the generated bytecode will be identical as well (you can try it out with javap). So use the second style for clarity. Edit: In fact if...

viewResolver with more folders inside of WEB-INF/jsp is not working in spring

java,spring,jsp,spring-mvc

Say you have a jsp test.jsp under /WEB-INF/jsp/reports From your controller return @RequestMapping("/helloWorld") public String helloWorld(Model model) { model.addAttribute("message", "Hello World!"); return "reports/test"; } ...

Form submit portlet with Spring MVC

java,jsp,spring-mvc,liferay,portlet

Which version of Liferay you are using? if it is > 6.2 GA1 Then in your liferay-portlet.xml file, please add this attribute and recompile and test again. <requires-namespaced-parameters>false</requires-namespaced-parameters> Liferay adds namespace to the request parameters by default. You need to disable it. ...

custom arraylist get distinct

java,android

It's not possible to do this using only the ArrayList. Either implement your own method which can be as simple as: private List<mystatistik> getAllUniqueEnemies(List<mystatistik> list){ List<mystatistik> uniqueList = new ArrayList<mystatistik>(); List<String> enemyIds = new ArrayList<String>(); for (mystatistik entry : list){ if (!enemyIds.contains(entry.getEnemyId())){ enemyIds.add(entry.getEnemyId()); uniqueList.add(entry); } } return uniqueList; } Or...

setOnClickListener error Null object

java,android

After super.onCreate(savedInstanceState); insert setContentView(R.layout.YourLayout); you need to make a request to a server in another thread. It might look like public class LoginTask extends AsyncTask<Void, Void, String>{ private String username; private String password; private Context context; public LoginTask(Context context, String username, String password) { this.username = username; this.password = password;...

Javadoc: Do parameter and return need an explicit type description

java,types,javadoc

No, there's no need, the JavaDoc tool parses the Java code and gets the types from there. This article on the Oracle Java site may be useful: How to Write Doc Comments for the Javadoc Tool From the @param part of that article: The @param tag is followed by the...

Bulkheading strategies for Akka actors

java,asynchronous,akka,blocking,future

If I understand this correctly, you kind of have two options here: you listen to a Future being completed or you do something with the result: If you want to listen, you can use some callback like final ExecutionContext ec = system.dispatcher(); future.onSuccess(new OnSuccess<String>() { public void onSuccess(String result) {...

Iterating over a map and putting its values in java

java,guava

It Should be a loop inside loop for column and row final Table<String, String, List<String>> values = HashBasedTable.create(); values.put("ton bon", "currency", Lists.newArrayList("ccdd","rode1","cwey","Certy")); values.put("ton bon", "racy", Lists.newArrayList("wqadd","werde","ihtr","ytre")); Map<String, List<String>> row = values.row("ton bon"); Map<String, String> fmap = new HashMap<String, String>(); System.out.println("Key\tValue"); for(String columnKey:row.keySet()) { List<String> rowValues =...

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) doesn't work

java,jpa,glassfish,ejb-3.0

deleteEmployee method is not wrapped into a new transaction because you are referencing method on this. What you can do is to inject reference to the facade itself and then call deleteEmployee method on it (it should be public). More or less something like this: @Stateless public class MyFacade {...

WebDriver can't get dropdown menu element (Java)

java,selenium,webdriver,junit4

Your ID is dynamic, so you can't use it. Select will not work in your case, you just need to use two clicks WebElement dropdown = driver.findElement(By.xpath("//div[@class='select-pad-wrapper AttributePlugin']/input")); dropdown.click(); WebElement element = driver.findElement(By.xpath("//div[@class='select-pad-wrapper AttributePlugin']/div/ul/li[text()='Image']")); element.click(); ...

How to do custom rounding of numbers in Java?

java,rounding

Math.floor(x+0.7) should do it. This should work for an arbitrary mantissa. Just add the offset to the next integer to your value and round down. The rounding is done by floor. Here is what the java API says to floor: Returns the largest (closest to positive infinity) double value that...

type conversion if flex

java,actionscript-3,flex

You try to cast data type mx.collections:IList to UI component type spark.components:List, which of course leads to exception. Try to follow the error message hint and use mx.collections:IList: screenList.addAll(event.result as IList); ...

How can implement long running process in spring hibernate?

java,spring,hibernate

I recommend you to use DeferredResult of Spring. It´s a Future implementation, that use the http long poling technique. http://docs.spring.io/spring-framework/docs/3.2.0.BUILD-SNAPSHOT/api/org/springframework/web/context/request/async/DeferredResult.html So let´s says that you will make a request, and the server it will return you the deferredResult, and then your request will keep it open until the internal process(Hibernate)...

Android String if-statement

java,android,string

Correct me if I'm wrong. If you're saying that your code looks like this: new Thread(new Runnable() { public void run() { // thread code if (ready.equals("yes")) { // handler code } // more thread code }).start(); // later on... ready = "yes"; And you're asking why ready = "yes"...

why java API prevents us to call add and remove together?

java,list,collections,listiterator

You're reading the wrong documentation: you should read ListIterator's javadoc. It says: Throws: ... IllegalStateException - if neither next nor previous have been called, or remove or add have been called after the last call to next or previous Now, if you want a reason, it's rather simple. You're playing...

How to check if an ExecutionResult is empty in Neo4j

java,neo4j

An execution result is essentially an iterator of a map, its type definition is something like: Iterable<Map<String,Object>> So you can easily just do: result.iterator().hasNext(); I think that its strictly a ResourceIterator, so if you get an iterator you are supposed to close it if you don't exhaust it. Check the...

Android set clickable text to go one fragment to another fragment

java,android,android-fragments,spannablestring

If LoginActivity is a fragment class then it would be okay is you use setOnClickListener on textview. But for fragment change you have to change Intent to fragmentTransaction, Use something like, textview.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getFragmentManager().beginTransaction().replace(R.id.container, new LoginActivity() ).addToBackStack("").commit(); }); But, if you want to...

Unfortunately, (My app) has stopped. Eclipse Android [duplicate]

java,android,eclipse,adt

In your MainActivity.java at line no 34 you are trying to initialize some widget that is not present in your xml layout which you have set it in your setContentView(R.layout.... That;s why you are geting nullpointerexception. EDIT: change your setContentView(R.layout.activity_main) to setContentView(R.layout.fragment_main)...

Android Implicit Intent for Viewing a Video File

java,android,android-intent,uri,avd

Change your onClick method to below code. You should give the option to choose the external player. @Override public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse("https://youtu.be/jxoG_Y6dvU8"), "video/*"); startActivity(Intent.createChooser(intent, "Complete action using")); } ...

Get network interfaces on remote machine

java,network-programming

No, we cannot by definition. The IP address is needed to hide the mac address from external world. To retrieve it you definitely need some code running on that machine. It means that you need some kind of agent. You can either implement it in Java or use platform specific...

Java Scanner not reading newLine after wrong input in datatype verification while loop

java,while-loop,java.util.scanner

You are reading too much from the scanner! In this line while (sc.nextLine() == "" || sc.nextLine().isEmpty()) you are basically reading a line from the scanner, comparing it (*) with "", then forgetting it, because you read the next line again. So if the first read line really contains the...

Get element starting with letter from List

java,android,list,indexof

The indexOf method doesn't accept a regex pattern. Instead you could do a method like this: public static int indexOfPattern(List<String> list, String regex) { Pattern pattern = Pattern.compile(regex); for (int i = 0; i < list.size(); i++) { String s = list.get(i); if (s != null && pattern.matcher(s).matches()) { return...

Get document on some condition in elastic search java API

java,elasticsearch,elasticsearch-plugin

When indexing documents in this form, Elasticsearch will not be able to parse those strings as dates correctly. In case you transformed those strings to correctly formatted timestamps, the only way you could perform the query you propose is to index those documents in this format { "start": "2010-09", "end":...

Get the min and max value of several items with Comparable

java

You should not let BehaviourItem implement Comparable as it doesn’t have a natural order. Instead, implement different Comparators for the different properties. Note that in Java 8, you can implement such a Comparator simply as Comparator<BehaviourItem> orderBySpeed=Comparator.comparingInt(BehaviourItem::getSpeed); which is the equivalent of Comparator<BehaviourItem> orderBySpeed=new Comparator<BehaviourItem>() { public int compare(BehaviourItem a, BehaviourItem...

How to block writes to standard output in java (System.out.println())

java,logging,stdout

If you can identify the thread you want to "mute" reliably somehow (e.g. by name), you can setOut to your own stream which will only delegate the calls to the actual System.out if they don't come from the muted thread.

App Not Downloading Newest Version Of File [Java]

java,caching,download

Use URLConnection.setUseCaches(boolean);. In your case, it would be connection.setUseCaches(false);...

How to call MySQL view in Struts2 or Hibernate

java,mysql,hibernate,java-ee,struts2

You can simply create an Entity, that's mapping the database view: @Entity public class CustInfo { private String custMobile; private String profession; private String companyName; private Double annualIncome; } Make sure you include an @Id in your view as well, if that's an updatable view. Then you can simply use...

count items in a column vaadin

java,vaadin

Columns don't contain items, Rows contain items. You can set the visible columns by passing a array to the setVisibleColumns methos of the Table. It could also be a idea, to just colapse the column, not hiding it... Determining if all values of this colum are empty should be simple...

how to call Java method which returns any List from R Language? [on hold]

java,r,rjava

You can do it with rJava package. install.packages('rJava') library(rJava) .jinit() jObj=.jnew("JClass") result=.jcall(jObj,"[D","method1") Here, JClass is a Java class that should be in your ClassPath environment variable, method1 is a static method of JClass that returns double[], [D is a JNI notation for a double array. See that blog entry for...

PropertyNotFoundException in jsp

java,jsp

The name of your getter & setter is wrong. By convention it must be: public Integer getSurvey_id() { return survey_id; } public void setSurvey_id(Integer survey_id) { this.survey_id=survey_id; } ...

Getting particular view from expandable listview

java,android,listview,android-fragments,expandablelistview

You shouldn't pass your view item form a fragment to an other. You should retrieve the object associated with your group view, pass this object to your second/edition fragment. You can use setTargetFragment(...) and onActivityResult(...) to send the modified text from your second to your first fragment. And then you...

Numeric literals in Java - octal? [duplicate]

java,literals,octal

-0777 is treated by the compiler as an octal number (base 8) whose decimal value is -511 (-(64*7+8*7+7)). -777 is a decimal number.

Get current latitude and longitude android

java,android,gps,geolocation,location

See my post at http://gabesechansoftware.com/location-tracking/. The code you're using is just broken. It should never be used. The behavior you're seeing is one of the bugs- it doesn't handle the case of getLastLocation returning null, an expected failure. It was written by someone who kind of knew what he was...

Join files using Apache Spark / Spark SQL

java,apache-spark,apache-spark-sql

If you use plain spark you can join two RDDs. let a = RDD<Tuple2<K,T>> let b = RDD<Tuple2<K,S>> RDD<Tuple2<K,Tuple2<S,T>>> c = a.join(b) This produces an RDD of every pair for key K. There are also leftOuterJoin, rightOuterJoin, and fullOuterJoin methods on RDD. So you have to map both datasets to...

Selenium catch popup on close browser

java,selenium,browser

Instead of using driver.quit() to close the browser, closing it using the Actions object may work for you. This is another way to close the browser using the keyboard shortcuts. Actions act = new Actions(driver); act.sendKeys(Keys.chord(Keys.CONTROL+"w")).perform(); Or, if there are multiple tabs opened in driver window: act.sendKeys(Keys.chord(Keys.CONTROL,Keys.SHIFT+"w")).perform(); ...

Exception in thread “main” java.util.InputMismatchException: For input string: “1234567891011”

java

InputMismatchException - if the next token does not match the Integer regular expression, or is out of range. Integer.MIN_VALUE: -2147483648 Integer.MAX_VALUE: 2147483647 Instead of int use long long z = sc.nextLong(); ...

Logging operations in lightadmin

java,spring,logging,lightadmin

You can use the class AbstractRepositoryEventListener like it's show on the LightAdmin documentation here Add you logger insertion by overiding onAfterSave, onAfterCreate and onAfterDelete into your own RepositoryEventListener. After you just need to register your listener like this public class YourAdministration extends AdministrationConfiguration<YourObject> { public EntityMetadataConfigurationUnit configuration(EntityMetadataConfigurationUnitBuilder configurationBuilder) { return...

Reading and modifying the text from the text file in Java

java

I wrote a quick method for you that I think does what you want, i.e. remove all occurrences of a token in a line, where that token is embedded in the line and is identified by a leading dash. The method reads the file and writes it straight out to...

A beginner questions about printf, java

java,string,printf

I'm sad that this question hasn't been answered, and upon that, I can't upvote it from it's -8 cause I don't have enough reputation. It seems downvoting is getting too unwarranted here. OP is just looking for an answer, which can be answered here and found online, he has tried...

Can I install 2 or more Android SDK when using Eclipse

java,android,eclipse,sdk,versions

There shouldn't be any problem if you use the latest SDK version ; actually, this is recommended. However, make sure to set the correct "Target SDK", i.e. the highest android version you have successfully tested your app with, and the "Minimum Required SDK" as well....

Mysterious claim of a missing { in eclipse

java,eclipse

In Java, you cannot write executable statements directly in class.So this is syntactically wrong: for(int i=0; i<10; i++) { this.colorList[i] = this.allColors[this.r.nextInt(this.allColors.length)]; } Executable statements can only be in methods/constructors/code blocks...

Using world coordinates

java,libgdx

You shouldn't use constant a pixel-to-unit conversion, as this would lead to different behavior on different screen sizes/resolutions. Also don't forget about different aspect ratios, you also need to take care about them. The way you should solve this problem is using Viewports. Some of them support virtual screen sizes,...

Interpreting hex dump of java class file

java,class,hex

The 000000b0 is not part of the data. It's the memory address where the following 16 bytes are located. The two-digit hex numbers are the actual data. Read them from left to right. Each row is in two groups of eight, purely to asist in working out memory addresses etc....

Get the value of the last inserted record

java,jdbc

You may try this query: select stop_name from behaviour where created_at in (select max(created_at) from behaviour) ...

Finding embeded xpaths in a String

java,regex

Use {} instead of () because {} are not used in XPath expressions and therefore you will not have confusions.