0
這是我的小程序。toString不打印JApplet中的實際數組值
public void paint(Graphics g){
super.paint(g);
Font font = new Font("monospaced", Font.BOLD, 12);
g.setFont(font);
g.setColor(Color.YELLOW);
g.fillRect(0, 105, 500, 500);
g.setColor(Color.BLACK);
g.drawString("hello", 120, 300);
for(int c = 0; c < 1;){
for(int b = 250; c < 9; b = b + 10){
g.drawString(roster[c].toString(), 10, b);
c++;
}
}
g.drawString(roster[0].toString(), 0, 250);
}
public Student[] setup(){
count = 10;
roster = new Student[count];
int x = 0; int e = 0;
int[] gtest = new int[5];
for(e = 0; e < 5; e++){
gtest[e] = 0;
}
for(x = 0; x < 31; x++){
roster[x] = new Student("", 0, gtest);
}
int[] help = new int[5];
help[0] = 84; help[1] = 85; help[2] = 86; help[3] = 87; help[4] = 88;
roster[0] = new Student("Pocket, beam", 2017, new int[] {84, 85, 84, 87, 88, 88});
roster[1] = new Student("Zuckerberg, Marcus", 2017, help);
roster[2] = new Student("Timelapse, Random", 2013, help);
roster[3] = new Student("Timelapse, Random2", 2013, help);
roster[4] = new Student("Timelapse, Random3", 2016, help);
roster[5] = new Student("god, not", 2016, help);
roster[6] = new Student("Webster, Jacques", 2016, help);
roster[7] = new Student("East, Kanayo", 2016, help);
roster[8] = new Student("Blue, Canoe", 2017, help);
roster[9] = new Student("West, East", 2017, help);
return(roster);
}
我粘貼的特定代碼,以及,所述.toString
是在圖形方法。
這是我在構造函數類中的toString
方法。
public String toString(){
DecimalFormat tens = new DecimalFormat("0.00");
String ans = String.format("%-20s%-8s %-5s%-5s%-5s%-5s%-5s%-10s", name, year,
grades[0], grades[1], grades[2], grades[3], grades[4], tens.format(gpa));
return(ans);
}
所以我相信這個問題是我如何打電話.toString
,我的谷歌搜索顯示,我應該使用java.util.Arrays
?我試過了,我無法弄清楚什麼是錯的。我知道它是一個簡單的語法錯誤,但我無法挑選它是什麼。
會發生什麼情況是名冊號碼打印到小程序,但所有的值都是0.00或0或其他格式的任何0。
也repaint()
叫我actionperformed
方法
你嘗試調用重繪()? –
我做過了,它在我的動作執行方法中 – Hquad
首先,從x = 0到31的循環導致數組索引超出範圍,因爲名單數組只有10個。 – pacifier21