import javax.swing.*;
public class Hujia// extends JFrame
{
    static JFrame f1;
    JPanel p1;
    JButton b1;
    public  Hujia()
    {
    //, JFrame f1 = new JFrame;
        JPanel p1 = new JPanel();
        JButton b1 = new JButton("Submit");
        b1.setLabel("Cancel");
        f1.getContentPane().add(p1);
        f1.setSize(300,300);
        p1.add(b1);
        
        p1.add(p1);
    }
    public static void main(String arg[])
    {
        JFrame f1 = new JFrame("Sample Application");
        
        
    }
}这是改动后
提示是
Note: J:\ÖÜÓÂ\Hujia.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
同样可以编译通过

解决方案 »

  1.   

    b1.setLabel("Cancel");  //这个方法已经建议废弃查查jdk文档:
    setLabel
    public void setLabel(String label)
    Deprecated. - Replaced by setText(text) 这个方法已经Deprecated了,可以用setText来取代。如果你现在一定要用这个方法的话,编译的时候要加上-deprecation参数
    PS:其实出错信息已经提示的相当清楚了
      

  2.   

    加了f1.setVisiblie(true)
    b1.setTabel("Canbel");
    改成了
    b1.setText("Canbel");
    编译通过
    运行不报错
    但无界面输出
      

  3.   

    import javax.swing.*;
    public class Hujia// extends JFrame
    {
    static JFrame f1;
    JPanel p1;
    JButton b1;
    public  Hujia()
    {
    f1 = new JFrame("Sample Application");
    JPanel p1 = new JPanel();
    JButton b1 = new JButton("Submit");
    b1.setText("Cancel");
    f1.getContentPane().add(p1);
    f1.setSize(300,300);
    p1.add(b1);
            
    f1.setVisible(true);
    }
    public static void main(String arg[])
    {
    Hujia t = new Hujia();
    }
    }