我在一個學校項目上工作,我現在想知道是否有可能從JTextField獲取文本與get?獲取輸入文本沒有掃描儀
// Textrutor
JTextField textTitel = new JTextField(null, 20);
textTitel.setToolTipText("ex. Flickan som lekte med elden");
JTextField textSort = new JTextField(null, 10);
textSort.setToolTipText("ex. Skräck, Action");
JTextField textDesc = new JTextField(null, 15);
textDesc.setToolTipText("ex. Stieg Larsson");
// Knappar
JButton addButton = new JButton("Lägg till");
// Combobox
JComboBox comboBox = new JComboBox();
comboBox.addItem("Film");
comboBox.addItem("CD");
comboBox.addItem("Bok");
comboBox.addItem("Annat");
我試圖獲取文本並將其添加到我的數組是這樣的:
public String getTitelText() {
return titelText;
}
public String getDescText() {
return descText;
}
public String getSortText() {
return sortText;
}
public void actionPerformed(ActionEvent e) {
DatabaseTable dt = new DatabaseTable();
dt.add(titelText, sortText, descText, descText);
但我認爲,這種方式是錯誤的,但不知道如何解決它。另一個問題是有沒有簡單的方法知道JComboBox上選擇了什麼?
是否要從文本字段插入文本到數據庫表? – jjj 2010-02-22 08:40:44
是的,這就是我想要的 – Stefan 2010-02-22 08:57:46
也許這可能有助於http://www.java2s.com/Code/Java/Database-SQL-JDBC/InserttextfileintoMySQL.htm – jjj 2010-02-22 10:48:54