?? shuru_chengji.java
字號:
package coursedesign;
import java.awt.*;
import javax.swing.*;
import java.awt.BorderLayout;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import com.borland.dx.sql.dataset.Database;
import com.borland.dx.sql.dataset.QueryDataSet;
import com.borland.dx.sql.dataset.QueryResolver;
import com.borland.dx.sql.dataset.ConnectionDescriptor;
import com.borland.dx.sql.dataset.Load;
import com.borland.dx.sql.dataset.QueryDescriptor;
import com.borland.dbswing.JdbTable;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import com.borland.dx.dataset.DataSetView;
import com.borland.javax.sql.JdbcDataSource;
import com.borland.datastore.DataStore;
import com.borland.dbswing.JdbNavToolBar;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class shuru_chengji
extends JFrame {
JButton jButton1 = new JButton();
XYLayout xYLayout1 = new XYLayout();
Database student = new Database();
QueryDataSet queryDataSet1 = new QueryDataSet();
QueryResolver queryResolver1 = new QueryResolver();
JdbTable jdbTable1 = new JdbTable();
JTextField jTextField1 = new JTextField();
JTextField jTextField2 = new JTextField();
JTextField jTextField3 = new JTextField();
JTextField jTextField4 = new JTextField();
JTextField jTextField5 = new JTextField();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JdbNavToolBar jdbNavToolBar1 = new JdbNavToolBar();
public shuru_chengji() {
try {
jbInit();
}
catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(xYLayout1);
this.getContentPane().setBackground(SystemColor.inactiveCaptionText);
setSize(new Dimension(500, 400));
setTitle("輸入成績");
jButton1.setText("輸入成績 ");
jButton1.addActionListener(new shuru_chengji_jButton1_actionAdapter(this));
student.setConnection(new ConnectionDescriptor(
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=student", "sa",
"zjxy2006", false, "com.microsoft.jdbc.sqlserver.SQLServerDriver"));
queryResolver1.setDatabase(student);
queryResolver1.setUpdateMode(com.borland.dx.dataset.UpdateMode.
CHANGED_COLUMNS);
queryDataSet1.setReadOnly(true);
queryDataSet1.setResolver(null);
queryDataSet1.setQuery(new QueryDescriptor(student,
"SELECT * FROM CHENGJIBIAO", null, true,
Load.ALL));
jdbTable1.setDataSet(queryDataSet1);
jTextField3.addActionListener(new shuru_chengji_jTextField3_actionAdapter(this));
jLabel1.setText("學號");
jLabel2.setText("姓名");
jLabel3.setText("課程名");
jLabel4.setText("分數");
jLabel5.setText("教師");
jdbNavToolBar1.setBackground(UIManager.getColor(
"InternalFrame.inactiveTitleForeground"));
this.getContentPane().add(jButton1, new XYConstraints(7, 6, -1, 27));
this.getContentPane().add(jdbTable1, new XYConstraints(4, 175, 496, 222));
this.getContentPane().add(jLabel1, new XYConstraints(43, 50, -1, -1));
this.getContentPane().add(jTextField1, new XYConstraints(107, 45, 72, -1));
this.getContentPane().add(jLabel2, new XYConstraints(260, 49, -1, -1));
this.getContentPane().add(jTextField2, new XYConstraints(320, 45, 82, -1));
this.getContentPane().add(jLabel4, new XYConstraints(178, 91, -1, -1));
this.getContentPane().add(jTextField3, new XYConstraints(82, 86, 64, -1));
this.getContentPane().add(jLabel3, new XYConstraints(16, 91, -1, -1));
this.getContentPane().add(jTextField4, new XYConstraints(229, 85, 71, -1));
this.getContentPane().add(jLabel5, new XYConstraints(329, 89, -1, -1));
this.getContentPane().add(jTextField5, new XYConstraints(385, 84, 71, -1));
this.getContentPane().add(jdbNavToolBar1, new XYConstraints(2, 137, 454, -1));
}
public static void main(String[] args) {
shuru_chengji shuru_chengji = new shuru_chengji();
}
public void jTextField3_actionPerformed(ActionEvent e) {
}
public void jButton1_actionPerformed(ActionEvent e) {
String Field1 = jTextField1.getText().trim();
String Field2 = jTextField2.getText().trim();
String Field3 = jTextField3.getText().trim();
String Field4 = jTextField4.getText().trim();
int re=Integer.parseInt(Field4);
String Field5 = jTextField5.getText().trim();
if (Field1.equals("") && Field2.equals("") && Field3.equals("") &&
Field4.equals("") && Field5.equals("")) {
JOptionPane.showMessageDialog(null, "請在下面的框內填寫出正確的內容");
}
else {
try {
Jdbcconn conn = new Jdbcconn(); //連接數據庫
conn.OpenConn("student", "sa", "zjxy2006");
String strSQL =
"insert into chengjibiao (id,name,course,result,teacher) values ('" +
Field1 + "','" + Field2 + "','" + Field3 + "','" + re + "','" +
Field5 + "')";
conn.executeUpdate(strSQL);
queryDataSet1.refresh();
JOptionPane.showMessageDialog(null, "成績輸入成功");
//System.out.println("name");
}
catch (Exception ex) {
System.out.println(ex.getMessage());
JOptionPane.showMessageDialog(null, "數據庫沒有鏈接成功,數據沒有輸入成功!");
} //end catch
}
} //end if
}
class shuru_chengji_jButton1_actionAdapter
implements ActionListener {
private shuru_chengji adaptee;
shuru_chengji_jButton1_actionAdapter(shuru_chengji adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class shuru_chengji_jTextField3_actionAdapter
implements ActionListener {
private shuru_chengji adaptee;
shuru_chengji_jTextField3_actionAdapter(shuru_chengji adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jTextField3_actionPerformed(e);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -