java 的jcombobox的取值
发布网友
发布时间:2022-07-14 21:02
我来回答
共3个回答
热心网友
时间:2023-10-06 06:54
import javax.swing.JComboBox;
import javax.swing.JFrame;
public class Test2 extends JFrame implements Runnable {
private JComboBox box;
public Test2() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
box = new JComboBox();
box.addItem("葡萄");
box.addItem("香蕉");
box.addItem("苹果");
this.add(box);
this.pack();
}
public static void main(String[] args) {
Test2 test = new Test2();
test.setVisible(true);
Thread t = new Thread(test);
t.start();
}
@Override
public void run() {
// TODO Auto-generated method stub
while (true) {
String value = (String) box.getSelectedItem();
System.out.println(value);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
热心网友
时间:2023-10-06 06:54
(String)fruitCombo.getSelectedItem().equals("Grape")
热心网友
时间:2023-10-06 06:55
String ret=jcombobox.getSelectedItem().toString();