有关JComboBox
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Boxtest implements ActionListener{
public Boxtest() {
static int n;
static String[] items ={"one","two","three","four","five"};
JFrame f = new JFrame();
JComboBox combo=new JComboBox(items));
JButton buttonok=new JButton("Button ok"));
Container contentPane = f.getContentPane();
Box baseBox = Box.createHorizontalBox();
contentPane.add(baseBox);
baseBox.add(combo);
baseBox.add(buttonok);
f.setTitle("Boxtest");
f.setSize(new Dimension(200,200));
f.setVisible(true);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
public void actionPerformed(ActionEvent e) {
if(e.getSource()==buttonOK){
n = combo.getSelectedIndex();
f.setVisible(false);
}
}
//返回选中的项目的值
public static String getItems(){
....??如何实现?
}
}
我想通过内部函数public static String getItems()取得选择的项目值,该如何实现呢?