我是一个初学java的人,并且遇到了一个我无法解决的问题。用actionlistener添加到数组
我想添加字符串到我的数组,我测试了我的数组,以便工作。但我的问题是,我创建了一个actionlistener并试图从另一个类中获取文本,然后将其添加到数组中。
我Buttonlistener:
public class ButtonListener extends AddToLibrary implements ActionListener {
public void actionPerformed(ActionEvent e) {
Database dt = new Database();
dt.add(textType, textTitle, textSort, textDesc);
} }
我有一个朋友,谁告诉我,我创造我每次按下按钮时,一个新的数据库,但我该怎么做,如果我只是想“负荷”吗?可以清除该数据库是我的数组的类名。
这个更“有趣”的部分是,当我在eclipse中运行它时,它调试器没有向我显示任何明确的错误,并且由于我在java中的知识有限,这对我来说太过于了。
我buttonlistener是歌厅从AddToLibrary的信息,它看起来像这样:
public class AddToLibrary extends JPanel{
public String textTitle;
public String textSort;
public String textDesc;
public String textType;
public AddToLibrary() {
// Förklarande text
JLabel titel = new JLabel("Titel");
JLabel sort = new JLabel("Genre");
JLabel desc = new JLabel("Beskriving");
// 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");
addButton.addActionListener(new ButtonListener()); //Lyssna på knapp
// Combobox
JComboBox comboBox = new JComboBox();
comboBox.addItem("Film");
comboBox.addItem("CD");
comboBox.addItem("Bok");
comboBox.addItem("Annat");
// Lägg till i panelen
add(titel);
add(textTitel);
add(sort);
add(textSort);
add(desc);
add(textDesc);
add(comboBox);
add(addButton);
}
public String getTitelText(JTextField titelText) {
textTitle = "" + titelText.getText();
return textTitle;
}
public String getDescText(JTextField descText) {
textDesc = "" + descText.getText();
return textDesc;
}
public String getSortText(JTextField sortText) {
textSort = "" + sortText.getText();
return textSort;
}
public String getTypeText(JComboBox comboBox) {
return textType = "" + (String) comboBox.getSelectedItem() + ".png";
}
}
但它不工作,我无法理解为什么它不是工作,所以如果任何人有一定的时间来帮我,我会很高兴。
谢谢!
感谢您的尝试,但它仍然不会工作,但感谢试试吧! – user290030 2010-03-09 22:53:09