JComboBox how to compute for two integers from two JComboBox and have the result in a JTextfield when clicking the JButton

后端 未结 3 527
盖世英雄少女心
盖世英雄少女心 2021-01-17 02:52

I have 2 JComboBox consisting of numbers combobox1= 1 to 5 and combobox2= 1 to 6.

and when I click my JButton, I

3条回答
  •  余生分开走
    2021-01-17 03:42

    use form.setVisible(true);

    then:

        btn.addActionListener(new ActionListener() {
    
            public void actionPerformed(ActionEvent e) {
                int cb1Int = Integer.parseInt(cb1.getSelectedItem().toString());
                int cb2Int = Integer.parseInt(cb2.getSelectedItem().toString());
                txt.setText(String.valueOf(cb1Int + cb2Int));
            }
        });
    

    Good luck with your homework. ;)

提交回复
热议问题