求各位大佬帮帮忙,代码写出来了,但是有问题,我实在是找不出来问题出在哪??

吴溪啊 吴溪啊 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
package ui;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.util.Random;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

public class GameInterface extends JFrame implements ActionListener{
JLabel lblBackground;
static JButton play01;
static JButton play02;
static JButton play03;

int index1;
int index2;
int score1;
int score2;
BufferedImage image1;
BufferedImage image2;


public GameInterface() {
// TODO Auto-generated constructor stub
//设置标题
setTitle("游戏主界面");
//位置居中
setLocation(200,100);
//设置大小
setSize(1200, 500);
//设置退出方式
setDefaultCloseOperation(EXIT_ON_CLOSE);

//加载背景图片
ImageIcon imageIcon=new ImageIcon("src/image/游戏主界面.jpg");
lblBackground=new JLabel(imageIcon);
//设置图片大小
lblBackground.setBounds(0, 0, 1200, 500);
lblBackground.setLayout(null);
this.add(lblBackground);

play01=new JButton("round 1");
play01.setBounds(500, 100, 150, 50);
lblBackground.add(play01);
play01.addActionListener(this);

play02=new JButton("round 2");
play02.setBounds(500, 200, 150, 50);
lblBackground.add(play02);
play02.addActionListener(this);

play03=new JButton("round 3");
play03.setBounds(500, 300, 150, 50);
lblBackground.add(play03);
play03.addActionListener(this);


setLayout(null);
setVisible(true);

}

public static void main(String[] args) {
GameInterface g=new GameInterface();
}



public void judge() {

Random r=new Random();
index1=r.nextInt(3)+1;
index2=r.nextInt(3)+1;

image1=App.getImg("/image/0"+index1+".jpg");
image2=App.getImg("/image/0"+index2+".jpg");

repaint();

if(index1==1&&index2==1) {
JOptionPane.showMessageDialog(null,"此局平局");
}
if(index1==1&&index2==2) {
score1++;
JOptionPane.showMessageDialog(null,"此局机兄胜出");
}
if(index1==1&&index2==3) {
score2++;
JOptionPane.showMessageDialog(null,"此局魏兄胜出");
}
if(index1==2&&index2==1) {
score2++;
JOptionPane.showMessageDialog(null,"此局魏兄胜出");
}
if(index1==2&&index2==2) {
JOptionPane.showMessageDialog(null,"此局平局");
}
if(index1==2&&index2==3) {
score1++;
JOptionPane.showMessageDialog(null,"此局机兄胜出");
}
if(index1==3&&index2==1) {
score1++;
JOptionPane.showMessageDialog(null,"此局机兄胜出");
}
if(index1==3&&index2==2) {
score2++;
JOptionPane.showMessageDialog(null,"此局魏兄胜出");
}
if(index1==3&&index2==3) {
JOptionPane.showMessageDialog(null,"此局平局");
}


}

public void finalJudge() {
if(score1>score2) {
JOptionPane.showMessageDialog(null,"结果为:机兄胜利");
}else if(score1<score2){
JOptionPane.showMessageDialog(null,"结果为:魏兄胜利");
}else {
JOptionPane.showMessageDialog(null,"结果为:平局");
}
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==play01) {
judge();
}


if(e.getSource()==play02) {
judge();
}

if(e.getSource()==play03) {
judge();
finalJudge();
}


}

@Override
public void paint(Graphics g) {
// TODO Auto-generated method stub
super.paint(g);
g.setColor(Color.BLACK);
g.setFont(new Font("楷体",Font.BOLD,30));
g.drawImage(image1, 0,20,image1.getWidth(),image1.getHeight(), null);
g.drawImage(image2,1030, 20,image2.getWidth(),image2.getHeight(), null);
g.drawString("机兄分数:"+score1, 250, 300);
g.drawString("魏兄分数:"+score2, 850, 300);

}

}

能够运行出来,但是一直有很多警示
...全文
评论 6
收藏 已收藏
分享
返回顶部
吴溪啊
Java SE 62,621 成员 307,251 内容