You problem is that you insert your code to wrong place and you use a wrong type of button.Try this:import java.awt.*;
import javax.swing.*;
import java.lang.*;
import java.awt.event.*;class Dialog extends JFrame
{
public Dialog()
{
setSize(300,200);
setTitle("插入数据");
getContentPane().setLayout(new BorderLayout());
JPanel panel= new JPanel();
panel.setLayout(new GridLayout(3,2)); panel.add(new JLabel("学号"));
JTextField username= new JTextField("Number",10);
    panel.add(username); panel.add(new JLabel("学生名"));
JTextField Password=new JTextField("Name",10);
panel.add(Password); panel.add(new JLabel("课程名"));
JTextField sss=new JTextField("ClassName",10);
panel.add(sss); getContentPane().add(panel,BorderLayout.CENTER);
         
         //Should be here!!!!!
JPanel buttonPanel = new JPanel();
         //JButton okButton = new Button("OK"); This is a wrong type of "Button" ,should be the following code.
JButton okButton = new JButton("OK");
JButton cancelButton = new JButton("cancel"); buttonPanel.add(okButton);
buttonPanel.add(cancelButton); getContentPane().add(buttonPanel,BorderLayout.SOUTH); }
public static void main(String[] args)
{
JFrame xxx=new Dialog(); xxx.show();
} //加入一段Should not be here!!!!!!
private  JTextField username;
private     JTextField Password;
}