开发者

Components not initialized throwing NUllPointerException

开发者 https://www.devze.com 2023-03-23 22:03 出处:网络
Please help me figure out what is going wrong here? just starting out in java. public class PropertyChangeListenerTest {

Please help me figure out what is going wrong here? just starting out in java.

public class PropertyChangeListenerTest {
private JPanel mainPanel = null;
private JTextField source = null;
private JTextField target = null;

PropertyChangeListenerTest() {

    mainPanel = new JPanel();
    mainPanel.setLayout(new GridLayout(1, 0, 10, 0));
    source = new JTextField(20);
    target = new JTextField(20);
    mainPanel.add(source);
    mainPanel.add(target);

}

JPanel getMainPanel() {
    return mainPanel;
}

public static void main(String[] 开发者_如何学运维args) {
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            createAndShowGUI();
        }
    });
}

protected static void createAndShowGUI() {
    JFrame f = new JFrame("PropertyChangeListener");
    f.getContentPane().add(new PropertyChangeListenerTest().getMainPanel());
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.pack();
    f.setVisible(true);
}

}


No problem in this code. any way to run this code. means use cmd.

cmd combile command:

javac PropertyChangeListenerTest.java

java PropertyChangeListenerTest

0

精彩评论

暂无评论...
验证码 换一张
取 消