📄 10ee0b6ef850001d1d14f346b68412eb
字号:
import javax.swing.*;
import java.sql.*;
import java.awt.*;
import javax.swing.border.*;
import java.awt.event.*;
import java.sql.DriverManager;
class addmarch1 extends JFrame implements ActionListener
{ Box baseBox,boxV1,boxV2;
TextField noText,nameText,courseText,marchText;
Label noLabel,nameLabel,courseLabel,marchLabel;
Button addButton,resetButton,delButton;
JPanel panel=new JPanel();
addmarch1(String s)
{ super(s);
setLayout(new FlowLayout());
noLabel=new Label("学号",Label.LEFT);
nameLabel=new Label("姓名",Label.LEFT);
courseLabel=new Label("科目",Label.LEFT);
marchLabel=new Label("分数",Label.LEFT);
noText=new TextField(10);
nameText=new TextField(10);
courseText=new TextField(10);
marchText=new TextField(10);
addButton=new Button("添加");
resetButton=new Button("修改");
delButton=new Button("删除");
add(addButton);
add(resetButton);
add(delButton);
boxV1=Box.createVerticalBox();
boxV1.add(noLabel);
boxV1.add(Box.createVerticalStrut(5));
boxV1.add(nameLabel);
boxV1.add(Box.createVerticalStrut(5));
boxV1.add(courseLabel);
boxV1.add(Box.createVerticalStrut(5));
boxV1.add(marchLabel);
boxV2=Box.createVerticalBox();
boxV2.add(Box.createVerticalStrut(7));
boxV2.add(noText);
boxV2.add(Box.createVerticalStrut(6));
boxV2.add(nameText);
boxV2.add(Box.createVerticalStrut(6));
boxV2.add(courseText);
boxV2.add(Box.createVerticalStrut(7));
boxV2.add(marchText);
boxV2.add(Box.createVerticalStrut(6));
addButton.addActionListener(this);
resetButton.addActionListener(this);
delButton.addActionListener(this);
baseBox=Box.createHorizontalBox();
baseBox.add(boxV1);
baseBox.add(Box.createHorizontalStrut(5));
baseBox.add(boxV2);
setLayout(new FlowLayout());
add(baseBox);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setBounds(120,120,250,250);
setVisible(true);
validate();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==addButton)
{
Connection con;
Statement sql;
ResultSet rs;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundException k){
System.out.println(""+k);
}
try{
con=DriverManager.getConnection("jdbc:odbc:sun","","");
sql=con.createStatement();
String no,name,course,march,addstr;
no=noText.getText();
name=nameText.getText();
course=courseText.getText();
march=marchText.getText();
addstr="INSERT INTO 成绩信息表 VALUES ('"+no+"','"+name+"','"+course+"','"+march+"','" +
""+null+"','"+null+"','"+null+"','"+null+"')";
sql.executeUpdate(addstr);
con.close();
}catch(SQLException ee){
System.out.print(ee);
}
}
if(e.getSource()==resetButton)
{
/* Connection con;
Statement sql;
ResultSet rs;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundException k){
System.out.println(""+k);
}
try{
con=DriverManager.getConnection("jdbc:odbc:sun","","");
sql=con.createStatement();
String no,course,teacher,updatestr=null;
no=noText.getText();
course=courseText.getText();
teacher=teacherText.getText();
updatestr="UPDATE 成绩信息表 SET courseno='" + no+ "' WHERE course='" + course +"'";
sql.executeUpdate(updatestr);
con.close();
}catch(SQLException ee){
System.out.print(ee);
}*/
}
if(e.getSource()==delButton)
{
Connection con;
Statement sql;
ResultSet rs;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundException k){
System.out.println(""+k);
}
try{
con=DriverManager.getConnection("jdbc:odbc:sun","","");
sql=con.createStatement();
String no,delstr;
no=noText.getText();
delstr="DELETE FROM 成绩信息表 WHERE courseno = '" + no+ "'";
System.out.println(delstr);
sql.executeUpdate(delstr);
con.close();
}catch(SQLException ee){
System.out.print(ee);
}
}
}
}
public class addmarch
{
public static void main(String args[])
{
addmarch1 win=new addmarch1("课程更改");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -