我在一个学校项目上工作,我现在想知道是否可以使用 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);
但我认为这种方式是错误的,但不知道如何解决。另一个问题是有什么简单的方法可以知道在 JComboBox 上选择了什么?