1
public class frame {

        genericclass twelveoclockfix;
        JFrame Frame1;
        JPanel j2;
        JPanel j4;
        JButton b1;
        JTextField t1;
        ArrayList<Integer> hour;
        ArrayList<Integer> minute;
        JComboBox<Integer> t2;
        JComboBox<Integer> t3;
        JComboBox<String> t4;
        JPanel j1;
        JLabel l1;

        public frame() {
                //twelveoclockfix = new genericclass();
                Frame1 = new JFrame("9gag's own: jClock");
                j2 = new JPanel();
                j4 = new JPanel();
                b1 = new JButton ("Get le Time!");
                t1 = new JTextField(10);
                //h4x0r
                minute = new ArrayList<Integer>();
                for (int i = 01; i <= 60; ++i)
                {
                        minute.add(i);
                }
                //shplit
                hour = new ArrayList<Integer>();
                for (int i = 1; i <= 12; ++i) {
                        hour.add(i); String.format("%05d", 2);
                }
                t2 = new JComboBox<>(hour.toArray(new Integer[0]));
                t3 = new JComboBox<>(minute.toArray(new Integer[0]));
                t4 = new JComboBox<>(new String[]{"AM", "PM"});
                j1 = new JPanel (new FlowLayout());
                l1 = new JLabel ("time in comic sans:");
                j1.add(l1);
                j1.add(t1);
                j2.add(b1);
                j4.add(t2);
                j4.add(t3);
                j4.add(t4);
                l1.setFont(new Font("Comic Sans MS",Font.PLAIN,20));
                t1.setFont(new Font("Comic Sans MS",Font.PLAIN,20));
                b1.setFont(new Font("Comic Sans MS",Font.PLAIN,20));
                Frame1.add(j1);
                Frame1.add(j2);
                Frame1.add(j4);
                Frame1.setLayout(new FlowLayout());
                Frame1.setSize(400,150);
                Frame1.setVisible(true);
                Frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                b1.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                                t1.setText(""+genericclass.twelveoclockfix + ":" + genericclass.minfixed + " " + genericclass.AMPMtxt);
                                System.out.println(t2.getSelectedItem());
                                JOptionPane.showMessageDialog(Frame1, "Le 9gag army waz h3r3!");
                        }
                });


        }
}

我试图让它从定义数字0-60的数组列表中进入JComboBox。

有人可以指出我在使单个数字之前有 0 的正确方向。

谢谢

4

1 回答 1

0

更改ArrayList<Integer> minuteArrayList<String> minute。此外,更改JComboBox<Integer> t3JComboBox<String> t3并添加如下分钟:

minute = new ArrayList<String>();
for (int i = 01; i <= 60; ++i)
{
    if (i < 10) {
        minute.add("0" + String.valueOf(i));
    } else {
        minute.add(String.valueOf(i));
    }
}
于 2013-07-04T15:07:38.870 回答