为什么会说--XLint:我在cmd中运行程序时的弃用?

时间:2018-02-26 23:48:19

标签: java applet javac deprecation-warning

我在通过窗口自己的cmd编译时遇到问题。

现在我得到的问题如下:

Note: ApplicationCentre.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

当我使用它编译时,我收到以下错误:

ApplicationCentre.java:7: warning: [deprecation] JApplet in javax.swing has been deprecated
public class ApplicationCentre extends JApplet implements ActionListener{

我的所有文件都在一个文件夹名称中:applicationCentre 该文件夹包含:ApplicationCentre.java和ApplicationCentre.html

代码发布在下面:

import java.awt.event.*;
import java.util.ArrayList;
import java.awt.*;
import javax.swing.*;

@SuppressWarnings("serial")
public class ApplicationCentre extends JApplet implements ActionListener{

    private static final long serialVersionUID = 1L;

    public ApplicationCentre() {
    }

    JTextField t1,t2;
    JLabel l3,l4;
    JButton b1,b2,b3,b4;
    String best = "";
    Student stu[];
    JScrollPane listScrollPane = new JScrollPane();
    String[] uni = {"Toronto","York","Western","Brock","Guelph","Waterloo","McGill","Concordia","Laval","Macmaster"};
    JList<?> uniList = new JList<Object>(uni);
    CardLayout cardManager = new CardLayout();
    JPanel cards = new JPanel(cardManager);
    int count = 0;
    Object[] values;
    String userName;
    int avgMark;
    ArrayList<String> nameList = new ArrayList<String>();
    ArrayList<String> markList = new ArrayList<String>();

    public void init() {

        //Added Buttons 
        stu = new Student[20];
        Container c = this.getContentPane();
        JPanel p1 = new JPanel();
        b1 = new JButton("Input");
        b2 = new JButton("Display All");
        b3 = new JButton("Search");
        b1.addActionListener(this);
        b2.addActionListener(this);
        b3.addActionListener(this);
        p1.setLayout(new GridLayout(3,1));
        p1.add(b1);
        p1.add(b2);
        p1.add(b3);
        c.add(p1, BorderLayout.WEST);

        //Added Labels, TextFields and JList 
        JPanel p2 = new JPanel();
        JLabel l1 = new JLabel("Enter Students Name. ");
        t1 = new JTextField();
        JLabel l2 = new JLabel("Enter Average Mark. ");
        t2 = new JTextField();
        JLabel l3 = new JLabel("From the List below choose 3 universities. ");  
        uniList.setVisibleRowCount(2);
        listScrollPane.setViewportView(uniList);
        b4 = new JButton("Submit");
        p2.setLayout(new GridLayout(0,1));
        p2.add(l1);
        p2.add(t1);
        p2.add(l2);
        p2.add(t2);
        p2.add(l3);
        p2.add(listScrollPane);
        p2.add(b4);
        c.add(p2, BorderLayout.EAST);       

        b4.addActionListener(this);     
    }


    public void actionPerformed(ActionEvent e) {        

        userName = t1.getText();
        avgMark = Integer.parseInt(t2.getText());
        values = uniList.getSelectedValuesList().toArray();
        if(e.getSource()==b4) {
            t1.setText(" ");
            t2.setText(" ");
            System.out.println(userName);
            System.out.println(avgMark);
            System.out.println(values);
        }       
    }
}

class Student {

    private String name;
    private int mark;

    protected String universityOne;
    protected String universityTwo;
    protected String universityThree;
    protected boolean universityOneAccept;
    protected boolean universityTwoAccept;
    protected boolean universityThreeAccept;

    public Student(String n, int m) {
        name = n;
        mark = m;

        this.universityOneAccept = false;
        this.universityTwoAccept = false;
        this.universityThreeAccept = false;
    }

    public void addUniversity(String name) {
        //When a university is added it doesn't mean that the user has 
        //accepted. So I set it to false. 
        this.addUniversity(name,false);
    }

    public void addUniversity(String name, boolean isAccepted) {
        //If the user does happen to selected one university then set the isAccepted to true. 
        //If the user selected more than 3 universities by chance then show the message "You have chosen over 3 universities.".
        if((this.universityOne == null) || (this.universityOne.equals(name))){
            this.universityOne = name;
            this.universityOneAccept = isAccepted;
        } else if ((this.universityTwo == null) || (this.universityTwo.equals(name))) {
            this.universityTwo = name;
            this.universityTwoAccept = isAccepted;
        } else if ((this.universityThree == null) || (this.universityThree.equals(name))) {
            this.universityThree = name;
            this.universityThreeAccept = isAccepted;
        } else {
            throw new RuntimeException("You have chosen over 3 universities.");
        }
    }

    //Getting the marks and the name of the user and setting them. 
    public String getName() {
        return name;
    }

    public int getMark() {
        return mark;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setMark(int mark) {
        this.mark = mark;
    }

    //The toString() method that will print what the user's name, mark and universities chosen 
    //The if statements will determine whether the user has accepted or rejected. 
    //The ? is pretty much the alternative of the if-else statement which i learned in high-school and off internet. 
    //It was just easy and simple to use. 
    //The : tells the computer to use the value if the condition is false
    //The ? tells the computer to use the value if the condition is true.

    public String toString() {
        String result = "Student [name=" + getName() + ",mark=" + getMark() +",universities=[";

        if(this.universityOne !=null)
            result += this.universityOne + ":" + (this.universityOneAccept ? "accepted" : "rejected");
        if(this.universityTwo !=null)
            result += this.universityTwo + ":" + (this.universityTwoAccept ? "accepted" : "rejected");
        if(this.universityThree !=null)
            result += this.universityThree + ":" + (this.universityThreeAccept ? "accepted" : "rejected");

        result += "]]";

        return result;
    }
}

HTML代码:

<html>
<applet CODE="ApplicationCentre.class" width=700 height=500>
</applet>
</html>

我知道错误发生在第7行,但我不知道如何修复它。

0 个答案:

没有答案