Java扫雷如何捕捉右键Button单击事件
整理:yaobaiwang.com 时间:07月19日
[扫雷java源代码是什么]扫雷java源代码是什么,扫雷程序用c语言怎样写:import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Frame extends JFrame { JTextField text;...+阅读
Java扫雷如何捕捉右键Button单击事件
import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import javax.swing.JButton;import javax.swing.JFrame;public class A extends JFrame implements MouseListener { private JButton btn = new JButton("右键点我"); public A() { this.setTitle("test"); this.setSize(300, 200); this.add(btn); btn.addMouseListener(this); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); } public void actionPerformed(ActionEvent e) { } public static void main(String[] args) { new A(); } public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) {//右键点击 btn.setText("H"); } } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { }}...
关于扫雷的Java
你用I/0 把要保存的东西,直接写到*.ini文件中不就可以了吗
这个是我 写 连连看游戏,用来保存记录的,自己参考下,很简单。
import java.awt.Point;
import java.io.*;
import java.util.*;
public class LoadAndSave {
private static final Properties prop=new Properties();
public static File recordFile=new File("record.dat");
public static File setFile=new File("setup.ini");
public static StringBuilder[] setLines;
public static int getRecord(int total) {
int seconds=999999999;
try {
BufferedReader bReader=new BufferedReader(new InputStreamReader(new FileInputStream(recordFile)));
String line=null;
while((line=bReader.readLine())!=null)
try {
String[] values=line.split("\t");
int n=Integer.parseInt(values[1]);
int s=Integer.parseInt(values[2]);
if(n==total&s } catch (RuntimeException e) { } bReader.close(); } catch (Exception e) { } return seconds; } public static void load(){ try { prop.loadFromXML(new FileInputStream(setFile)); } catch (Exception e) { } } public static void save(){ try { prop.storeToXML(new FileOutputStream(setFile), "no comment"); } catch (Exception e) { } } public static void saveLevel(int level){ prop.setProperty("level", level+""); save(); } public static void saveLocation(Point p) { prop.setProperty("frameX", p.x+""); prop.setProperty("frameY", p.y+""); save(); } public static void saveRecord(int total, int seconds) { try { FileOutputStream fos=new FileOutputStream(recordFile,true); PrintWriter out=new PrintWriter(fos,true); out.println(new Date(System.currentTimeMillis())+"\t"+total+"\t"+seconds); out.close(); } catch (FileNotFoundException e) { } } } 这里是随机生成二维坐标,页面方面可以使用JButton import java.util.Random; public class SweepMine { int row=20; int column=20; int array[][]=new int[row][column]; int mineNum=40; boolean bool=true; public void init(){ Random r =new Random(); for(int i=0;i for(int j=0;j array[i][j]=0; for(int k=0;k bool=true;//由于随机生成的坐标可能已是地雷,所以这里设置标记,使其循环获取 while(bool){ int x=r.nextInt(row-1); int y=r.nextInt(column-1); if(x>=row) x=x%row; if(y>=column) y=y%column; if(array[x][y]==0){ array[x][y]=1; bool=false; } } } } public void print(){ int n=0; for(int i=0;i for(int j=0;j System.out.print(array[i][j]+" "); if(array[i][j]==1) n++; } System.out.println(); } System.out.println("地雷数量:"+n); } public static void main(String[]args){ SweepMine sw=new SweepMine(); sw.init(); sw.print(); } } 以下为关联内容: 扫雷java源代码扫雷java源代码,汇编写的扫雷源码:import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Frame extends JFrame { JTextField text; JLabel nowB... java程序设计扫雷帮助看看java程序设计扫雷帮助看看,扫雷高手请进编一个扫雷程序:这里是随机生成二维坐标,页面方面可以使用JButton import java.util.Random; public class SweepMine { int row=20; in... java扫雷源代码或者原理java扫雷源代码或者原理,您好请问有基于Java设计的简易版的扫雷代码吗:mport java.awt.*; import javax.swing.*; import java.util.Random; import java.awt.event.*;class M... 关于扫雷的Java扫雷中英雄榜用JAVA:你用I/0 把要保存的东西,直接写到*.ini文件中不就可以了吗 这个是我 写 连连看游戏,用来保存记录的,自己参考下,很简单。 import java.awt.Point; import jav... 高手帮忙一个扫雷游戏的JAVA的程序代码J2ME扫雷游戏源码:import javax.swing.ImageIcon; //程序入口 public class Block { String name; //名字,比如"雷"或数字 int aroundMineNumber; //周围雷的数目 ImageIcon mineIc... 谁有JAVA编写的扫雷游戏加急J2ME扫雷游戏源码:import java.awt.*;import java.awt.event.*;import javax.swing.*;public class Frame extends JFrame { JTextField text; JLabel nowBomb, setBomb; int... 学了很久JAVA不会写扫雷Java俄罗斯方块的源代码能在eclipse上运行的:扫雷、俄罗斯方块这些小游戏不是为了开发游戏而开发,做这些项目只是为了巩固你学的java se这部分的知识。比如说,你做俄罗斯方块,你... 扫雷中英雄榜用JAVA高手帮忙给我的扫雷游戏JAVA代码添加一个计时功能:JOptionPane就可以了,不必自己再设计类了。 你运行一下我下面的代码段就知道了。import javax.swing.JOptionPane;import ja... JAVA扫雷的一段代码解释基于Java设计的简易版的扫雷代码能实现基本功能即可不要那种:int BombNum, BlockNum; // 当前雷数,当前方块数 int rightBomb, restBomb, restBlock; // 找到的地雷数,剩余雷数,剩...java程序设计扫雷帮助看看