求各位大佬帮帮忙,代码写出来了,但是有问题,我实在是找不出来问题出在哪??
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);
}
}
能够运行出来,但是一直有很多警示

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);
}
}
能够运行出来,但是一直有很多警示

...全文
相关推荐
python 给一个不多于5位的正整数,要求:一、求它是几位数,二、逆序打印出各位数字 (示例)
# 题目: # 给一个不多于5位的正整数,要求:一、求它是几位数,二、逆序打印出各位数字。 # 分析: # 学会分解出每一位数。
代码_C循环-求各位数字之积_
入一个英文句子和空格字符,则输出删除了所有空格的字符测试说明以下是测试样例:样例输入:abc333dgf3样例输出:abcdgf*/
java小实验:求一个整数各位数字之和
求一个整数各位数字之和。求一个整数各位数字之和。求一个整数各位数字之和。求一个整数各位数字之和。
求整数的位数及各位数字之和 C语言
求整数的位数及各位和
求正整数各位数字之和
从键盘接收一个正整数,求正整数各位数字之和


Java SE
