java,如何在组合框(GUI)中选择项目时显示列表?

时间:2018-01-23 16:43:24

标签: java user-interface combobox

我有一个包含"Drivers","Tickets","Buses","Passengers"信息的双重链接列表,如果我选择组合框中的项目,例如当我选择driverlist时,我想打印,使用我的打印方法打印信息,如果它可以通过选择器显示每个列表,请告诉我,谢谢。

 private static void Listframe() {
     JFrame f = new JFrame("Lists");
     String Lists[]={"Drivers","Tickets","Buses","Passengers"};
     JComboBox box = new JComboBox(Lists);
     JButton b = new JButton("show");

     JLabel label = new JLabel();
     f.setTitle("Lists");
     f.setForeground(Color.white);
     f.setBackground(Color.black);
     f.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
     f.setSize(new Dimension(600,500));
     f.setLocation(new Point(20, 50));           
     f.setVisible(true);
     f.setLayout(new GridLayout(1,3));
     f.add(box);
     f.add(label);
     f.add(b);
     b.addActionListener(new ActionListener() {  
         public void actionPerformed(ActionEvent e) {
             String data = "picked list for: " + box.getItemAt(box.getSelectedIndex());  
             label.setText(data);
         }
     });
}  

0 个答案:

没有答案