Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- final JTextField[] fields = new JTextField[3];
- for (int i = 0; i < fields.length; i++) {
- fields[i] = new JTextField("" + i);
- fields[i].setVisible(Boolean.TRUE);
- }
- JButton button = new JButton("Sum");
- button.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- Integer a = Integer.parseInt(fields[0].getText());
- Integer b = Integer.parseInt(fields[1].getText());
- Integer c = a + b;
- fields[2].setText(c.toString());
- } catch (Exception ex) {
- fields[2].setText("Error");
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment