ACM Interactors Freeze

前端 未结 1 380
谎友^
谎友^ 2020-11-30 15:21

I\'m trying to make a very simple program with Swing and ACM interactors. It is taken directly from a class handout, but does not function on my computer. When I run it, it

相关标签:
1条回答
  • 2020-11-30 15:53

    As a workaround, in addition to using Java 1.5, add the field to the NORTH. Also, you may want to extend GraphicsProgram.

    Modified SSCCE:

    import acm.program.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class TextFieldExample extends GraphicsProgram {
    
        @Override
        public void init() {
            nameField = new JTextField(15);
            add(new JLabel("Name: "), NORTH);
            add(nameField, NORTH);
            nameField.addActionListener(this);
        }
    
        @Override
        public void actionPerformed(ActionEvent e) {
            if (e.getSource() == nameField) {
                println("Hello, " + nameField.getText());
            }
        }
        private JTextField nameField;
    }
    
    0 讨论(0)
提交回复
热议问题