首页 > 解决方案 > 在“Invasion.Project.Invasion”类中找不到属性“hScore”的设置器

问题描述

需要帮忙!

我有一个错误在类“Invasion.Project.Invasion”中找不到属性“hScore”的设置器

'Invasion' 有对象'hScore' 并且它已经生成了 set 和 get。我以同样的方式设置了其他属性。

为什么我得到那个错误?

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans.xsd">



<bean id="animation" class="Animation.Project.Animation">
    <property name="setup" ref="setup"></property>
    <property name="walker" ref="walker"></property>
    <property name="frame" ref="frame"></property>
</bean>
<bean id="setup" class="Animation.Project.Setup"></bean>
<bean id="walker" class="Animation.Project.Walker"></bean>
<bean id="frame" class="MainProject.TextShow"></bean>


<bean id="mysql_project" class="MySQL.Project.MySQL_Project">
    <property name="conn" ref="communication"></property>
</bean>
<bean id="communication" class="MySQL.Project.Communication">
    <property name="doConnect" ref="doConnect"></property>
</bean>
<bean id="doConnect" class="MySQL.Project.DoConnect"></bean>


<bean id="invasion" class="Invasion.Project.Invasion">
    <property name="saveGame" ref="saveGame"></property>
    <property name="hScore" ref="hScore"></property>
</bean>
<bean id="saveGame" class="Invasion.Project.Save">
    <property name="textName" value="Save.txt"></property>
</bean>
<bean id="hScore" class="Invasion.Project.HighScore"></bean>
<bean id="textShow" class="MainProject.TextShow"></bean>
<bean id="gamePlay" class="Invasion.Project.Gameplay"></bean>

入侵类。也许这里有问题:)。我必须添加更多的文本行,所以我必须发布。

package Invasion.Project;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.*;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import MainProject.TextShow;

public class Invasion extends JPanel implements ActionListener, KeyListener {

/**
 * 
 */
private static final long serialVersionUID = 1L;

private JButton newGame, loadGame, highScore, credits, exit, back, save;

private Image image;

private int buttonHeight = 20;
private int buttonWidth = 120;
private Gameplay gameplay;
private TextShow textShow;
private HighScore hScore;
private Save saveGame;

private String playerName;

private Timer tm = new Timer(5, this);

private ApplicationContext context;


public Invasion() {

    setLayout(null);
    setButtons();

    context = new ClassPathXmlApplicationContext("/beanPackage/beans.xml");
    saveGame = (Save)context.getBean("saveGame");
    hScore = (HighScore)context.getBean("hScore"); // set method not found

    addKeyListener(this);
    setFocusable(true);
    setFocusTraversalKeysEnabled(false);

}

// set buttons on panel
public void setButtons() {
    newGame = new JButton("New Game");
    loadGame = new JButton("Load Game");
    highScore = new JButton("High Score ");
    credits = new JButton("Credits");
    exit = new JButton("Exit");

    newGame.addActionListener(this);
    loadGame.addActionListener(this);
    highScore.addActionListener(this);
    credits.addActionListener(this);
    exit.addActionListener(this);

    newGame.setBounds(800/2 - buttonWidth/2, 500/2 - buttonHeight/2 - buttonHeight * 2 - 20, buttonWidth, buttonHeight);
    loadGame.setBounds(800/2 - buttonWidth/2, 500/2 - buttonHeight/2 - buttonHeight - 10, buttonWidth, buttonHeight);
    highScore.setBounds(800/2 - buttonWidth/2, 500/2 - buttonHeight/2, buttonWidth, buttonHeight);
    credits.setBounds(800/2 - buttonWidth/2, 500/2 - buttonHeight/2 + buttonHeight + 10, buttonWidth, buttonHeight);
    exit.setBounds(800/2 - buttonWidth/2, 500/2 - buttonHeight/2 + buttonHeight * 2 + 20, buttonWidth, buttonHeight);

    add(newGame);
    add(loadGame);
    add(highScore);
    add(credits);
    add(exit);
}

// Paint on canvas
public void paintComponent(Graphics g) {

    super.paintComponent(g);
    setBackground(g);

    if (gameplay != null) {
        gameplay.paintComponenet(g);
        if (gameplay.gameEnded()) {

            hScore.setScore(gameplay.getscore() +" "+ playerName);
            gameplay = null;

            highScore.setBounds(800/2 - buttonWidth/2, 500/2 - buttonHeight/2, buttonWidth, buttonHeight);

            tm.stop();

            setButtons();
            repaint();

        }
    } else if (textShow != null) {
        textShow.move++;
        textShow.paintComponent(g);
    }
}

// Set background picture
private void setBackground(Graphics g) {

    try {
        image = ImageIO.read(new File("alienfleet.png"));
    } catch (IOException e) {
        e.printStackTrace();
    }

    g.drawImage(image, 0, 0, getWidth(), getHeight(), null);
}

// Action performed for buttons
public void actionPerformed(ActionEvent e) {

    if (e.getSource() == newGame || e.getSource() == loadGame) {

        this.removeAll();
        tm.start();

        playerName = JOptionPane.showInputDialog("Enter your name: ");
        gameplay = (Gameplay)context.getBean("gameplay");
        gameplay.setWidth(getWidth());
        gameplay.setHeight(getHeight());

        if (e.getSource() == loadGame){

            gameplay.setSavedShipsList(saveGame.getSave());
        }
        back = new JButton("exit");
        save = new JButton("save");

        back.setBounds(getWidth() - 150, 20, 65, 15);
        save.setBounds(getWidth() - 75, 20, 65, 15);

        back.addActionListener(this);
        save.addActionListener(this);

        add(back);
        add(save);
        repaint();  

    } else if (e.getSource() == highScore) {

        hScore.setTextName("HighScore.txt");
        hScore.showHighScore();

    } else if (e.getSource() == credits) {
        this.removeAll();
        tm.start();
        if (textShow == null) {
            textShow = (TextShow)context.getBean("textShow");
            textShow.setTextName("Credits.txt");
            textShow.setCords(30, getHeight() + 10, -10, 15, Color.WHITE);
        }
        back = new JButton("<-Back");
        back.setBounds(20, 20, buttonWidth, buttonHeight);
        back.addActionListener(this);
        add(back);

    } else if (e.getSource() == exit) {
        ((ClassPathXmlApplicationContext) context).close();
        System.exit(0);
    }

    // this action pr are for manipulation when you are in objects

    if (e.getSource() == back) { // return to menu
        textShow = null;
        gameplay = null;
        tm.stop();
        this.removeAll();
        setButtons();

    } else if(e.getSource() == save) { // save game

        saveGame.setSave(gameplay.getSavedShipsList());
    }

    repaint();
}

// just for gameplay class
public void keyPressed(KeyEvent e) {
    int code = e.getKeyCode();
    if (code == KeyEvent.VK_LEFT) {
        if ((gameplay.playerShipX - gameplay.palyerShip.shipWidth/2) > 0) {
            gameplay.playerShipX = gameplay.playerShipX - 3;
        }
    }
    else if (code == KeyEvent.VK_RIGHT) {
        if ((gameplay.playerShipX + gameplay.palyerShip.shipWidth/2) < getWidth()) {
            gameplay.playerShipX = gameplay.playerShipX + 3;
        }
    }
}

public void keyReleased(KeyEvent e) {

}

public void keyTyped(KeyEvent e) {
    char ch = e.getKeyChar();
    if (ch == ' ') {
        gameplay.missile = false;
    }

}

public Save getSaveGame() {
    return saveGame;
}

public void setSaveGame(Save saveGame) {
    this.saveGame = saveGame;
}

public TextShow getTextShow() {
    return textShow;
}

public void setTextShow(TextShow textShow) {
    this.textShow = textShow;
}
public HighScore gethScore() {
    return hScore;
}

public void sethScore(HighScore hScore) {
    this.hScore = hScore;
}


}

