我在编写一个名为LogFrame.java的程序后,编译没有出错,也可以运行,但是编译有两行提示:
Note:   LogFrame.java   uses   or   overrides   a   deprecated   API.
Note:   Recompile   with-deprecation   for   details.
用javac   LogFrame.java   -deprecation
提示错误行是:password=jPasswordField.getText();
我要怎么改才能正常运行阿
谢谢了,请大侠帮帮我

解决方案 »

  1.   

    package app;import java.awt.*;
    import com.borland.jbcl.layout.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.sql.*;
    import java.lang.Object;/**
     * <p>Title: 个人日常事务管理系统</p>
     * <p>Description: 用于个人管理</p>
     * <p>Copyright: Copyright (c) 2003</p>
     * <p>Company: </p>
     * @author unascribed
     * @version 1.0
     */public class LogFrame extends JFrame {
      private XYLayout xYLayout1 = new XYLayout();
      private JLabel jLabel_name = new JLabel();
      private JLabel jLabel_password = new JLabel();
      private JTextField jTextField_name = new JTextField();
      private JLabel jLabel1 = new JLabel();
      private JPasswordField jPasswordField = new JPasswordField();
      private JButton jButton1 = new JButton();
      private JButton jButton2 = new JButton();
      protected String user,password,password_from;
      AppFrame frame;
      public LogFrame(AppFrame frame1) {
        frame = frame1;
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      private void jbInit() throws Exception {
        this.setTitle("登录窗口");
        this.getContentPane().setLayout(xYLayout1);
        jLabel_name.setFont(new java.awt.Font("Dialog", 0, 14));
        jLabel_name.setText("请输入用户名:");
        jLabel_password.setFont(new java.awt.Font("Dialog", 0, 14));
        jLabel_password.setText("请输入密码:");
        jLabel1.setFont(new java.awt.Font("Dialog", 0, 16));
        jLabel1.setText("个 人 日 常 事 务 管 理 系 统");
        jButton1.setFont(new java.awt.Font("Dialog", 0, 14));
        jButton1.setText("确    认");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            jButton1_actionPerformed(e);
          }
        });
        jButton2.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            jButton2_actionPerformed(e);
          }
        });
        jButton2.setText("取    消");
        jButton2.setFont(new java.awt.Font("Dialog", 0, 14));
        jTextField_name.addFocusListener(new java.awt.event.FocusAdapter() {
          public void focusLost(FocusEvent e) {
            jTextField_name_focusLost(e);
          }
        });
        jPasswordField.addFocusListener(new java.awt.event.FocusAdapter() {
          public void focusLost(FocusEvent e) {
            jPasswordField_focusLost(e);
          }
        });
        this.getContentPane().add(jLabel_password, new XYConstraints(52, 148, 91, 28));
        this.getContentPane().add(jLabel_name, new XYConstraints(51, 101, 99, -1));
        this.getContentPane().add(jTextField_name, new XYConstraints(160, 95, 155, 28));
        this.getContentPane().add(jLabel1,  new XYConstraints(84, 20, 220, 38));
        this.getContentPane().add(jPasswordField,  new XYConstraints(159, 143, 156, 32));
        this.getContentPane().add(jButton1, new XYConstraints(77, 205, 88, 33));
        this.getContentPane().add(jButton2,    new XYConstraints(218, 206, 88, 33));
      }  void jButton2_actionPerformed(ActionEvent e) {
       System.exit(0);
      }  void jTextField_name_focusLost(FocusEvent e) {  }  void jPasswordField_focusLost(FocusEvent e) {
    password = jPasswordField.getText();
      }  void jButton1_actionPerformed(ActionEvent e) {
                     Connection con;
                     String url="jdbc:odbc:grrc";
                     Statement stmt;
                     user = jTextField_name.getText();
                     try{
                             Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                             con=DriverManager.getConnection(url,"","");
                             String sql="SELECT PASSWORD from sys_safe where NAME ='"+user+"'";
                             stmt=con.createStatement();
                             ResultSet rs=stmt.executeQuery(sql);
                             if(rs.next())
                               password_from =  rs.getString("PASSWORD");
                               if(password_from.endsWith(password)){
                                 JOptionPane.showMessageDialog(this,"密码正确!","登录信息",JOptionPane.INFORMATION_MESSAGE);
                               this.setVisible(false);
                               frame.setVisible(true);
                               Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
                               int h = screenSize.height;
                               int w = screenSize.width;
                               frame.setSize(w,h);
                               Dimension frameMainSize = frame.getSize();
                               // Center the Window
                               if (frameMainSize.height > screenSize.height) {
                                 frameMainSize.height = screenSize.height;
                                }
                               if (frameMainSize.width > screenSize.width) {
                                 frameMainSize.width = screenSize.width;
                                }
                                 frame.setLocation((screenSize.width - frameMainSize.width) / 2, (screenSize.height - frameMainSize.height) / 2);
                               }
                               else{
                                 JOptionPane.showMessageDialog(this,"密码和用户名不符,请重新输入密码!","登录信息",JOptionPane.INFORMATION_MESSAGE);
                               }
                             con.close();
                     }catch(Exception ex){
                             System.out.println("A problem occurred during the establishment of th connection: "+ex);
                           }      }}
      

  2.   

    jPasswordField.getText()从JDK1.2版本以后已经废除,用getPassword()方法替换,getPassword()方法返回的是char[]
    其实不改也没关系,这个只是个Warning,程序还是可以运行的
      

  3.   

    java中一部分API的功能已经由新的API去实现了,你的程序中使用了一些过时的API,所以编译器会有提示