?? result_manage.java~100~
字號(hào):
package coursedesign;
import java.awt.*;
import javax.swing.*;
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.dbswing.JdbTable;
import com.borland.dx.sql.dataset.Load;
import com.borland.dx.sql.dataset.QueryDescriptor;
import coursedesign.DM.entities.DM;
import com.borland.dbswing.JdbTextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import com.borland.dbswing.JdbNavToolBar;
import java.sql.ResultSet;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class result_manage
extends JFrame {
XYLayout xYLayout1 = new XYLayout();
JTextField jTextField1 = new JTextField();
JLabel jLabel1 = new JLabel();
JButton jButton1 = new JButton();
JdbTable jdbTable1 = new JdbTable();
JdbTextField jdbTextField1 = new JdbTextField();
JdbTextField jdbTextField2 = new JdbTextField();
JdbTextField jdbTextField3 = new JdbTextField();
JdbTextField jdbTextField4 = new JdbTextField();
JdbTextField jdbTextField5 = new JdbTextField();
JButton jButton4 = new JButton();
Database database1 = new Database();
QueryDataSet queryDataSet1 = new QueryDataSet();
QueryResolver queryResolver1 = new QueryResolver();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
public result_manage() {
try {
jbInit();
}
catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(xYLayout1);
this.getContentPane().setBackground(UIManager.getColor(
"InternalFrame.inactiveTitleForeground"));
setSize(new Dimension(500, 400));
setTitle("學(xué)生成績(jī)管理");
jLabel1.setText("學(xué)號(hào)");
jdbTable1.setDataSet(queryDataSet1);
jButton1.setText("查詢");
jButton1.addActionListener(new result_manage_jButton1_actionAdapter(this));
jButton4.setText("添加成績(jī)");
jButton4.addActionListener(new result_manage_jButton4_actionAdapter(this));
database1.setConnection(new ConnectionDescriptor(
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=student", "sa",
"yaya", false, "com.microsoft.jdbc.sqlserver.SQLServerDriver",
ConnectionDescriptor.arrayToProperties(new String[][] { {"serverName",
""}, {"hostProcess", ""},
{"user", "sa"}, {"netAddress",
""},
{"sendStringParametersAsUnicode ",
"true"}, {"programName", ""},
{"databaseName", "student"},
{"selectMethod", "direct"},
{"password", ""}, {"portNumber",
"1433"},
})));
queryDataSet1.setResolver(queryResolver1);
queryDataSet1.setQuery(new QueryDescriptor(database1,
"SELECT * FROM CHENGJIBIAO", null, true,
Load.ALL));
queryResolver1.setDatabase(database1);
queryResolver1.setUpdateMode(com.borland.dx.dataset.UpdateMode.
CHANGED_COLUMNS);
jdbTextField1.setColumnName("id");
jdbTextField1.setDataSet(queryDataSet1);
jdbTextField2.setColumnName("name");
jdbTextField2.setDataSet(queryDataSet1);
jLabel2.setText("學(xué)號(hào)");
jLabel3.setText("姓名");
jLabel4.setText("課程名");
jLabel5.setText("分?jǐn)?shù)");
jLabel6.setText("教師");
jdbTextField3.setColumnName("course");
jdbTextField3.setDataSet(queryDataSet1);
jdbTextField4.setColumnName("result");
jdbTextField4.setDataSet(queryDataSet1);
jdbTextField5.setColumnName("teacher");
jdbTextField5.setDataSet(queryDataSet1);
this.getContentPane().add(jdbTable1, new XYConstraints(1, 79, 496, 87));
this.getContentPane().add(jLabel2, new XYConstraints(15, 258, -1, -1));
this.getContentPane().add(jLabel5, new XYConstraints(24, 311, -1, -1));
this.getContentPane().add(jdbTextField3, new XYConstraints(386, 255, 85, -1));
this.getContentPane().add(jLabel4, new XYConstraints(335, 257, -1, -1));
this.getContentPane().add(jLabel3, new XYConstraints(176, 260, -1, -1));
this.getContentPane().add(jdbTextField1, new XYConstraints(69, 257, 88, -1));
this.getContentPane().add(jdbTextField4, new XYConstraints(70, 310, 90, -1));
this.getContentPane().add(jLabel6, new XYConstraints(204, 315, -1, -1));
this.getContentPane().add(jdbTextField2, new XYConstraints(223, 257, 96, -1));
this.getContentPane().add(jTextField1, new XYConstraints(140, 12, 81, -1));
this.getContentPane().add(jButton1, new XYConstraints(324, 11, -1, -1));
this.getContentPane().add(jButton4, new XYConstraints(58, 197, -1, -1));
this.getContentPane().add(jdbTextField5, new XYConstraints(253, 310, 97, -1));
this.getContentPane().add(jLabel1, new XYConstraints(76, 13, -1, -1));
// jLabel7.setIcon(b);
}
public static void main(String[] args) {
result_manage result_manage = new result_manage();
}
//***********************************添加成績(jī)事件**************************************
public void jButton4_actionPerformed(ActionEvent e)
{ String Field1=jdbTextField1.getText();
String Field3=jdbTextField3.getText();
String Field4=jdbTextField4.getText();
//String input;
//String result;
//JOptionPane.showMessageDialog(null,"請(qǐng)先輸入課程名,再輸入這門課程的成績(jī)!");
if(Field3.equals("") || Field4.equals(""))
{
JOptionPane.showMessageDialog(null,"請(qǐng)直接在下面的框內(nèi)輸入課程名和成績(jī)!");
//input = JOptionPane.showInputDialog("課程名:");
//result = JOptionPane.showInputDialog("分?jǐn)?shù):");
}else
{
try{
Jdbcconn conn = new Jdbcconn();
//連接數(shù)據(jù)庫
conn.OpenConn("student", "sa", "yaya");
String strSQL ="update chengjibiao set course='"+Field3+"','"+Field4+"'where id='"+Field1+"'";
conn.executeUpdate(strSQL);
//refreshComponent();
queryDataSet1.refresh();//有必要加哦,否則表格里不會(huì)顯加新加的信息
JOptionPane.showMessageDialog(null, "添加成功");
}//end try
catch(Exception ex)
{
JOptionPane.showMessageDialog(null, "Sorry!成績(jī)都已經(jīng)輸入");
}//end catch
}//end else
}
public void jButton3_actionPerformed(ActionEvent e) {
xiugaichengji xgcj=new xiugaichengji();
xgcj.setVisible(true);
}
//*******************查詢學(xué)生信息*******************************************
public void jButton1_actionPerformed(ActionEvent e) {
//得到用戶輸入的學(xué)號(hào)
String Field = jTextField1.getText().trim();
if (Field.equals("")) {
JOptionPane.showMessageDialog(null, "請(qǐng)輸入你要查的學(xué)生的學(xué)號(hào)");
} else {
try{//如果沒有找到記錄則會(huì)拋出異常。
//根據(jù)學(xué)號(hào)得到對(duì)應(yīng)的SQL語句;
String strSQL = "select * from chengjibiao where id='" + Field +"'";
//要將strSQL傳給queryDataSet1執(zhí)行,必須先關(guān)閉queryDataSet1
queryDataSet1.close();
//將SQL語句傳給queryDataSet1執(zhí)行。
queryDataSet1.setQuery(new QueryDescriptor(database1, strSQL, null, true,Load.ALL));
//將queryDataSet1打開
queryDataSet1.open();
//刷新queryDataSet1
queryDataSet1.refresh();
}catch(Exception ex)
{
//找不到結(jié)果時(shí),捕獲異常。
JOptionPane.showMessageDialog(null, "抱歉,沒有找到您要的記錄!");
//輸出異常結(jié)果
System.out.println("exception is:" + ex.getMessage());
}
} //end if else
}//此事件完成
}
class result_manage_jButton1_actionAdapter
implements ActionListener {
private result_manage adaptee;
result_manage_jButton1_actionAdapter(result_manage adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class result_manage_jButton4_actionAdapter
implements ActionListener {
private result_manage adaptee;
result_manage_jButton4_actionAdapter(result_manage adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton4_actionPerformed(e);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -