|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
进而能拉拢大多数程序员用windows产品。并且从net网页编程网页编程AJAX可以跨平台这一点上,间接证明了我们的推断,至少证明了微软做过这方面的研究。所以如果哪一天突然听说了.net网页编程可以跨平台了,那么请不要吃惊,如果这一天真的到来,java就到了真正和.net网页编程决战的时刻。因为不到万不得以的时候微软是不会推出跨平台的.net网页编程的,如果跨平台的.net网页编程还不足以对抗java的话,那么微软还剩的手段就是开源了,呵呵。
//以下代码在JDK1.4下经由过程
//编译:javacMyPanel.java
//运转:javaMyPanel
//MadeByQiukai
//注重:启动后,在窗口中点鼠标反键选择入手下手游戏举行
importjava.awt.*;
importjava.awt.event.*;
importjava.util.*;
importjavax.swing.*;
publicclassMyPanelextendsJFrame
{
publicintFPS;
publicThreadnewthread;
publicstaticbooleanswit;
MouseListenerml=newC();
KeyListenerkl=newD();
JPopupMenujmp;
JMenuItemjmi;
lettermyletter;
Randomr;
intisTypedSum;
intisOmittedSum;
intisWrongTypedSum;
intwidth,height;
floatpercent;
ToolkitKT;
publicstaticvoidmain(Stringargs[])
{
newMyPanel();
}
publicMyPanel()
{
KT=this.getToolkit();
width=KT.getScreenSize().width;
height=KT.getScreenSize().height;
this.setSize(newDimension(width,height));
this.setContentPane(newA());
this.show();
FPS=100;
isTypedSum=isOmittedSum=isWrongTypedSum=0;
percent=0f;
r=newRandom();
}
classAextendsJPanelimplementsRunnable
{
publicA()
{
this.setBackground(Color.pink);
addComponents();
sta();
}
publicvoidsta()
{
newthread=newThread(this);
newthread.start();
myletter=newletter(MyPanel.this);
myletter.randomLetters();
}
publicvoidrun()
{
while(newthread!=null)
{
this.repaint();
try
{
Thread.sleep(FPS);
}catch(InterruptedExceptione)
{
System.out.println(e.toString());
}
}
}
publicvoidaddComponents()
{
MyPanel.this.addKeyListener(kl);
jmp=newJPopupMenu();
jmi=newJMenuItem("入手下手游戏");
jmi.addActionListener(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
isTypedSum=isOmittedSum=isWrongTypedSum=0;
swit=true;
sta();
}
});
jmp.add(jmi);
jmi=newJMenuItem("停止游戏");
jmi.addActionListener(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
stop();
swit=false;
}
});
jmp.add(jmi);
jmp.addSeparator();
jmi=newJMenuItem("增添字母数字");
jmi.addActionListener(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
if(myletter.exist_letter_num==9);
else
myletter.exist_letter_num++;
myletter.randomLetters();
}
});
jmp.add(jmi);
jmi=newJMenuItem("加速下跌速率");
jmi.addActionListener(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
for(inti=0;i<myletter.exist_letter_num;i++)
myletter.speed[i]++;
}
});
jmp.add(jmi);
jmp.addSeparator();
jmi=newJMenuItem("削减字母数字");
jmi.addActionListener(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
if(myletter.exist_letter_num==1);
else
myletter.exist_letter_num--;
myletter.randomLetters();
}
});
jmp.add(jmi);
jmi=newJMenuItem("减缓下跌速率");
jmi.addActionListener(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
for(inti=0;i<myletter.exist_letter_num;i++)
{
if(myletter.speed[i]>1)
myletter.speed[i]--;
}
}
});
jmp.add(jmi);
MyPanel.this.addMouseListener(ml);
}
publicvoidpaintComponent(Graphicsg)
{
super.paintComponent(g);
intsum;
intshowPercent=0;
if(swit)
{
myletter.paintLetters(g);
sum=isTypedSum+isWrongTypedSum+isOmittedSum;
if(sum==0){percent=0f;showPercent=0;}
else
{
percent=(float)isTypedSum/sum;
showPercent=(int)(percent*100);
}
g.drawString("击中"+isTypedSum+"错击"+isWrongTypedSum+"遗漏"+isOmittedSum+"准确率"+showPercent+"%",200,200);
}
else
{
g.drawString("击中"+isTypedSum+"错击"+isWrongTypedSum+"遗漏"+isOmittedSum+"准确率"+showPercent+"%",200,200);
}
}
}
classCextendsMouseAdapter
{
publicvoidmousePressed(MouseEvente)
{
showPopup(e);
}
publicvoidmouseReleased(MouseEvente)
{
showPopup(e);
}
publicvoidshowPopup(MouseEvente)
{
if(e.isPopupTrigger())
jmp.show(e.getComponent(),e.getX(),e.getY());
}
}
classDextendsKeyAdapter
{
publicvoidkeyPressed(KeyEvente)
{
charkey=e.getKeyChar();
if(isTyped(key))
{
}
else
{
}
}
publicbooleanisTyped(charkey)
{
for(inti=0;i<myletter.exist_letter_num;i++)
{
if((char)(key-32)==myletter.cc[i].charAt(0))
{
isTypedSum++;
myletter.reStart(i);
returntrue;
}
}
isWrongTypedSum++;
returnfalse;
}
}
publicvoidstop()
{
newthread=null;
}
}
classletter
{
MyPanelgame;
finalintMax;
booleanlet[];
intX[];
intY[];
intspeed[];
intexist_letter_num;
intXY[];
intini;
StringBufferc[];
Stringcc[];
Randomran=newRandom();
Colormycolor[]={Color.red,Color.green};
intaa[];
publicletter(MyPanelgame)
{
Max=9;//将字母最多设置为9个。此数为不成改动的。
this.game=game;
let=newboolean[Max];
XY=newint[Max];
ini=50;
initArray();
exist_letter_num=3;//初始化,刚入手下手落下字母的个数。
}
publicvoidinitArray()
{
for(inti=0;i<Max;i++)
{
let[i]=false;
XY[i]=ini;
ini+=70;
}
}
publicvoidrandomLetters()//随机发生n个分歧数字的值。
{
X=newint[exist_letter_num];
Y=newint[exist_letter_num];
speed=newint[exist_letter_num];
aa=newint[100];
for(inti=0,n=0;i<exist_letter_num;i++)//经由过程9个分歧的地位来随机发生字母呈现的坐标地位。
{
aa[n]=ran.nextInt(9);
if(i!=0)
{
while(check(aa,n))
{
aa[n]=ran.nextInt(9);
}
}
X[i]=XY[aa[n]];
Y[i]=ran.nextInt(11)-10;
speed[i]=ran.nextInt(8)+1;
let[aa[n]]=true;//保留下放字母的地位。
n++;
}
randomStrings();
}
publicvoidrandomStrings()
{
c=newStringBuffer[exist_letter_num];
cc=newString[exist_letter_num];
while(true)
{
for(inti=0;i<exist_letter_num;i++)
{
c[i]=newStringBuffer();
cc[i]=newString();
c[i].setLength(1);
c[i].setCharAt(0,(char)(ran.nextInt(26)+65));
cc[i]=""+c[i];
}
if(checkChar(c))
break;
}
}
publicbooleancheckChar(StringBufferc[])
{
if(exist_letter_num==1)returntrue;
for(inti=0;i<exist_letter_num-1;i++)
for(intj=i+1;j<exist_letter_num;j++)
{
if(c[i].equals(c[j]))returnfalse;
}
returntrue;
}
publicbooleancheck(intaa[],intn)
{
for(inti=0;i<n;i++)
for(intj=i+1;j<=n;j++)
{
if(aa[i]==aa[j])returntrue;
}
returnfalse;
}
publicvoidpaintLetters(Graphicsg)
{
for(inttemp=0;temp<exist_letter_num;temp++)
{
g.setColor(mycolor[ran.nextInt(2)]);
g.fill3DRect(X[temp],Y[temp],20,20,true);
g.setColor(Color.blue);
g.drawString(cc[temp],X[temp]+5,Y[temp]+15);
Y[temp]+=speed[temp];
if(Y[temp]>game.height)//当字母消散后,从头给初始地位和速率。
{
game.isOmittedSum++;
reStart(temp);
}
}
}
publicvoidreStart(inttemp)
{
Y[temp]=ran.nextInt(11)-10;
speed[temp]=ran.nextInt(8)+1;
reStartX(temp);
reStartStr(temp);
}
publicvoidreStartX(inttemp)
{
intcause;
Label:while(true)
{
cause=ran.nextInt(9);
for(inti=0;(i<exist_letter_num)&(i!=temp);i++)
{
if(cause==aa[i])
continueLabel;
}
break;
}
X[temp]=XY[cause];
aa[temp]=cause;
}
publicvoidreStartStr(inttemp)
{
StringBuffersb;
Strings;
Label2:while(true)
{
sb=newStringBuffer();
sb.setLength(1);
s="";
sb.setCharAt(0,(char)(ran.nextInt(26)+65));
s+=sb;
for(inti=0;i<exist_letter_num&i!=temp;i++)
{
if(s.equals(cc[i]))
continueLabel2;
}
break;
}
cc[temp]=s;
}
}
从一个编程语言的普及程度来将,一个好的IDE是至关中要的,而现在的java的IDE虽然已经很好了,但是和.net网页编程比起来还是稍微差一些的,这是个客观事实。java要想普及的更好。DE是必须加以改进的。 |
|