1
添加一個私有字段I類有兩個相關的類SpaceInvadersApp和HighScoreTableModel在Java中
我需要一個新的私人領域在SpaceInvadersApp的開頭添加到SpaceInvadersApp類類型HighScoreTableModel的,並初始化這個領域構造函數。
這是我的嘗試,我認爲我沒有做正確。
public class SpaceInvadersApp extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private final GamePanel game;
private HighScoreTableModel highScoreTableModel; // unsure about this
final private JMenuItem menuItemGamePause;
/**
* Create new Space Invaders application.
* @throws HeadlessException
*/
public SpaceInvadersApp() throws HeadlessException {
highScoreTableModel = new HighScoreTableModel("Name", "Score"); //unsure about this
繼承人從HighScoreTableModel類
package spaceinvaders.highscores;
import java.util.*;
import javax.swing.event.*;
import javax.swing.table.*;
public class HighScoreTableModel implements TableModel {
private List<String> col1StringList = new ArrayList<String>();
private List<Integer> col2IntegerList = new ArrayList<Integer>();
private String col1Name, col2Name;
private List<TableModelListener> listenerList = new ArrayList<TableModelListener>();
public HighScoreTableModel(String col1Name, String col2Name) {
this.col1Name = col1Name;
this.col2Name = col2Name;
什麼是你的問題? – 2014-08-31 23:46:22
上面的代碼不起作用。看到/ /不確定這個 – Zhauo 2014-08-31 23:47:33
你沒有給所有的'final'字段賦值,但究竟是什麼*不起作用,以及它如何不能工作*? – 2014-08-31 23:48:57