当前位置: 代码迷 >> Java相关 >> 麻烦们帮忙解决下这个,多谢!
  详细解决方案

麻烦们帮忙解决下这个,多谢!

热度:6094   发布时间:2013-02-25 21:49:17.0
麻烦大虾们帮忙解决下这个,谢谢!!
类似俄罗斯方块的,这里只是一小部分,主要是点击“变形”,无法实现。下面是代码
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
import java.awt.*;
import java.awt.event.*;

public class ErsBlockTest extends JFrame
 {
  /**

*/
private static final long serialVersionUID = 1L;

private JButton
btOne = new JButton("一"),
btTwo = new JButton("T"),
btThree = new JButton("Z"),
btFour = new JButton("L"),
btXuanz=new JButton("变形");
  private JPanel jpanel=new JPanel();
  private JPanel jpanel2=new JPanel();
  private int temp;  
  JButton button[][]=new JButton[4][4];
JPanel boxPanel=new JPanel(new GridLayout(4, 4));

private void setTopButton()
{
btOne.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
setButtonBackgroud();
int key = 0x8000;
for (int i = 0; i < button.length; i++) {
for (int j = 0; j < button[i].length; j++) {
if((key & STYLES[0][0])!=0)
{
button[i][j].setBackground(Color.red);
}
key >>= 1;
}
}
repaint();
}
});
btTwo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
setButtonBackgroud();
int key = 0x8000;
for (int i = 0; i < button.length; i++) {
for (int j = 0; j < button[i].length; j++) {
if((key & STYLES[1][0])!=0)
{
button[i][j].setBackground(Color.red);
}
key >>= 1;
}
}
repaint();
}
});
btThree.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
setButtonBackgroud();
int key = 0x8000;
for (int i = 0; i < button.length; i++) {
for (int j = 0; j < button[i].length; j++) {
if((key & STYLES[2][0])!=0)
{
button[i][j].setBackground(Color.red);
}
key >>= 1;
}
}
repaint();
}
});
btFour.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
setButtonBackgroud();
int key = 0x8000;
for (int i = 0; i < button.length; i++) {
for (int j = 0; j < button[i].length; j++) {
if((key & STYLES[3][0])!=0)
{
button[i][j].setBackground(Color.red);
}
key >>= 1;
}
}
repaint();
}
});
jpanel.setLayout(new FlowLayout());
jpanel.add(btOne);  
  jpanel.add(btTwo);
  jpanel.add(btThree);
  jpanel.add(btFour);
}
  private void setMildButton(){
  btXuanz.addActionListener(new ActionListener(){

@Override
public void actionPerformed(ActionEvent ae) {
// TODO Auto-generated method stub
setButtonBackgroud();
int Key=0x8000;
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
if(temp==STYLES[i][j]){
if(j==3){j=0;temp=STYLES[i][j];break;}
else{j++;temp=STYLES[i][j];break;}
}
for(int n=0;n<button.length;n++){
for(int k=0;k<button[n].length;k++){
if((Key & temp)!=0)  
{
button[n][k].setBackground(Color.red);
}
Key>>=1;
}
}
repaint();
}});
  jpanel2.add(btXuanz);
  相关解决方案