在没有扫描仪的情况下获取输入文本 [英] Get input text without scanner
本文介绍了在没有扫描仪的情况下获取输入文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在做一个学校项目,现在我想知道是否可以通过get从JTextField中获取文本?
I work on a school project and I am now wondering if it is possible to get text from JTextField with 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");
我正在尝试获取文本并将其添加到我的数组中,如下所示:
I am trying to get the text and adding it to my array like this:
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上选择了什么吗?
But I think that this way is wrong, but dont know how to solve it. Another question is there any easy way to know what is selected on JComboBox?
推荐答案
comboBox.getSelectedItem();
public String getSortText() {
return sortText.getText();
}
可以在SUN的 Java DOCs 中轻松找到所有这些内容
All this can easily be found in the Java DOCs from SUN.
-edit--更新了我的答案,以确保您真正了解:)
--edit-- updated my answer to really make sure you understand :)
这篇关于在没有扫描仪的情况下获取输入文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文