请问怎么解决剩下的问题

cjj929178101 2012-10-15 10:06:09
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();




}


}




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






...全文
86 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
long95wang 2012-10-26
  • 打赏
  • 举报
回复
lz,你能说下你要做什么的东西?具体在哪出现问题,建议lz写代码的时候能把注释写的详细点,这样方便别人阅读,方法变量名称尽量能起的见名知意点,如:aaa()就不是太好了。

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