还有一个实例:
package bao; 
 
import java.awt.event.ActionEvent; 
import java.awt.event.ActionListener; 
import javax.swing.JButton; 
import javax.swing.JFrame; 
import javax.swing.JLabel; 
import javax.swing.JPanel; 
import javax.swing.JTextField; 
import javax.swing.border.EtchedBorder; 
import javax.swing.border.TitledBorder; 
 
import bao.Dao; 
 
public class StuIns extends JFrame { 
 
    private JTextField txtName; 
    private JTextField txtSex; 
    private JTextField txtPsw; 
    private JTextField txtAcc; 
    JLabel lblInfo; 
    /** 
     * Launch the application 
     * @param args 
     */ 
    public static void main(String args[]) { 
        try { 
            StuIns frame = new StuIns(); 
            frame.setVisible(true); 
        } catch (Exception e) { 
            e.printStackTrace(); 
        } 
    } 
 
    /** 
     * Create the frame 
     */ 
    public StuIns() { 
        super(); 
        getContentPane().setName(""); 
        getContentPane().setLayout(null); 
        setBounds(100, 100, 468, 464); 
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
 
        final JPanel panel = new JPanel(); 
        panel.setBorder(new TitledBorder(null, "插入", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null)); 
        panel.setLayout(null); 
        panel.setToolTipText("111"); 
        panel.setBounds(34, 37, 338, 369); 
        getContentPane().add(panel); 
 
        final JLabel lblAcc = new JLabel(); 
        lblAcc.setText("用户名"); 
        lblAcc.setBounds(57, 49, 60, 26); 
        panel.add(lblAcc); 
 
        final JLabel lblPsw = new JLabel(); 
        lblPsw.setText("密
  码"); 
        lblPsw.setBounds(57, 97, 60, 26); 
        panel.add(lblPsw); 
 
        final JLabel lblSex = new JLabel(); 
        lblSex.setText("性
  别"); 
        lblSex.setBounds(57, 141, 60, 26); 
        panel.add(lblSex); 
 
        final JLabel lblName = new JLabel(); 
        lblName.setText("姓
  名"); 
        lblName.setBounds(57, 192, 60, 26); 
        panel.add(lblName); 
 
        txtAcc = new JTextField(); 
        txtAcc.setBounds(123, 50, 165, 26); 
        panel.add(txtAcc); 
 
        txtPsw = new JTextField(); 
        txtPsw.setBounds(123, 98, 165, 26); 
        panel.add(txtPsw); 
 
        txtSex = new JTextField(); 
        txtSex.setBounds(123, 142, 165, 26); 
        panel.add(txtSex); 
 
        txtName = new JTextField(); 
        txtName.setBounds(123, 193, 165, 26); 
        panel.add(txtName); 
 
        final JButton btnIns = new JButton(); 
        btnIns.addActionListener(new ActionListener() { 
            public void actionPerformed(ActionEvent e) { 
                butInsertActionPerformed(e); 
            } 
        }); 
        btnIns.setText("插入"); 
        btnIns.setBounds(125, 262, 99, 34); 
        panel.add(btnIns); 
 
        final JLabel lblInfo = new JLabel(); 
        lblInfo.setBounds(125, 315, 99, 26); 
        panel.add(lblInfo); 
         
    } 
    protected void butInsertActionPerformed(ActionEvent e) { 
        Dao studao=new Dao(); 
        String stuAcc=this.txtAcc.getText(); 
        String stuPwd=this.txtPsw.getText(); 
        String stuSex=this.txtSex.getText(); 
        String stuName=this.txtName.getText(); 
        boolean b=studao.insert(stuAcc, stuPwd, stuSex, stuName); 
        if(b) 
        { 
             
            this.lblInfo.setText("插入ok"); 
        } 
        else 
        { 
             
            this.lblInfo.setText("插入NG"); 
        } 
         
    } 
}