?? j_studentinsert.java
字號:
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.SystemColor;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
public class J_studentinsert extends JPanel {
private static final long serialVersionUID = 1L;
private JLabel jLabel = null;
private JLabel jLabel1 = null;
private JLabel jLabel11 = null;
private JLabel jLabel12 = null;
private JLabel jLabel13 = null;
private JTextField jtfxingming = null;
private JTextField jtfxuehao = null;
private JTextField jtfage = null;
private JTextField jtfaddress = null;
private JButton jButton = null;
private JButton jButton1 = null;
private JFileChooser jchose=null;
public static String m_stri=null;
private JLabel jLabel3 = null;
private JLabel jLabel4 = null;
private JTextField jtftelphone = null;
private JLabel jLabel2 = null;
private JRadioButton jrbman = null;
private JRadioButton jrbgirl = null;
private String m_sex=null;
/**
* This is the default constructor
*/
public J_studentinsert() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
jLabel4 = new JLabel();
jLabel4.setBounds(new Rectangle(27, 179, 63, 32));
jLabel4.setText("性別:");
jLabel3 = new JLabel();
jLabel3.setBounds(new Rectangle(291, 77, 141, 128));
jLabel3.setIcon(new ImageIcon("52065.gif"));
jLabel3.setText("照片");
jLabel13 = new JLabel();
jLabel13.setBounds(new Rectangle(24, 273, 71, 28));
jLabel13.setText("電話:");
jLabel12 = new JLabel();
jLabel12.setBounds(new Rectangle(25, 224, 65, 32));
jLabel12.setText("家庭住址:");
jLabel11 = new JLabel();
jLabel11.setBounds(new Rectangle(27, 137, 66, 29));
jLabel11.setText("年齡:");
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(26, 99, 66, 26));
jLabel1.setText("學號:");
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(26, 61, 68, 28));
jLabel.setText("姓名:");
this.setSize(465, 367);
this.setLayout(null);
this.setBackground(SystemColor.activeCaption);
this.add(jLabel, null);
this.add(jLabel1, null);
this.add(jLabel11, null);
this.add(jLabel12, null);
this.add(jLabel13, null);
this.add(getJtfxingming(), null);
this.add(getJtfxuehao(), null);
this.add(getJtfage(), null);
this.add(getJtfaddress(), null);
this.add(getJButton(), null);
this.add(getJButton1(), null);
this.add(jLabel3, null);
this.add(jLabel4, null);
this.add(getJtftelphone(), null);
this.add(getJLabel2(), null);
this.add(getJrbman(), null);
this.add(getJrbgirl(), null);
ImageIcon ic=new ImageIcon("shui.jpg");
JLabel jbl=new JLabel();
jbl.setIcon(ic);
jbl.setBounds(new Rectangle(0, 1, 466, 366));
this.setOpaque(false);
this.add(jbl, null);
}
/**
* This method initializes jtfxingming
*
* @return javax.swing.JTextField
*/
private JTextField getJtfxingming() {
if (jtfxingming == null) {
jtfxingming = new JTextField();
jtfxingming.setBounds(new Rectangle(103, 57, 158, 31));
}
return jtfxingming;
}
/**
* This method initializes jtfxuehao
*
* @return javax.swing.JTextField
*/
private JTextField getJtfxuehao() {
if (jtfxuehao == null) {
jtfxuehao = new JTextField();
jtfxuehao.setBounds(new Rectangle(104, 103, 157, 30));
}
return jtfxuehao;
}
/**
* This method initializes jtfage
*
* @return javax.swing.JTextField
*/
private JTextField getJtfage() {
if (jtfage == null) {
jtfage = new JTextField();
jtfage.setBounds(new Rectangle(102, 137, 157, 30));
}
return jtfage;
}
/**
* This method initializes jtfaddress
*
* @return javax.swing.JTextField
*/
private JTextField getJtfaddress() {
if (jtfaddress == null) {
jtfaddress = new JTextField();
jtfaddress.setBounds(new Rectangle(103, 222, 163, 31));
}
return jtfaddress;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton()
{
if (jButton == null)
{
jButton = new JButton();
jButton.setBounds(new Rectangle(354, 207, 77, 28));
jButton.setText("瀏覽");
jButton.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
try
{
jchose=new JFileChooser();
int n=jchose.showOpenDialog(null);
m_stri=jchose.getSelectedFile().getName();
if(n==0)
{
jLabel3.setIcon(new ImageIcon(m_stri));
jLabel3.setVisible(true);
}
}
catch (Exception e1)
{}
}
});
}
return jButton;
}
/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButton1()
{
if (jButton1 == null)
{
jButton1 = new JButton();
jButton1.setBounds(new Rectangle(328, 331, 106, 32));
jButton1.setText("添加");
jButton1.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
try
{
if(!jtfxingming.getText().isEmpty()&&!jtfxuehao.getText().isEmpty())
{
if(jrbman.isSelected()==true)
{
m_sex="男";
}
else
{
m_sex="女";
}
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("jdbc:odbc:studentSqlDatabase","sa","");
Statement s=c.createStatement();
s.executeUpdate("insert into "+J_Denglu.m_strbanji+"(姓名,學號,年齡,性別,家庭住址,電話,照片) values('"+
jtfxingming.getText() +"','"+jtfxuehao.getText() +"','"+
jtfage.getText() +"','"+m_sex +"','"+jtfaddress.getText() +"','"+
jtftelphone.getText() +"','"+m_stri+"')");
s.close();
c.close();
System.out.println("添加成功!");
JOptionPane.showMessageDialog(null,"添加成功!");
}
else
JOptionPane.showMessageDialog(null,"請輸入姓名和學號!");
}
catch(Exception e1)
{
System.err.println("異常"+e1.getMessage());
JOptionPane.showMessageDialog(null,e1.getMessage());
}
}
});
}
return jButton1;
}
/**
* This method initializes jtftelphone
*
* @return javax.swing.JTextField
*/
private JTextField getJtftelphone() {
if (jtftelphone == null) {
jtftelphone = new JTextField();
jtftelphone.setBounds(new Rectangle(105, 271, 167, 28));
}
return jtftelphone;
}
/**
* This method initializes jLabel2
*
* @return javax.swing.JLabel
*/
private JLabel getJLabel2() {
if (jLabel2 == null) {
jLabel2 = new JLabel();
jLabel2.setText("請填寫學生基本信息");
jLabel2.setFont(new Font("Dialog", Font.BOLD, 18));
jLabel2.setBounds(new Rectangle(151, 15, 182, 27));
}
return jLabel2;
}
/**
* This method initializes jrbman
*
* @return javax.swing.JRadioButton
*/
private JRadioButton getJrbman() {
if (jrbman == null) {
jrbman = new JRadioButton();
jrbman.setBounds(new Rectangle(106, 178, 60, 32));
jrbman.setText("男");
jrbman.setSelected(true);
}
return jrbman;
}
/**
* This method initializes jrbgirl
*
* @return javax.swing.JRadioButton
*/
private JRadioButton getJrbgirl() {
if (jrbgirl == null) {
jrbgirl = new JRadioButton();
jrbgirl.setBounds(new Rectangle(203, 179, 57, 30));
jrbgirl.setText("女");
ButtonGroup btg=new ButtonGroup();
btg.add(jrbman);
btg.add(jrbgirl);
}
return jrbgirl;
}
} // @jve:decl-index=0:visual-constraint="10,10"
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -