import java.awt.Component;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
 public class aaa extends JFrame{

  static String A[][] = new String[4][13];
  static int B[] = new int[13];
  static String C[][] = new String[1][13];
 
  static JButton D[] = new JButton[13];
 
  static boolean[] bool = new boolean[52];
  int X = 88;
  static boolean flagcode = false;

  ImagePanel panel;
  JButton jbtn;
  JButton btn;
  ImageIcon ii;
 
  static boolean flag[] = new boolean[13];
 
 
 
  //构造函数 随机数还有窗口界面都在此产生
  aaa(){
 
  for(int i = 0; i<4; i++)
for(int j = 0; j<13; j++){
switch(i){
case 0:
A[i][j]="/fang"+Integer.toString(j+1)+".jpg";//System.out.println(A[i][j]);
break;
case 1:
A[i][j]="/hong"+Integer.toString(j+1)+".jpg";//System.out.println(A[i][j]);
break;
case 2:
A[i][j]="/mei"+Integer.toString(j+1)+".jpg";//System.out.println(A[i][j]);
break;
case 3:
A[i][j]="/hei"+Integer.toString(j+1)+".jpg";//System.out.println(A[i][j]);
break;
}
}

//产生随机数

for(int i = 0; i<=12; i++){
int repeat = 0;

do{
repeat = (int)( Math.random()*52);

B[i] = repeat;



}while(bool[repeat]);

//System.out.print(B[i]+" ");
bool[repeat] = true; }


//sort
for(int i = 0; i<12; i++){
int temp;
for(int j=0; j<12-i; j++){
if(B[j]>B[j+1]){
temp = B[j];
B[j] = B[j+1];
B[j+1] = temp;
}
} }
/* for(int i =0; i<=12; i++){
System.out.print(B[i]+"  ");
}
*/



for(int j =0; j<13; j++){


C[0][j]= A[B[j]/13][B[j]%13];
if(B[j]==4){
B[j]=3;}

}
for(int i = 0; i<1; i++)
for(int j =0; j<13; j++){
System.out.println(C[i][j]);

}
 
 
 
 
 
  add(new ImagePanel());
   panel = new ImagePanel();
 
 
  for(int i=0; i<13; i++){
  ii = new ImageIcon("src/"+C[0][i]);
  jbtn = new JButton(ii);
 
 
  D[i] = jbtn;
//System.out.print(D[i]);  

 

 
  D[i].setBounds(50+X*i, 500, ii.getIconWidth(),ii.getIconHeight());
  panel.add(D[i]);
  D[i].addActionListener(new Monitor());
 
  }
  /*
  ImageIcon ii = new ImageIcon("src/1.jpg");
  JButton jbtn = new JButton(ii);
  jbtn.setBounds(50, 400, ii.getIconWidth(), ii.getIconHeight());
  panel.add(jbtn);
  */
 
 
  add(panel);
 
  this.setTitle("cjj PokerGame");
  this.setSize(getToolkit().getScreenSize().width,getToolkit().getScreenSize().height);
  this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  this.validate();
  this.setResizable(false);
  this.setVisible(true);
 
  }
     
 
 
  //画牌桌
   public class ImagePanel extends JLayeredPane{   private ImageIcon imageIcon = new ImageIcon("src/PokerTable.jpg");
    private Image image = imageIcon.getImage();  
   
   
 
   
   
   
    public void paintComponent(Graphics g){
    super.paintComponent(g);
   
    if(image != null){
    g.drawImage(image, 0, 0,getWidth(),getHeight(), this);
    }
    }
   }    
 
  class Monitor implements  ActionListener{
    @Override
  public void actionPerformed(ActionEvent e) {
System.out.println("检查事件驱动是否成功");



 for(int i = 0; i<=12; i++){
if(e.getSource()==D[i]){
if(false == flag[i]){
D[i].setBounds(D[i].getX(), D[i].getY()-40, ii.getIconWidth(), ii.getIconHeight());
flag[i] = true;

 btn = new JButton("出牌");
   btn.setBounds(1200,350 , 80, 50);
   panel.add(btn);
   
 
}
else{
D[i].setBounds(D[i].getX(), D[i].getY()+40, ii.getIconWidth(), ii.getIconHeight());
flag[i] = false;
btn.setVisible(false);
 
}
 
 

}


 
 


/* for( i = 0; i<=12; i++){
 if(btn==null){
   btn = new JButton("出牌");
   btn.setBounds(1200,350 , 80, 50);
   panel.add(btn);
   }
 else{
 
 }
 btn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {

if(e.getSource() == btn)
.setBounds(200, 200, ii.getIconWidth(), ii.getIconHeight());

D[1].setBounds(200, 200, ii.getIconWidth(), ii.getIconHeight());

D[2].setBounds(200, 200, ii.getIconWidth(), ii.getIconHeight());
}

 });
}
*/




 
  }
   
   
   
    }
 
  public class Monitor2 implements ActionListener{
public void actionPerformed(ActionEvent e) {
// if(flag[i] == true){

}
}
 
 
 
   //入口函数
  public static void main(String[] args) {   aaa pg = new aaa();

 

 
  }
   
   
 }
 
 
 
 
 怎样选中一个组件 其他组件不起作用  怎样用“出牌”组件控制其他的牌