public class my1311text2 extends JFrame{ private int i=0; private JComboBox<String> jc; private String[] test= {"红","黄","蓝","绿"}; public static void main(String[] args) { new my1311text2(); } public my1311text2() { jc=new JComboBox(); JButton jb1=new JButton("add"); setSize(200,100); setVisible(true); Container cp=getContentPane(); cp.add(jc,BorderLayout.NORTH); cp.add(jb1,BorderLayout.SOUTH); jb1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub if(i%4==0) { i=0; jc.removeAllItems(); } jc.addItem(test[i]); i++; } }); } }
原链接:https://blog.csdn.net/y786256773/article/details/80670084