0
一個ArrayList
我之前問過類似的問題,但意識到眼前的主要問題,我解決不了:添加的方法創建的JComboBox
目前有一個ArrayList名爲SundayList這是儘快裝作爲幀傳遞addStudent被加載(GUI的位)
的添加學生類: 編輯
public class AddStudent extends javax.swing.JFrame {
public AddStudent() {
initComponents();
}
private void loadLists() throws IOException
{
//Creating the array of Activities to put into the ComboBoxes
File f = new File("Activities.dat");
sundayList = new ArrayList<>();
mondayList= new ArrayList<>();
tuesdayList= new ArrayList<>();
wednesdayList= new ArrayList<>();
thursdayList= new ArrayList<>();
try{
BufferedReader reader = new BufferedReader(new FileReader(f));
while(reader.ready())
{
String CDay = reader.readLine();
String CActivityName = reader.readLine();
String CSupervisor = reader.readLine();
String CLocation = reader.readLine();
String CPaid = reader.readLine();
String nothing = reader.readLine();
if(CDay.equals("Sunday"))
{
sundayList.add(CActivityName);
}
else if(CDay.equals("Monday"))
{
mondayList.add(CActivityName);
}
else if(CDay.equals("Tuesday"))
{
tuesdayList.add(CActivityName);
}
else if(CDay.equals("Wednesday"))
{
wednesdayList.add(CActivityName);
}
else if(CDay.equals("Thursday"))
{
thursdayList.add(CActivityName);
}
}
reader.close();
}
catch (IOException ex)
{
Logger.getLogger(StartUpFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}
...
comboboxSunday = new javax.swing.JComboBox();
...
}
public static void main(String args[]) {
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new AddStudent().setVisible(true);
}
});
}
一開始,我試圖調用列表SundayList到組合框的comboboxSunday來填充它,但只得到了找不到符號錯誤。
我需要做些什麼才能做到這一點?
另外,我打算避開我之前見過的MySQL的參與方法,因爲我不熟悉..
爲組合框當前編碼
代碼自動生成通過Netbeans的組合框是:
comboboxSunday = new javax.swing.JComboBox();
comboboxSunday.setModel(new javax.swing.DefaultComboBoxModel<>(sundayList.toArray(new String[sundayList.size()])));
這意味着我將不得不爲每個列表創建一個類,例如SundayList,MondayList,Tuesday ...等等? – Geuni 2013-03-11 18:38:45
編號使用它們作爲上面顯示的類成員變量 – Reimeus 2013-03-11 18:43:40
我已經根據上面的示例進行了更改,編碼爲「comboboxSunday.setModel(new javax.swing.DefaultComboBoxModel <>(sundayList.toArray(new String [sundayList.size ()])));」由於Netbeans,必須添加javx.swing。但是,仍然存在錯誤,框架(帶有組合框)將不會顯示。我認爲這與添加組合框代碼有關? – Geuni 2013-03-11 19:08:52