mardi 26 mai 2015

GUI image display.

This is the code that I made for displaying randome cards, randome card selection working fine but images are not displaying. Only the problem is randome image not displaying. looking for a good solution.

import java.util.Random;
import javax.swing.JFrame;
import java.awt.*;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.imageio.ImageIO;
import javax.swing.JPanel;

public class RandomeCard {

public static void main(String[] args) {

    int CardNumber = 54;
    int i;
    int Num;
    int FirstNum=0;
    int SecNum=0;
    int ThirdNum=0;
    int cnt = 1;
    int numbersNeeded=0;
    int max = 0;

    for(i=1; i<=CardNumber; i++){
      Num = (int)(Math.random()*54)+1;

     if(i==1){
       FirstNum = Num;
       System.out.println("Fist card number "+FirstNum);
     }

     if(i==2){
       SecNum = Num;
       if(FirstNum == SecNum){
           i++;
     } else {
           System.out.println("Second card number "+SecNum);
          }
     }   
     if(i==3){
       ThirdNum = Num;
       if(FirstNum == SecNum){
           i++;
     } else {
       System.out.println("Third card number "+ThirdNum);
     }
    }

 }

    JFrame frame = new JFrame("Random Card Display");
    frame.setSize(300, 200);

 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
 frame.setLocationRelativeTo(null);
 frame.setLayout(new GridLayout(1,3));
 frame.setVisible(true);
 ImageIcon icon = new ImageIcon("card/.png");
 JLabel label = new JLabel(icon);
 frame.add(label);
 frame.add(new jlbl(new icon1("card/"+FirstNum+".png")));
 frame.add(new jlbl(new icon1("card/"+SecNum+".png")));
 frame.add(new jlbl(new icon1("card/"+ThirdNum+".png")));
}

  private static class icon1 {

    public icon1(String string) {
        ImageIcon icon1 = new ImageIcon();
    }
}

private static class jlbl extends PopupMenu {

    public jlbl(icon1 icon1) {
        JLabel jlbl = new JLabel();
    }
}

}




Aucun commentaire:

Enregistrer un commentaire