?? inputgrade.java~189~
字號:
package xscjgl;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import java.awt.Color;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JTextField;
import javax.swing.JButton;
import com.borland.dbswing.JdbTextField;
import com.borland.dbswing.TableScrollPane;
import com.borland.dbswing.JdbTable;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.ResultSet;
import javax.swing.JOptionPane;
import java.awt.Dimension;
import com.borland.dx.sql.dataset.QueryDescriptor;
import com.borland.dx.sql.dataset.Load;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class inputGrade extends JFrame {
XYLayout xYLayout2 = new XYLayout();
JPanel jPanel1 = new JPanel();
JLabel jLabel1 = new JLabel();
JComboBox jComboBox1 = new JComboBox();
JPanel jPanel2 = new JPanel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JTextField jTextField1 = new JTextField();
JButton jButton1 = new JButton();
JdbTextField jdbTextField1 = new JdbTextField();
JdbTextField jdbTextField2 = new JdbTextField();
TableScrollPane tableScrollPane1 = new TableScrollPane();
XYLayout xYLayout3 = new XYLayout();
JLabel jLabel5 = new JLabel();
JdbTable jdbTable1 = new JdbTable();
DataModule1 dataModule11 = new DataModule1();
public String Cno;
JButton jButton2 = new JButton();
public inputGrade() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
dataModule11 = DataModule1.getDataModule();
getContentPane().setLayout(xYLayout2);
jPanel2.setBackground(new Color(236, 233, 255));
jPanel2.setLayout(xYLayout3);
jLabel2.setText("當前選擇的學生信息是:");
jLabel2.setBounds(new Rectangle(35, 31, 164, 15));
xYLayout2.setWidth(424);
xYLayout2.setHeight(362);
jLabel3.setText("學號:");
jLabel3.setBounds(new Rectangle(35, 54, 49, 15));
jLabel4.setText("姓名:");
jLabel4.setBounds(new Rectangle(213, 53, 47, 15));
jTextField1.setToolTipText("");
jTextField1.setBounds(new Rectangle(116, 82, 77, 20));
jButton1.setBounds(new Rectangle(217, 81, 68, 23));
jButton1.setText("提交");
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
jdbTextField1.setColumnName("Sno");
jdbTextField1.setDataSet(dataModule11.getStudent());
jdbTextField1.setBounds(new Rectangle(85, 51, 102, 20));
jdbTextField1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jdbTextField1_actionPerformed(e);
}
});
jdbTextField2.setColumnName("Sname");
jdbTextField2.setDataSet(dataModule11.getStudent());
jdbTextField2.setBounds(new Rectangle(264, 49, 93, 20));
jLabel5.setText("請輸入成績:");
jLabel5.setBounds(new Rectangle(35, 85, 91, 15));
jdbTable1.setDataSet(dataModule11.getStudent());
jComboBox1.setBounds(new Rectangle(139, 0, 100, 23));
jComboBox1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jComboBox1_actionPerformed(e);
}
});
jLabel1.setBounds(new Rectangle(35, 6, 95, 15));
jButton2.setBounds(new Rectangle(301, 81, 81, 23));
jButton2.setText("退出");
jButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton2_actionPerformed(e);
}
});
tableScrollPane1.getViewport().add(jdbTable1);
this.getContentPane().add(jPanel1, new XYConstraints( -1, 6, 425, 140));
jPanel1.add(jLabel3, null);
jPanel1.add(jLabel1, null);
jPanel1.add(jLabel2, null);
jPanel1.add(jLabel5, null);
jPanel1.add(jLabel4, null);
jPanel1.add(jdbTextField2, null);
jPanel1.add(jComboBox1, null);
jPanel1.add(jdbTextField1, null);
jPanel1.add(jTextField1, null);
jPanel1.add(jButton1, null);
jPanel1.add(jButton2);
jPanel2.add(tableScrollPane1, new XYConstraints(6, 10, 387, 128));
this.getContentPane().add(jPanel2, new XYConstraints(10, 165, 404, 161));
jPanel1.setLayout(null);
jLabel1.setText("請選擇課程:");
jPanel1.setBackground(new Color(236, 233, 255));
}
public void jComboBox1_actionPerformed(ActionEvent e) {
String Cname=String.valueOf(jComboBox1.getSelectedItem().toString());
try {
Jdbcconn conn = new Jdbcconn();
conn.OpenConn("tqti", "tqti", "111111");
ResultSet rs = conn.getResults("select Cno from Course where Cname='"+Cname+"'");
rs.first();
Cno=rs.getString("Cno");
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "catch first");
} //end try catch
String courseSQL = "select * from queryGrade where Cno='"+Cno+"'";
try {
dataModule11.Query.close();
dataModule11.Query.setQuery(new QueryDescriptor(dataModule11.database1,courseSQL, null, true, Load.ALL));
dataModule11.Query.open();
dataModule11.Query.refresh();
//jdbTable
jdbTextField1.setColumnName("Sno");
jdbTextField2.setColumnName("Sname");
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "catch last!");
} //end try catch
}
public void jButton1_actionPerformed(ActionEvent e) {
String inputGrade=jTextField1.getText().trim().toString();
try{
float grade = Float.parseFloat(inputGrade);
if(grade>100||grade<0){
JOptionPane.showMessageDialog(null, "您的輸入有誤,請重新輸入!");
jTextField1.setText("");
}else{
try {
Jdbcconn conn = new Jdbcconn();
conn.OpenConn("tqti", "tqti", "111111");
String gradeSQL="update SC set Cgrade='"+grade+"' where Sno='"+jdbTextField1.getText().trim()+"'and Cno='"+Cno+"'";
conn.executeUpdate(gradeSQL);
JOptionPane.showMessageDialog(null, "成績輸入成功!");
dataModule11.Query.refresh();
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "成績輸入出錯!");
} //end try catch
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "您的輸入有誤,請重新輸入!");
jTextField1.setText("");
} //end try catch
}
public void jButton2_actionPerformed(ActionEvent e) {
this.dispose();
}
public static void main(String[] args) {
inputGrade inputgrade = new inputGrade();
inputgrade.setVisible(true);
inputgrade.setLocationRelativeTo(null);
inputgrade.setSize(new Dimension(425,390));
Jdbcconn conn = new Jdbcconn();
String strsql="select * from Course";
try {
conn.OpenConn("tqti", "tqti", "111111");
ResultSet cs= conn.getResults(strsql);
cs.beforeFirst();
while(cs.next()){
inputgrade.jComboBox1.addItem(cs.getString("Cname"));
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "catch first");
} //end try catch
}
public void jdbTextField1_actionPerformed(ActionEvent e) {
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -