LabelTest4 application = new LabelTest4();程序完全正常!!

解决方案 »

  1.   

    没有什么不妥之处啊?是不是JDK版本的问题???import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;/**
     * <p>Title: </p>
     *
     * <p>Description: </p>
     *
     * <p>Copyright: Copyright (c) 2002</p>
     *
     * <p>Company: </p>
     *
     * @author not attributable
     * @version 1.0
     */
    public class Frame1 extends JFrame
    {
        private JLabel label1;
        private JButton bt;
        public Frame1()
        {
            super("Testing JLabel");
            Container container = getContentPane();
            container.setLayout(new FlowLayout());
            label1 = new JLabel("Label with text");        container.add(label1);        bt = new JButton("开始测试");
            container.add(bt);
            bt.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    System.out.println("开始测试了");
                }
            }
            );        setSize(275,170);
            setVisible(true);
        } // end constructor    public static void main(String args[])
        {
            Frame1 application = new Frame1();
            application.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        }
    }