
正文
微信飞机大战代码java 微信飞机大战下载安装
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
写了一个java swing的飞机大战,但是碰撞检测获取坐标的地方出现了错误,求大神帮忙
你好!很高兴为你回答问题。
首先微信飞机大战代码java,请原谅我指出你微信飞机大战代码java的错误。
错误一微信飞机大战代码java:int a[] =Integer.parseInt(jta.getText());
错处:从jta获取字符串后微信飞机大战代码java,转换为整数,乃1个数,用数组存放可以,但不能像你这样写,你这样写是将一个整形数组初始化为一个整数。所以错。。。
错误二:jtf.append(String.valueOf(max));
错处:JTextField没有append方法,无中生有。所以错。。。
错误三:思路错
错处:将文本域中获取的几个数字,不加处理则提取其中数字作为整数数组,是不行的
修正如下:(在文本框中输入几个数字,请用空格隔开,有问题请追问)
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Exam3_7 {
public static void main(String[] args) {
FrameText ft = new FrameText();
ft.setVisible(true);
}
}
class FrameText extends JFrame implements ActionListener {
JTextField jtf;
JTextArea jta;
JButton jbt, jbt1;
FrameText() {
super("输出最大数和最小数的程序");
Container con = getContentPane();
con.setLayout(new FlowLayout());
jta = new JTextArea("", 5, 10);
jtf = new JTextField(5);
jbt = new JButton("获取最大数");
jbt1 = new JButton("获取最小数");
jbt.addActionListener(this);
jbt1.addActionListener(this);
con.add(jta);
con.add(jtf);
con.add(jbt);
con.add(jbt1);
setSize(300, 300);
}
public void actionPerformed(ActionEvent e) {
String[] input = jta.getText().split(" ");
int[] a = new int[input.length];
for (int i = 0; i input.length; i++) {
a[i] = Integer.parseInt(input[i]);
}
if (e.getSource() == jbt) {
int max = a[0];
for (int j = 1; j a.length; j++) {
if (a[j] max) {
max = a[j];
}
}
jtf.setText(String.valueOf(max));
}
if (e.getSource() == jbt1) {
int min = a[0];
for (int j = 1; j a.length; j++) {
if (a[j] min) {
min = a[j];
}
}
jtf.setText(String.valueOf(min));
}
}
}
相关问答
Q1: 求一个简单的Java小游戏的代码
连连看微信飞机大战代码java的小源码
package Lianliankan;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class lianliankan implements ActionListener
{
JFrame mainFrame; //主面板
Container thisContainer;
JPanel centerPanel,southPanel,northPanel; //子面板
JButton diamondsButton[][] = new JButton[6][5];//游戏按钮数组
JButton exitButton,resetButton,newlyButton; //退出微信飞机大战代码java,重列,重新开始按钮
JLabel fractionLable=new JLabel("0"); //分数标签
JButton firstButton,secondButton; //分别记录两次被选中的按钮
int grid[][] = new int[8][7];//储存游戏按钮位置
static boolean pressInformation=false; //判断是否有按钮被选中
int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV; //游戏按钮的位置坐标
int i,j,k,n;//消除方法控制
public void init(){
mainFrame=new JFrame("JKJ连连看");
thisContainer = mainFrame.getContentPane();
thisContainer.setLayout(new BorderLayout());
centerPanel=new JPanel();
southPanel=new JPanel();
northPanel=new JPanel();
thisContainer.add(centerPanel,"Center");
thisContainer.add(southPanel,"South");
thisContainer.add(northPanel,"North");
centerPanel.setLayout(new GridLayout(6,5));
for(int cols = 0;cols 6;cols++){
for(int rows = 0;rows 5;rows++ ){
diamondsButton[cols][rows]=new JButton(String.valueOf(grid[cols+1][rows+1]));
diamondsButton[cols][rows].addActionListener(this);
centerPanel.add(diamondsButton[cols][rows]);
}
}
exitButton=new JButton("退出");
exitButton.addActionListener(this);
resetButton=new JButton("重列");
resetButton.addActionListener(this);
newlyButton=new JButton("再来一局");
newlyButton.addActionListener(this);
southPanel.add(exitButton);
southPanel.add(resetButton);
southPanel.add(newlyButton);
fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText())));
northPanel.add(fractionLable);
mainFrame.setBounds(280,100,500,450);
mainFrame.setVisible(true);
}
public void randomBuild() {
int randoms,cols,rows;
for(int twins=1;twins=15;twins++) {
randoms=(int)(Math.random()*25+1);
for(int alike=1;alike=2;alike++) {
cols=(int)(Math.random()*6+1);
rows=(int)(Math.random()*5+1);
while(grid[cols][rows]!=0) {
cols=(int)(Math.random()*6+1);
rows=(int)(Math.random()*5+1);
}
this.grid[cols][rows]=randoms;
}
}
}
public void fraction(){
fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText())+100));
}
public void reload() {
int save[] = new int[30];
int n=0,cols,rows;
int grid[][]= new int[8][7];
for(int i=0;i=6;i++) {
for(int j=0;j=5;j++) {
if(this.grid[i][j]!=0) {
save[n]=this.grid[i][j];
n++;
}
}
}
n=n-1;
this.grid=grid;
while(n=0) {
cols=(int)(Math.random()*6+1);
rows=(int)(Math.random()*5+1);
while(grid[cols][rows]!=0) {
cols=(int)(Math.random()*6+1);
rows=(int)(Math.random()*5+1);
}
this.grid[cols][rows]=save[n];
n--;
}
mainFrame.setVisible(false);
pressInformation=false; //这里一定要将按钮点击信息归为初始
init();
for(int i = 0;i 6;i++){
for(int j = 0;j 5;j++ ){
if(grid[i+1][j+1]==0)
diamondsButton[i][j].setVisible(false);
}
}
}
public void estimateEven(int placeX,int placeY,JButton bz) {
if(pressInformation==false) {
x=placeX;
y=placeY;
secondMsg=grid[x][y];
secondButton=bz;
pressInformation=true;
}
else {
x0=x;
y0=y;
fristMsg=secondMsg;
firstButton=secondButton;
x=placeX;
y=placeY;
secondMsg=grid[x][y];
secondButton=bz;
if(fristMsg==secondMsg secondButton!=firstButton){
xiao();
}
}
}
public void xiao() { //相同的情况下能不能消去。仔细分析,不一条条注释
if((x0==x (y0==y+1||y0==y-1)) || ((x0==x+1||x0==x-1)(y0==y))){ //判断是否相邻
remove();
}
else{
for (j=0;j7;j++ ) {
if (grid[x0][j]==0){ //判断第一个按钮同行哪个按钮为空
if (yj) { //如果第二个按钮的Y坐标大于空按钮的Y坐标说明第一按钮在第二按钮左边
for (i=y-1;i=j;i-- ){ //判断第二按钮左侧直到第一按钮中间有没有按钮
if (grid[x][i]!=0) {
k=0;
break;
}
else{ k=1; } //K=1说明通过微信飞机大战代码java了第一次验证
}
if (k==1) {
linePassOne();
}
}
if (yj){ //如果第二个按钮的Y坐标小于空按钮的Y坐标说明第一按钮在第二按钮右边
for (i=y+1;i=j ;i++ ){ //判断第二按钮左侧直到第一按钮中间有没有按钮
if (grid[x][i]!=0){
k=0;
break;
}
else { k=1; }
}
if (k==1){
linePassOne();
}
}
if (y==j ) {
linePassOne();
}
}
if (k==2) {
if (x0==x) {
remove();
}
if (x0x) {
for (n=x0;n=x-1;n++ ) {
if (grid[n][j]!=0) {
k=0;
break;
}
if(grid[n][j]==0 n==x-1) {
remove();
}
}
}
if (x0x) {
for (n=x0;n=x+1 ;n-- ) {
if (grid[n][j]!=0) {
k=0;
break;
}
if(grid[n][j]==0 n==x+1) {
remove();
}
}
}
}
}
for (i=0;i8;i++ ) { //列
if (grid[i][y0]==0) {
if (xi) {
for (j=x-1;j=i ;j-- ) {
if (grid[j][y]!=0) {
k=0;
break;
}
else { k=1; }
}
if (k==1) {
rowPassOne();
}
}
if (xi) {
for (j=x+1;j=i;j++ ) {
if (grid[j][y]!=0) {
k=0;
break;
}
else { k=1; }
}
if (k==1) {
rowPassOne();
}
}
if (x==i) {
rowPassOne();
}
}
if (k==2){
if (y0==y) {
remove();
}
if (y0y) {
for (n=y0;n=y-1 ;n++ ) {
if (grid[i][n]!=0) {
k=0;
break;
}
if(grid[i][n]==0 n==y-1) {
remove();
}
}
}
if (y0y) {
for (n=y0;n=y+1 ;n--) {
if (grid[i][n]!=0) {
k=0;
break;
}
if(grid[i][n]==0 n==y+1) {
remove();
}
}
}
}
}
}
}
public void linePassOne(){
if (y0j){ //第一按钮同行空按钮在左边
for (i=y0-1;i=j ;i-- ){ //判断第一按钮同左侧空按钮之间有没按钮
if (grid[x0][i]!=0) {
k=0;
break;
}
else { k=2; } //K=2说明通过了第二次验证
}
}
if (y0j){ //第一按钮同行空按钮在与第二按钮之间
for (i=y0+1;i=j ;i++){
if (grid[x0][i]!=0) {
k=0;
break;
}
else{ k=2; }
}
}
}
public void rowPassOne(){
if (x0i) {
for (j=x0-1;j=i ;j-- ) {
if (grid[j][y0]!=0) {
k=0;
break;
}
else { k=2; }
}
}
if (x0i) {
for (j=x0+1;j=i ;j++ ) {
if (grid[j][y0]!=0) {
k=0;
break;
}
else { k=2; }
}
}
}
public void remove(){
firstButton.setVisible(false);
secondButton.setVisible(false);
fraction();
pressInformation=false;
k=0;
grid[x0][y0]=0;
grid[x][y]=0;
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==newlyButton){
int grid[][] = new int[8][7];
this.grid = grid;
randomBuild();
mainFrame.setVisible(false);
pressInformation=false;
init();
}
if(e.getSource()==exitButton)
System.exit(0);
if(e.getSource()==resetButton)
reload();
for(int cols = 0;cols 6;cols++){
for(int rows = 0;rows 5;rows++ ){
if(e.getSource()==diamondsButton[cols][rows])
estimateEven(cols+1,rows+1,diamondsButton[cols][rows]);
}
}
}
public static void main(String[] args) {
lianliankan llk = new lianliankan();
llk.randomBuild();
llk.init();
}
}
//old 998 lines
//new 318 lines
Q2: 刚刚开始学java,老师给的代码在自己运行电脑上就出现了错误
根据javax.imageio.IIOException: Can't read input file!异常,意思是无法读取到文件,原因是background = ImageIO.read(new File(Game.class.getResource(
"/img/background.png").getFile()));代码中的文件不在本地或者路径不对,解决办法是将图片路径填写正确。
Q3: 微信5.0飞机大战无敌模式怎么开启
手机必须是越狱过微信飞机大战代码java的哦,否则是不能运行的微信飞机大战代码java!
飞机大战无敌模式开启:
第一步:先通过Cydia进行软件的安装
第二步:通过上述方法安装好无敌补丁后,选择下载好的无敌补丁即 org.ioshack.dafeijiPatch_1.0-1_iphoneos-arm.deb文件,运行游戏!
第三步:开启微信打飞机游戏无敌模式
Q4: java做的Android 飞机大战中如何实现敌机个数随机实现?比如在一个屏幕中最多只能出现5个敌机!
可以使用java.util.Random类来产生一个随机数发生器。它有两种形式的构造函数,分别是Random()和Random(long seed)。Random()使用当前时间即System.currentTimeMillis()作为发生器的种子,Random(long seed)使用指定的seed作为发生器的种子。
随机数发生器(Random)对象产生以后,通过调用不同的method:nextInt()、nextLong()、nextFloat()、nextDouble()等获得不同类型随机数。
1生成随机数
Random random = new Random();
Random random = new Random(100);//指定种子数100
random调用不同的方法,获得随机数。
如果2个Random对象使用相同的种子(比如都是100),并且以相同的顺序调用相同的函数,那它们返回值完全相同。如下面代码中两个Random对象的输出完全相同
import java.util.*;
class TestRandom {
public static void main(String[] args) {
Random random1 = new Random(100);
System.out.println(random1.nextInt());
System.out.println(random1.nextFloat());
System.out.println(random1.nextBoolean());
Random random2 = new Random(100);
System.out.println(random2.nextInt());
System.out.println(random2.nextFloat());
System.out.println(random2.nextBoolean());
}
}
2指定范围内的随机数
随机数控制在某个范围内,使用模数运算符%
import java.util.*;
class TestRandom {
public static void main(String[] args) {
Random random = new Random();
for(int i = 0; i 10;i++) {
System.out.println(Math.abs(random.nextInt())%10);
}
}
}
获得的随机数有正有负的,用Math.abs使获取数据范围为非负数
3获取指定范围内的不重复随机数
import java.util.*;
class TestRandom {
public static void main(String[] args) {
int[] intRet = new int[6];
int intRd = 0; //存放随机数
int count = 0; //记录生成的随机数个数
int flag = 0; //是否已经生成过标志
while(count6){
Random rdm = new Random(System.currentTimeMillis());
intRd = Math.abs(rdm.nextInt())%32+1;
for(int i=0;icount;i++){
if(intRet[i]==intRd){
flag = 1;
break;
}else{
flag = 0;
}
}
if(flag==0){
intRet[count] = intRd;
count++;
}
}
for(int t=0;t6;t++){
System.out.println(t+"-"+intRet[t]);
}
}
}
Java随机数类Random介绍
Java实用工具类库中的类java.util.Random提供了产生各种类型随机数的方法。它可以产生int、long、float、double以 及Goussian等类型的随机数。这也是它与java.lang.Math中的方法Random()最大的不同之处,后者只产生double型的随机 数。
类Random中的方法十分简单,它只有两个构造方法和六个普通方法。
构造方法:
(1)public Random()
(2)public Random(long seed)
Java产生随机数需要有一个基值seed,在第一种方法中基值缺省,则将系统时间作为seed。
普通方法:
(1)public synonronized void setSeed(long seed)
该方法是设定基值seed。
(2)public int nextInt()
该方法是产生一个整型随机数。
(3)public long nextLong()
该方法是产生一个long型随机数。
(4)public float nextFloat()
该方法是产生一个Float型随机数。
(5)public double nextDouble()
该方法是产生一个Double型随机数。
(6)public synchronized double nextGoussian()
该方法是产生一个double型的Goussian随机数。
例2 RandomApp.java。
//import java.lang.*;
import java.util.Random;
public class RandomApp{
public static void main(String args[]){
Random ran1=new Random();
Random ran2=new Random(12345);
//创建了两个类Random的对象。
System.out.println("The 1st set of random numbers:");
System.out.println(" Integer:"+ran1.nextInt());
System.out.println(" Long:"+ran1.nextLong());
System.out.println(" Float:"+ran1.nextFloat());
System.out.println(" Double:"+ran1.nextDouble());
System.out.println(" Gaussian:"+ran1.nextGaussian());
//产生各种类型的随机数
System.out.print("The 2nd set of random numbers:");
for(int i=0;i5;i++){
System.out.println(ran2.nextInt()+" ");
if(i==2) System.out.println();
//产生同种类型的不同的随机数。
System.out.println();
}
}
}
Random random=new Random();
random.nextInt();
也可以有nextFloat等等,各种基本类型都有
Math.random也可以
比如说你想要0-10之间的随机数
你可以这样写
(int)(Math.random()*10);
JAVA产生指定范围的随机数》
《JAVA产生指定范围的随机数》
产生机制:
产生Min-Max之间的数字
实现原理:
Math.round(Math.random()*(Max-Min)+Min)
long Temp; //不能设定为int,必须设定为long
//产生1000到9999的随机数
Temp=Math.round(Math.random()*8999+1000);
微信飞机大战代码java的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于微信飞机大战下载安装、微信飞机大战代码java的信息别忘了在本站进行查找喔。







