JComboBox cBox = new JComboBox();
cBox.addItem("Food"); String x = "Food";
cBox.addItem("Shirt");
cBox.addItem("Computer");
cBox.setSelectedItem(null);
cBox.setBounds(56, 127, 336, 27);
contentPane.add(cBox);
tPName = new JTextArea();
tPName.setBounds(38, 227, 130, 26);
contentPane.add(tPName);
tPName.setColumns(10);
tSName = new JTextArea();
tSName.setBounds(262, 227, 130, 26);
contentPane.add(tSName);
tSName.setColumns(10);
JButton btn = new JButton("New button");
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String name = (String) cBox.getSelectedItem(); //gets value of combo box
tPName.setText(name); //text area displays value
x; tSName.setText(F);
}
});
其中F字符串等于“值”。我正在使用eclipse,并且在如何让tSName打印响应tsPName中特定值的特定显示时遇到麻烦。