|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
IDE是好。java中的IDE更是百花齐放,你用jbuilder能说jbuilder赶不上vs吗?用eclipse,netbeans也很舒服啊。我就不明白“稍微差一些”那一些是从哪里差来的。程序自界说JButton子类:
//ExtendButton.java
packagely.java;
importjava.awt.*;
importjava.awt.event.*;
importjavax.swing.*;
publicclassExtendButtonextendsJButton
{
privateintButton_Pos;
privatebooleanButton_Status;
privatebooleanButton_Visited;
publicintSetPostion(intpos)
{
this.Button_Pos=(pos>=0&&pos<=81)?pos:0;
returnthis.Button_Pos;
}
publicintGetPostion()
{
returnthis.Button_Pos;
}
publicbooleanSetStatus(booleansta)
{
this.Button_Status=sta;
returnthis.Button_Status;
}
publicbooleanGetStatus()
{
returnthis.Button_Status;
}
publicbooleanVisited()
{
returnthis.Button_Visited;
}
publicbooleanSetVisited(booleanvis)
{
this.Button_Visited=vis;
returnthis.Button_Visited;
}
}
游戏类
//Game.java
packagely.java.game;
importjava.awt.*;
importjava.awt.event.*;
importjavax.swing.*;
importly.java.ExtendButton;
publicclassGameextendsJFrameimplementsActionListener{
privateContainermyContainer;
privateGridLayoutmyLayout;
ExtendButton[]myButton=newExtendButton[81];
privateGame()
{
this.setTitle("Game");
this.setSize(500,500);
this.InitButton();
}
privatevoidInitButton()
{
myContainer=getContentPane();
myLayout=newGridLayout(9,9,1,1);
myContainer.setLayout(myLayout);
for(inti=0;i<81;i++)
{
myButton[i]=newExtendButton();
myButton[i].SetPostion(i);
myContainer.add(myButton[i]);
myButton[i].addActionListener(this);
}
System.gc();
this.SetBomb(13);
show();
}
privatevoidSetBomb(intcount)
{
intcounter=0;
inttempint;
while(counter!=count)
{
tempint=(int)(Math.random()*81);
if(!myButton[tempint].GetStatus())
{
myButton[tempint].SetStatus(true);
counter++;
}
}
}
privatevoidShowBomb()
{
for(inti=0;i<81;i++)
{
if(myButton[i].GetStatus())
{
myButton[i].setBackground(newColor(0,0,0));
}
}
}
privatevoidCheckButton(ExtendButtonTempButton)
{
if(TempButton.GetStatus())
{
JOptionPane.showMessageDialog(null,"YouFailed!","Game",JOptionPane.INFORMATION_MESSAGE);
this.ShowBomb();
return;
}
int[]CircleNum=newint[8];
inttemp=0;
if(!TempButton.Visited())
{
CircleNum[0]=TempButton.GetPostion()-9;
CircleNum[0]=(CircleNum[0]<0)?-1:CircleNum[0];
CircleNum[1]=TempButton.GetPostion()-8;
CircleNum[1]=(CircleNum[1]<0||CircleNum[1]%9==0)?-1:CircleNum[1];
CircleNum[2]=TempButton.GetPostion()+1;
CircleNum[2]=(CircleNum[2]%9==0)?-1:CircleNum[2];
CircleNum[3]=TempButton.GetPostion()+10;
CircleNum[3]=(CircleNum[3]>80||CircleNum[3]%9==0)?-1:CircleNum[3];
CircleNum[4]=TempButton.GetPostion()+9;
CircleNum[4]=(CircleNum[4]>80)?-1:CircleNum[4];
CircleNum[5]=TempButton.GetPostion()+8;
CircleNum[5]=(CircleNum[5]>80||CircleNum[5]%8==0)?-1:CircleNum[5];
CircleNum[6]=TempButton.GetPostion()-1;
CircleNum[6]=(CircleNum[6]%8==0)?-1:CircleNum[6];
CircleNum[7]=TempButton.GetPostion()-10;
CircleNum[7]=(CircleNum[7]<0||CircleNum[7]%8==0)?-1:CircleNum[7];
for(inti=0;i<8;i++)
{
if(CircleNum[i]!=-1)
{
if(myButton[CircleNum[i]].GetStatus()&&!myButton[CircleNum[i]].Visited())temp++;
}
}
if(temp>0)
{
TempButton.SetVisited(true);
TempButton.setText(String.valueOf(temp));
temp=0;
}
elseif(temp==0)
{
TempButton.SetVisited(true);
TempButton.setBackground(newColor(125,152,0));
for(inti=0;i<8;i++)
{
if(CircleNum[i]!=-1&&!myButton[CircleNum[i]].Visited())
{
CheckButton(myButton[CircleNum[i]]);
}
}
}
}
}
publicvoidactionPerformed(ActionEvente)
{
CheckButton((ExtendButton)e.getSource());
}
publicstaticvoidmain(String[]args)
{
GamenewGame=newGame();
newGame.addWindowListener(
newWindowAdapter(){
publicvoidwindowClosing(WindowEvente)
{
System.exit(0);
}
}
);
}
}
windows系统样,他们做了什么事或者留了一些后门程序,谁都不知道,二,java开发是跨平台,任何系统上都可以运行,对于保密型系统和大型系统开发这是必要的 |
|