【急】有没有朋友用java写过单机版的别踩白块,急求源码! 30
1个回答
2015-05-13
展开全部
package 别踩白块;
import java.awt.GridLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
public class Main extends JFrame implements MouseListener {
Block[] block=new Block[9];
Block1 block1=new Block1();
public Main(){
setTitle("别踩白块");
setBounds(200,300,200,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridLayout(3,3,5,5));
addblock();
bk();
this.setVisible(true);
}
public void addblock(){
for(int i=0;i<9;i++)
{
block[i]=new Block();
add(block[i]);
}
}
public void bk(){
block1.setbk1(block[(int)(Math.random()*2)]);
block1.setbk1(block[(int)(Math.random()*2+4)]);
block1.setbk1(block[(int)(Math.random()*2+6)]);
}
public void over(){
block[3].setText("g");
block[4].setText("g");
block[5].setText("!");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new Main();
}
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
if(e.getSource().equals(""));
over();
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
}
Block
package 别踩白块;
import java.awt.Color;
import javax.swing.*;
@SuppressWarnings("serial")
public class Block extends JLabel{
public Block(){
setText("");
setOpaque(true);
setBackground(Color.white);
}
public void setbk(){
setBackground(Color.black);
}
}
block1
package 别踩白块;
public class Block1 {
Block a=new Block();
public void setbk1(Block a){
a.setbk();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询