私は学校のプロジェクトに取り組んでいますが、get を使用して JTextField からテキストを取得できるかどうか疑問に思っています。
// 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);
しかし、この方法は間違っていると思いますが、解決方法がわかりません。もう 1 つの質問は、JComboBox で何が選択されているかを知る簡単な方法はありますか?