方法和按钮以Java连接

我正在尝试将按钮链接到方法,用户必须在其中输入名称,GPA和ID。 这是代码

在主要方法中:

btnAdd.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String name = txt2.getText();
                String ID = txt2.getText();
                String GPA = txt3.getText();
                addNewStudent();

            } });

同一类中的方法

public static void addNewStudent() {

        String name =

        String IDnum = scanner.nextLine();

        String GPA = scanner.nextLine();
        Student newStudent = Student.createStudent(name, IDnum, GPA);
        if (studentInfoSystem.addNewStudent(newStudent)) {
            System.out.println("New student added: name = " + name + ", ID = " + IDnum + " GPA: " + GPA);
        } else {
            System.out.println("Cannot add, " + name + " already on file");
        }
    }

我想知道如何连接它们。