和高分班

package Invasion.Project;

import java.awt.Dimension;
import java.util.ArrayList;

import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.TableColumnModel;

import MainProject.TextRD;

public class HighScore extends TextRD {


private JTable table;

private String[] columnNames = { "Id", "Score", "Name" };
private String[][] data;
private ArrayList<String> lines = new ArrayList<String>();


public HighScore() {
}

public void setTextName(String textName) {
    super.setTextName(textName);
}



public void setScore(String score) {
    wrieIntoFile(score);
}

public void showHighScore() {

    lines = readFromFile();

    setTable();

    table = new JTable(data, columnNames);
    table.setPreferredScrollableViewportSize(new Dimension(380,200));
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    TableColumnModel columnModel = table.getColumnModel();
    for (int i = 0; i < columnNames.length; i++) {
        if (i < columnModel.getColumnCount()) {
            columnModel.getColumn(i).setMaxWidth(200);
            columnModel.getColumn(i).setMinWidth(120);
        }
        else break;
    }

    JScrollPane spane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    JOptionPane.showMessageDialog(null, spane);
}

private void setTable() {

    data = new String[lines.size()][3];

    sort(lines);

    for (int i = 0; i < data.length; i++) {
        for (int j = 0; j < data[0].length; j++) {

            if (j == 0) {
                data[i][j] = Integer.toString(i+1);
            } else if (j == 1){
                data[i][j] = lines.get(i).substring(0, lines.get(i).indexOf(" "));
            } else {
                data[i][j] = lines.get(i).substring(lines.get(i).indexOf(" "));
            }
        }
    }

}

private void sort(ArrayList<String> list) {

    for (int i = 0; i < list.size(); i++) {
        for (int j = i+1; j < list.size(); j++) {

            if (Integer.parseInt(list.get(i).substring(0, list.get(i).indexOf(" "))) < Integer.parseInt(list.get(j).substring(0, list.get(j).indexOf(" ")))) {
                String temp = list.get(i);
                list.set(i, list.get(j));
                list.set(j, temp);
            }
        }

    }
}

}

标签: javaspring

解决方案


推荐阅读