📄 jisuan.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.sql.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.table.*;
import java.sql.ResultSet;
import java.io.*;
///计算综合测评
///////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
class jisuan extends JFrame implements ActionListener {
private JLabel lbl7=new JLabel("学 号:");
private JLabel lbl1=new JLabel("姓 名:");
private JLabel lbl2=new JLabel("高等数学:");
private JLabel lbl4=new JLabel("大学物理:");
private JLabel lbl3=new JLabel("大学英语:");
private JLabel lbl5=new JLabel("VB :");
private JLabel lbl6=new JLabel("VC :");
private JLabel lbl8=new JLabel("智育成绩:");
private JLabel lbl9=new JLabel("加 分:");
private JLabel lbl10=new JLabel("减 分:");
private JLabel lbl11=new JLabel("综合测评成绩:");
private JTextField stid=new JTextField(10);
private JTextField stname=new JTextField(10);
private JTextField gaoshu=new JTextField(10);
private JTextField wuli=new JTextField(10);
private JTextField yingyu=new JTextField(10);
private JTextField vb=new JTextField(10);
private JTextField vc=new JTextField(10);
private JTextField zhiyu=new JTextField(10);
private JTextField jiafen=new JTextField(10);
private JTextField jianfen=new JTextField(10);
private JTextField zonghe=new JTextField(10);
private JButton jisuan=new JButton("计算");
private JButton up=new JButton("上一条");
private JButton next=new JButton("下一条");
int i=0;
String xh="";
String xm="";
String gs="";
String wl="";
String yy="";
String VB="";
String VC="";
String zy="";
String jia="";
String jian="";
String zh="";
Connection con;
Statement stmt;
ResultSet rs;
public jisuan(){
setTitle("计算综合测评");
stid.setEditable(false);
stname.setEditable(false);
gaoshu.setEditable(false);
wuli.setEditable(false);
yingyu.setEditable(false);
vb.setEditable(false);
vc.setEditable(false);
jiafen.setEditable(false);
jianfen.setEditable(false);
Font f=new Font("宋体",Font.PLAIN,12);
///this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().setLayout(null);
lbl7.setBounds(30,30,80,25);
lbl7.setFont(f);
getContentPane().add(lbl7);
stid.setBounds(100,30,100,25);
stid.setBorder(BorderFactory.createLineBorder(Color.black));
getContentPane().add(stid);
lbl1.setBounds(30,70,80,25);
lbl1.setFont(f);
getContentPane().add(lbl1);
stname.setBounds(100,70,100,25);
stname.setBorder(BorderFactory.createLineBorder(Color.black));
getContentPane().add(stname);
lbl2.setBounds(230,30,80,25);
lbl2.setFont(f);
getContentPane().add(lbl2);
gaoshu.setBounds(300,30,100,25);
gaoshu.setBorder(BorderFactory.createLineBorder(Color.black));
getContentPane().add(gaoshu);
lbl3.setBounds(30,110,80,25);
lbl3.setFont(f);
getContentPane().add(lbl3);
wuli.setBounds(300,70,100,25);
wuli.setBorder(BorderFactory.createLineBorder(Color.black));
getContentPane().add(wuli);
lbl4.setBounds(230,70,80,25);
lbl4.setFont(f);
getContentPane().add(lbl4);
yingyu.setBounds(100,110,100,25);
yingyu.setBorder(BorderFactory.createLineBorder(Color.black));
getContentPane().add(yingyu);
lbl5.setBounds(30,150,80,25);
lbl5.setFont(f);
getContentPane().add(lbl5);
vb.setBounds(100,150,100,25);
vb.setBorder(BorderFactory.createLineBorder(Color.black));
getContentPane().add(vb);
lbl9.setBounds(30,190,80,25);
lbl9.setFont(f);
getContentPane().add(lbl9);
jiafen.setBounds(100,190,100,25);
jiafen.setBorder(BorderFactory.createLineBorder(Color.black));
getContentPane().add(jiafen);
lbl6.setBounds(230,110,80,25);
lbl6.setFont(f);
getContentPane().add(lbl6);
zhiyu.setBounds(300,150,100,25);
zhiyu.setBorder(BorderFactory.createLineBorder(Color.black));
getContentPane().add(zhiyu);
lbl8.setBounds(230,150,80,25);
lbl8.setFont(f);
getContentPane().add(lbl8);
jianfen.setBounds(300,190,100,25);
jianfen.setBorder(BorderFactory.createLineBorder(Color.black));
getContentPane().add(jianfen);
lbl10.setBounds(230,190,80,25);
lbl10.setFont(f);
getContentPane().add(lbl10);
vc.setBounds(300,110,100,25);
vc.setBorder(BorderFactory.createLineBorder(Color.black));
getContentPane().add(vc);
lbl11.setBounds(30,240,180,25);
lbl11.setFont(new Font("宋体",Font.PLAIN,20));
getContentPane().add(lbl11);
zonghe.setBounds(200,240,130,25);
zonghe.setBorder(BorderFactory.createLineBorder(Color.black));
getContentPane().add(zonghe);
//按钮
jisuan.setBounds(110,270,60,25);
jisuan.setFont(f);
jisuan.setBorder(BorderFactory.createRaisedBevelBorder());
getContentPane().add(jisuan);
up.setBounds(190,270,60,25);
up.setFont(f);
up.setBorder(BorderFactory.createRaisedBevelBorder());
getContentPane().add(up);
next.setBounds(270,270,60,25);
next.setFont(f);
next.setBorder(BorderFactory.createRaisedBevelBorder());
getContentPane().add(next);
up.addActionListener(this);
next.addActionListener(this);
jisuan.addActionListener(this);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-403)/2, (screenSize.height-329)/2, 460,350);
//setSize(460,350);
//this.setClosable(true);
setVisible(true);
this.connection();
}
public double jisuankcjd(double a)
{
double f=0.0;
if(a>=90&&a<=100)
f=4.0;
if(a>=85&&a<90)
f=3.7;
if(a>=82&&a<85)
f=3.3;
if(a>=78&&a<82)
f=3.0;
if(a>=75&&a<78)
f=2.7;
if(a>=72&&a<75)
f=2.3;
if(a>=68&&a<72)
f=2.0;
if(a>=66&&a<68)
f=1.7;
if(a>=64&&a<66)
f=1.3;
if(a>=60&&a<64)
f=1.3;
if(a<60)
f=1.0;
return f;
}
//---连接数据库----------------------------------------------------------------------------
public void connection(){
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:studentscore");
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE) ;
String sqlw="select * from studentscore";
rs=stmt.executeQuery(sqlw);
try{
rs.next();
xh=(""+rs.getInt("学号"));
xm=rs.getString("姓名");
gs=rs.getString("高等数学");
wl=rs.getString("大学物理");
yy=rs.getString("大学英语");
VB=rs.getString("vb");
VC=rs.getString("vc");
zy=rs.getString("智育成绩");
jia=rs.getString("加分");
jian=rs.getString("减分");
zh=rs.getString("综合测评成绩");
stid.setText(xh);
stname.setText(xm);
gaoshu.setText(gs);
wuli.setText(wl);
yingyu.setText(yy);
vb.setText(VB);
vc.setText(VC);
zhiyu.setText(zy);
jiafen.setText(jia);
jianfen.setText(jian);
zonghe.setText(zh);
}
catch(Exception esql){
System.out.println(esql.getMessage());
}
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==up)
{
if(i==0){new JOptionPane().showMessageDialog(null,"已到第一条!");}
try{i--;
rs.previous();
xh=(""+rs.getInt("学号"));
xm=rs.getString("姓名");
gs=rs.getString("高等数学");
wl=rs.getString("大学物理");
yy=rs.getString("大学英语");
VB=rs.getString("vb");
VC=rs.getString("vc");
zy=rs.getString("智育成绩");
jia=rs.getString("加分");
jian=rs.getString("减分");
zh=rs.getString("综合测评成绩");
stid.setText(xh);
stname.setText(xm);
gaoshu.setText(gs);
wuli.setText(wl);
yingyu.setText(yy);
vb.setText(VB);
vc.setText(VC);
zhiyu.setText(zy);
jiafen.setText(jia);
jianfen.setText(jian);
zonghe.setText(zh);
}
catch(Exception eup){
System.out.println(eup.getMessage());
}
}
if(e.getSource()==next){
try{
i++;
rs.next();
xh=(""+rs.getInt("学号"));
xm=rs.getString("姓名");
gs=rs.getString("高等数学");
wl=rs.getString("大学物理");
yy=rs.getString("大学英语");
VB=rs.getString("vb");
VC=rs.getString("vc");
zy=rs.getString("智育成绩");
jia=rs.getString("加分");
jian=rs.getString("减分");
zh=rs.getString("综合测评成绩");
stid.setText(xh);
stname.setText(xm);
gaoshu.setText(gs);
wuli.setText(wl);
yingyu.setText(yy);
vb.setText(VB);
vc.setText(VC);
zhiyu.setText(zy);
jiafen.setText(jia);
jianfen.setText(jian);
zonghe.setText(zh);
}
catch(Exception enext){
System.out.println(enext.getMessage());
}
}
if(e.getSource()==jisuan){
try{
float gs2=Integer.parseInt(gs);
float wl2=Integer.parseInt(wl);
float yy2=Integer.parseInt(yy);
float VB2=Integer.parseInt(VB);
float VC2=Integer.parseInt(VC);
double jia2=Integer.parseInt(jia);
double jian2=Integer.parseInt(jian);
float zh2=Integer.parseInt(zh);
double a=jisuankcjd(gs2);
double b=jisuankcjd(wl2);
double c=jisuankcjd(yy2);
double d=jisuankcjd(VB2);
double f=jisuankcjd(VC2);
double zy3=((a*5+b*5+c*4+d*3+f*3)/(20*4))*65;
String str=String.valueOf(zy3);
zhiyu.setText(str);
//rs.next();
double zh3=zy3+jia2-jian2;
String str1=String.valueOf(zh3);
zonghe.setText(str1);
///ResultSet rs1;
String supdate="update studentscore set 智育成绩='"+ zhiyu.getText()+"', 综合测评成绩='"+ zonghe.getText()+"'where 学号='"+ stid.getText()+"'";
new JOptionPane().showMessageDialog(null,"计算完毕!");
stmt.executeUpdate(supdate);
String sqll="select * from studentscore";
rs=stmt.executeQuery(sqll);
try{for(int j=0;j<i;j++)
rs.next();}
catch(Exception eup){
System.out.println(eup.getMessage());
}
}catch(Exception eupdapt){
System.out.println(eupdapt.getMessage());
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -