java游戏源码(打地⿏游戏实现)
图⽚⽂件夹:
eclipse⾥的显⽰截图
源代码:
package use;
import java.awt.Color;
import java.awt.Font;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;jquery setinterval多次执行
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.sound.sampled.LineUnavailableException;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
witchCORBA.PUBLIC_MEMBER;
public class PlayMouse extends JFrame implements Runnable {
private int num=0;
private JLabel back;
private JLabel [] mouses;
private ImageIcon imgMouse;
private JLabel jtf;
java手机游戏下载public PlayMouse(){
this.setResizable(false);//不能够修改⼤⼩
this.setTitle("打地⿏");
this.setBounds(300,100,800,480);
back=new JLabel();
ImageIcon icon=new Class().getResource("5.gif")); back.setIcon(icon);
back.setBounds(0,-35,800,480);
this.DefaultToolkit().DefaultToolkit().getImage("src/com/iotek/mouse/chui.png"), new Point(),"self")
imgMouse=new Class().getResource("4.png"));
mouses=new JLabel[9];
for(int i=0;i<9;i++){
mouses[i]=new JLabel();
mouses[i].IconWidth(),IconHeight());
//mouses[i].setIcon(imgMouse);
mouses[i].addMouseListener(new MouseListener() {
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
@Overridematerial ui
public void mouseExited(MouseEvent e) {
/
/ TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseClicked(MouseEvent e) {
Object Source();
if(object instanceof JLabel){
JLabel label=(JLabel)object;
Icon()!=null){
num++;
mybatis和jpa哪个好用jtf.setText("您的得分是"+num+" 分");//加分功能
}
label.setIcon(null);
}
}
});
}
团购小程序怎么做jtf=new JLabel();
jtf.setBounds(360, 10,230,50);
jtf.setFont(new Font("", 20, 25));
jtf.setForeground(Color.RED);
jtf.setText("您的得分是:分");
mouses[0].setLocation(88,53);
mouses[1].setLocation(240,53);
mouses[2].setLocation(390,53);
mouses[3].setLocation(55,160);
mouses[4].setLocation(245,160);
mouses[5].setLocation(430,160);
mouses[6].setLocation(36,296);
mouses[7].setLocation(230,296);
mouses[8].setLocation(445,296);
this.setVisible(true);
}
public void run(){
while(true){
try {
Thread.sleep(500);
int index=(int)(Math.random()*9);
/
/ double abc=Math.random();
// /******/
// System.out.println(abc);
/******/
if(mouses[index].getIcon()==null){
mouses[index].setIcon(imgMouse);
Thread.sleep(900);//⽼⿏出现的速度,根据反应时间
if(mouses[index].isShowing()){
mouses[index].setIcon(null);
}
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static void main(String [] args){
PlayMouse p1=new PlayMouse();
Thread t1=new Thread(p1);
t1.start();
}
}
由于涉及的东西⽐较多,本⼈有的功能也不太了解,遇到不懂得函数调⽤,百度即可得到完美解答,这是头⼀次亲⾃了解游戏的设计思路及其代码实现,也是头⼀次在java程序中实现了图⽚的插⼊和代码逻辑的结合,,也深刻的了解到了java基础对于以后实战开发的重要性,越来越有趣了
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论