?? stugradeinput.java
字號:
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import java.awt.*;
import java.awt.event.*;
import java.sql.ResultSet;
import java.sql.SQLException;
public class StuGradeInput extends JFrame implements ActionListener{
DataBaseManager db = new DataBaseManager();
ResultSet rs;
JList jList1;
JLabel jLabel4;
JComboBox jComboBox4;
JLabel jLabel6;
JComboBox jComboBox3;
JLabel jLabel2;
JComboBox jComboBox2;
JComboBox jComboBox1;
JTextField jTextField5;
JLabel jLabel3;
JButton jButton2;
JButton jButton1;
JLabel jLabel5;
JTextField jTextField1;
JLabel jLabel1;
public StuGradeInput (){
this.setBounds(431, 223, 386, 315);
this.setVisible(true);
this.setLayout(null);
this.setTitle("錄入學生科目成績");
this.setResizable(false);
{
jLabel1 = new JLabel();
getContentPane().add(jLabel1);
jLabel1.setText("學號:");
jLabel1.setBounds(41, 30, 50, 21);
}
{
jTextField1 = new JTextField();
getContentPane().add(jTextField1);
jTextField1.setText("");
jTextField1.setBounds(119, 27, 136, 27);
}
{
jLabel4 = new JLabel();
getContentPane().add(jLabel4);
jLabel4.setText("科目名稱:");
jLabel4.setBounds(35, 150, 71, 23);
}
{
jLabel5 = new JLabel();
getContentPane().add(jLabel5);
jLabel5.setText("成績:");
jLabel5.setBounds(36, 196, 48, 21);
}
{
jTextField5 = new JTextField();
getContentPane().add(jTextField5);
jTextField5.setText("" );
jTextField5.setBounds(119, 194, 136, 25);
}
{
jButton1 = new JButton();
jButton1.addActionListener(this);
getContentPane().add(jButton1);
jButton1.setText("錄入");
jButton1.setBounds(286, 28, 71, 25);
}
{
jButton2 = new JButton();
jButton2.addActionListener(this);
getContentPane().add(jButton2);
jButton2.setText("關閉");
jButton2.setBounds(286, 79, 71, 27);
}
{
jLabel3 = new JLabel();
getContentPane().add(jLabel3);
jLabel3.setText("課程編號:");
jLabel3.setBounds(35, 79, 56, 19);
}
{
ComboBoxModel jComboBox1Model =
new DefaultComboBoxModel(
new String[] { "java程序設計", "日語" ,"操作系統","專業英語","體育","數據庫" });
jComboBox1 = new JComboBox();
getContentPane().add(jComboBox1);
jComboBox1.setModel(jComboBox1Model);
jComboBox1.setBounds(119, 147, 136, 29);
}
{
ComboBoxModel jComboBox2Model =
new DefaultComboBoxModel(
new String[] { "1", "2" ,"3","4","5","6"});
jComboBox2 = new JComboBox();
getContentPane().add(jComboBox2);
jComboBox2.setModel(jComboBox2Model);
jComboBox2.setBounds(119, 66, 136, 26);
}
{
jLabel2 = new JLabel();
getContentPane().add(jLabel2);
jLabel2.setText("學期名稱:");
jLabel2.setBounds(35, 117, 56, 15);
}
{
ComboBoxModel jComboBox3Model =
new DefaultComboBoxModel(
new String[] { "2008-2009上學期", "2008-2009下學期" });
jComboBox3 = new JComboBox();
getContentPane().add(jComboBox3);
jComboBox3.setModel(jComboBox3Model);
jComboBox3.setBounds(119, 104, 136, 28);
}
{
jLabel6 = new JLabel();
getContentPane().add(jLabel6);
jLabel6.setText("等級:");
jLabel6.setBounds(36, 238, 42, 15);
}
{
ComboBoxModel jComboBox4Model =
new DefaultComboBoxModel(
new String[] { "合格", "不合格" });
jComboBox4 = new JComboBox();
getContentPane().add(jComboBox4);
jComboBox4.setModel(jComboBox4Model);
jComboBox4.setBounds(119, 235, 136, 24);
}
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==jButton2){
this.dispose();
}
else if(e.getSource()==jButton1)
{
try
{
String strSQL="select * from cj where 學號='"+
jTextField1.getText().trim()+"'";
if(jTextField1.getText().trim().equals(""))
{
JOptionPane.showMessageDialog(null,"學號不能為空!");
}
else if(jTextField5.getText().trim().equals(""))
{
JOptionPane.showMessageDialog(null,"成績不能為空!");
}
else
{
if(db.getResult(strSQL).absolute(6));
strSQL="insert into cj (學號,課程編號,學期名稱,科目名稱,成績,等級) values ('"+jTextField1.getText().trim()+"','" +jComboBox2.getSelectedItem()+"','" +jComboBox3.getSelectedItem()+"'," +
"'" +jComboBox1.getSelectedItem()+"','"+jTextField5.getText().trim()+"','" +jComboBox4.getSelectedItem()+"')";
if(db.updateSql(strSQL))
{
int result=JOptionPane.showOptionDialog(null, "當前學號的成績錄入完畢是否要繼續輸入其他學生的成績?", "系統提示", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] {"是","否"}, "否");
if(result==JOptionPane.YES_OPTION){
new StuGradeInput();
this.dispose();
}
else{
db.closeConnection();
this.dispose();
}
}
else {
JOptionPane.showMessageDialog(null,"此學號的成績已經錄入,請重新錄入其他學生的成績!");
this.dispose();
}
}
}
catch(SQLException sqle)
{
System.out.println(sqle.toString());
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -