实验名称:实验5:综合性程序设计—简单学生信息管理系统
班级:***** 姓名:Zzz 学号:20151601**** 一、实验目的
二、实验内容与结果
(1)任务描述(1.3与1.4二选一,建议选择1.4)
利用课程所学知识,设计并实现一个简单学生信息管理系统,要求如下: 1.1 声明Student类,该类实现Serializable接口以表明该类可以进行序列化。该类有姓名、学号(long),math、os、java用来存放对应的成绩,在构造方法中进行姓名、学号、课程成绩的赋值。Override由Object继承来的toString方法以便以友好格式显示自己的属性,格式为:张三 12 os:90 java:90 math: 90。
1.2 建立一个类,利用数据库来存储多个Student,写完一个方法在main中写一段测试代码,运行以保证目前所做工作的正确性。有以下方法: add(Student stu):可以增加新的学生,并保存在数据库中。 update(Student stu):可以修改特定的学生,并保存在数据库中。 dispAll():可以显示所有的学生信息。
findById(long id):可以按照学号来查找,并显示符合条件的学生信息,查无该人的话显示错误信息。
findByName(String name):可以按照姓名查找学生,找到后显示其信息,查无此人显示错误信息。
delById(long id):可以按照id删除学生的信息,然后显示找到该人。若查无此人,显示相应的错误信息。
1.3 (控制台方式)完善应用程序,实现相应的功能如下:添加学生信息、修改指定学号的学生信息、显示所有学生信息、按学号查找、按姓名查找、按学号删除、按成绩排序和退出。
1.4 (Swing窗体方式)完善应用程序,实现相应的功能如下:添加学生信息、修改指定学号的学生信息、显示所有学生信息、按学号查找、按姓名查找、按学号删除、按成绩排序和退出。
(2)处理思路及关键技术说明
(3)程序完整源码(要求格式规范,适当注释)
(4)运行结果截图(按每个操作分别截图)
(2)处理思路及关键技术说明
分三个模块:一是 jdbc的代码,另一个是 Swing和AWT的代码,剩下是Student类。 Jdbc 一共有两个类:DBUtil(连接工具类)和Sql类(处理jdbc功能的静态方法)
大全
标准文案
Swing 和AWT一个有两个类:MyJFrame构建总窗口,MyJPanel 对窗口内的面板行修饰。
然后就是Student类和Main主方法类。
关键部分:
1)在主窗体中add三个Jpanel,底层和第二层左右三个,右边的Jpanel实现cardLayout布局,左边的Jpanel添加按钮并添加ActionListener来实现对象的card切换达到不同按钮进入不同功能面板的目的。
2)在MyJPanel类中,所有的init方法均传递参数JPanel p,对传递过来的Panel进行加工修饰,并且调用Sql里面对应功能的方法。
3)Sql中的显示全部信息的方法中使用了ArrayList来存储从studenttbl中读取的对象信息,存储之后为了按照String的方式显示在JtextArea中,又用了listToString方法,通过for循环并追加回车,使每个对象都转化为String并在后面加上了回车(separator),
4)在Sql中的查找,删除,添加都使用了jdbc中的预处理PreparedStatement 在操作完毕后执行sts.executeUpdate();
5)在Sql排序方法中,把所有的信息都存储到list中以后,调用工具类Collections.sort:根据指定比较器产生的顺序对指定列表进行排序。 (3)程序完整源码(要求格式规范,适当注释)
class DBUtil
package test;
import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class DBUtil {
private static String driver; private static String url;
private static String username; private static String password; static {
driver=\"com.mysql.jdbc.Driver\";
url=\"jdbc:mysql://localhost:3306/mydb\"; username=\"root\"; password=\"123456\"; }
public static Connection open(){ try {
Class.forName(driver); return
DriverManager.getConnection(url,username,password);
大全
标准文案
}
}catch (Exception e) { e.printStackTrace(); }
return null; }
public static void close(Connection conn){ if(conn!=null){ try {
conn.close();
} catch (SQLException e) { e.printStackTrace(); } } }
class Sql
package test;
import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import javax.swing.JLabel;
import javax.swing.JOptionPane; import javax.swing.JTextArea;
public class Sql {
public static String listToString(List StringBuilder sb = new StringBuilder(); for (int i = 0; i < list.size(); i++) { sb.append(list.get(i)).append(separator); } return sb.toString().substring(0,sb.toString().length()-1); } public static List 大全 标准文案 //查询 Connection conn=DBUtil.open(); String sql=\"select id,name,frctionJava,fractionMath,fractionOS from studentTbl\"; Statement stmt; try { stmt = conn.createStatement(); ResultSet rs=stmt.executeQuery(sql); List while(rs.next()){ int id=rs.getInt(1); String name=rs.getString(2); double a=rs.getDouble(3); double b=rs.getDouble(4); double c=rs.getDouble(5); Student u=new Student(); u.setId(id); u.setName(name); u.setFractionJava(a); u.setFractionMath(b); u.setFractionOS(c); list.add(u); } conn.close(); return list; } catch (SQLException e) { e.printStackTrace(); } return null; } public static void FindByID(long id ,JLabel lblNewLabel ){//按ID查找 Connection conn=DBUtil.open(); ResultSet rs = null; try { String sql=\"select * from StudentTbl where id=?\"; PreparedStatement sts=conn.prepareStatement(sql); sts.setLong(1, id); rs=sts.executeQuery(); 大全 标准文案 while(rs.next()){ int i=rs.getInt(1); String name=rs.getString(2); double a=rs.getDouble(3); double b=rs.getDouble(4); double c=rs.getDouble(5); lblNewLabel.setText(\" | \"+i+\" | \"+name+\" | \"+a+\" | \"+b+\" | \"+c); } }catch(Exception e) { e.printStackTrace(); }finally{ try { if(rs.first()!=true) lblNewLabel.setText(\"~~~~~~~查无此人!~~~~~~~~\"); } catch (SQLException e) { e.printStackTrace(); } } } public static void FindByName(String s, JLabel lblNewLabel) {//按Name查找 Connection conn=DBUtil.open(); ResultSet rs = null; try { String sql=\"select * from StudentTbl where name=?\"; PreparedStatement sts=conn.prepareStatement(sql); sts.setString(1, s); rs=sts.executeQuery(); while(rs.next()) { int id=rs.getInt(1); String name=rs.getString(2); double a=rs.getDouble(3); double b=rs.getDouble(4); double c=rs.getDouble(5); lblNewLabel.setText(\" | \"+id+\" | \"+name+\" | 大全 标准文案 \"+a+\" | \"+b+\" | \"+c); } }catch(Exception e) { e.printStackTrace(); }finally{ try{ if(rs.first()!=true) lblNewLabel.setText(\"~~~~~~~查无此人!~~~~~~~~\"); } catch (SQLException e) { e.printStackTrace(); } } } public static void DeleteByID(long id){//删除 Connection conn=DBUtil.open(); PreparedStatement sts=null; int a=0; try { sts=conn.prepareStatement(\"delete from StudentTbl where id=?\"); sts.setLong(1, id); a=sts.executeUpdate(); if(a>0) JOptionPane.showMessageDialog(null, \"删除成功!\\"WO\ if(a==0) JOptionPane.showMessageDialog(null, \"无此人!\\"WO\JOptionPane.INFORMATION_MESSAGE); }catch(Exception e) { e.printStackTrace(); } DBUtil.close(conn); } 大全 标准文案 public static void Sort(JTextArea ta,int index) {//排序 //查询 Connection conn=DBUtil.open(); String sql=\"select id,name,frctionJava,fractionMath,fractionOS from studentTbl\"; Statement stmt; try { stmt = conn.createStatement(); ResultSet rs=stmt.executeQuery(sql); List while(rs.next()){ int id=rs.getInt(1); String name=rs.getString(2); double a=rs.getDouble(3); double b=rs.getDouble(4); double c=rs.getDouble(5); Student u=new Student(); u.setId(id); u.setName(name); u.setFractionJava(a); u.setFractionMath(b); u.setFractionOS(c); list.add(u); } Collections.sort(list,new Comparator public int compare(Student o1, Student o2) { int i = 1 ; if(index==1) {i= (int) (o2.getFractionJava() - o1.getFractionJava()); } if(index==2){ i = (int) (o2.getFractionMath() - o1.getFractionMath()); } if(index==3){ i = (int) (o2.getFractionOS() - o1.getFractionOS()); 大全 标准文案 } return i; } }); String s=listToString(list, '\\n'); ta.setText(s); } catch (SQLException e) { e.printStackTrace(); } DBUtil.close(conn); } public static void add(Student stu) {//添加 Connection conn=DBUtil.open(); PreparedStatement sts; try { sts = conn.prepareStatement(\"insert into StudentTbl values(?,?,?,?,?)\"); sts.setLong(1, stu.getId()); sts.setString(2, stu.getName()); sts.setDouble(3, stu.getFractionJava()); sts.setDouble(4, stu.getFractionMath()); sts.setDouble(5, stu.getFractionOS()); sts.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } DBUtil.close(conn);} public static void UpdateStudent(Student stu){//更新 Connection conn=DBUtil.open(); try { String sql=\"update studenttbl set name='\"+stu.getName()+\"',FrctionJava='\"+ stu.getFractionJava()+\"',FractionMath='\"+stu.getFractionMath()+\"',FractionOS='\"+stu.getFractionOS()+\"' where id='\"+stu.getId()+\"'\"; 大全 标准文案 PreparedStatement sts=conn.prepareStatement(sql); sts.executeUpdate(); }catch(Exception e) { e.printStackTrace(); } } } class Student package test; import java.io.Serializable; public class Student implements Serializable{ private static final long =4558876142427402513L; private String name; private long id; private double fractionOS; private double fractionJava; private double fractionMath; public String getName() { return name; } public void setName(String name) { this.name = name; } public long getId() { return id; } public void setId(long id) { this.id = id; } public double getFractionOS() { return fractionOS; } public void setFractionOS(double fractionOS) { this.fractionOS = fractionOS; } public double getFractionJava() { 大全 serialVersionUID 标准文案 } return fractionJava; } public void setFractionJava(double fractionJava) { this.fractionJava = fractionJava; } public double getFractionMath() { return fractionMath; } public void setFractionMath(double fractionMath) { this.fractionMath = fractionMath; } public String toString() { return (name+\" \"+id+\" Java:\"+fractionJava+ \" Math:\"+fractionMath+\" OS:\"+fractionOS); } class MyJFrame package test; import javax.swing.JFrame; import javax.swing.JPanel; import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import java.awt.Color; import javax.swing.SwingConstants; import javax.swing.JLabel; import java.awt.Font; public class MyJFrame { JFrame frame=new JFrame(\"Demo\");; 大全 标准文案 /** * @wbp.parser.entryPoint */ public void init() { frame.setVisible(true); frame.setBounds(100, 100, 570, 474); //JPanel JPanel panel = new JPanel(); panel.setBackground(new Color(153, 204, 255)); frame.getContentPane().add(panel, BorderLayout.CENTER); panel.setLayout(null); //Panel X Y JPanel panel_x = new JPanel(); panel_x.setBackground(new Color(153, 204, 255)); panel_x.setBounds(0, 0, 141, 435); panel.add(panel_x); panel_x.setLayout(null); JPanel panel_y = new JPanel(); panel_y.setBackground(new Color(255, 255, 255)); panel_y.setBounds(140, 0, 414, 435); panel.add(panel_y); //功能按钮 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ JButton b0 = new JButton(\"Home\"); b0.setHorizontalAlignment(SwingConstants.LEADING); b0.setBackground(new Color(255, 255, 255)); b0.setBounds(34, 21, 66, 23); panel_x.add(b0); JButton b1 = new JButton(\"\显\示\"); b1.setBackground(new Color(255, 255, 255)); b1.setBounds(22, 66, 93, 23); panel_x.add(b1); 大全 标准文案 JButton b2 = new JButton(\"\查\找(ID)\"); b2.setBackground(new Color(255, 255, 255)); b2.setBounds(22, 112, 93, 23); b2.setMargin(new Insets(0, 0, 0, 0)); panel_x.add(b2); JButton b3 = new JButton(\"\查\找(Name)\"); b3.setBackground(new Color(255, 255, 255)); b3.setBounds(22, 157, 93, 23); b3.setMargin(new Insets(0, 0, 0, 0)); panel_x.add(b3); JButton b4 = new JButton(\"\删\除\"); b4.setBackground(new Color(255, 255, 255)); b4.setBounds(22, 200, 93, 23); panel_x.add(b4); JButton b5 = new JButton(\"\排\序\"); b5.setBounds(22, 243, 93, 23); b5.setBackground(new Color(255, 255, 255)); panel_x.add(b5); JButton b6 = new JButton(\"\添\加\"); b6.setBounds(22, 290, 93, 23); b6.setBackground(new Color(255, 255, 255)); panel_x.add(b6); JButton b7 = new JButton(\"\更\新\"); b7.setBounds(22, 334, 93, 23); b7.setBackground(new Color(255, 255, 255)); panel_x.add(b7); JButton bExit = new JButton(\"\退\出\"); bExit.setBounds(22, 378, 93, 23); bExit.setBackground(new Color(255, 255, 255)); panel_x.add(bExit); //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 大全 标准文案 //============================================================= CardLayout cl_panel_y=new CardLayout();//卡片JPanel panel_y.setLayout(cl_panel_y); JPanel panel_0 = new JPanel();//欢迎界面 panel_0.setBackground(new Color(153, 204, 255)); panel_y.add(panel_0, \"c0\"); panel_0.setLayout(null); JLabel l1 = new JLabel(\"\欢\迎\使\用\学\生\信\息\管\理\\u7A0B\序\"); l1.setFont(new Font(\"宋体\ l1.setHorizontalAlignment(SwingConstants.CENTER); l1.setBounds(37, 33, 317, 66); panel_0.add(l1); JPanel panel_1 = new JPanel();//显示 panel_y.add(panel_1, \"c1\"); JPanel panel_2 = new JPanel();//查找 panel_y.add(panel_2, \"c2\"); JPanel panel_3 = new JPanel();//查找 panel_y.add(panel_3, \"c3\"); //MyJPanel.init3(panel_3); JPanel panel_4 = new JPanel();//删除 panel_y.add(panel_4, \"c4\"); // MyJPanel.init4(panel_4); JPanel panel_5 = new JPanel();//排序 panel_y.add(panel_5, \"c5\"); //MyJPanel.init5(panel_5); JPanel panel_6 = new JPanel();//添加 panel_y.add(panel_6, \"c6\"); 大全 标准文案 JPanel panel_7 = new JPanel(); panel_y.add(panel_7, \"c7\"); //MyJPanel.init6(panel_6); //============================================================== //按钮事件 //============================================================== b0.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cl_panel_y.show(panel_y, \"c0\"); } }); b1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { MyJPanel.init1(panel_1); cl_panel_y.show(panel_y, \"c1\"); } }); b2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { MyJPanel.init2(panel_2); cl_panel_y.show(panel_y, \"c2\"); } }); b3.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { MyJPanel.init3(panel_3); cl_panel_y.show(panel_y, \"c3\"); } }); b4.addActionListener(new ActionListener() { @Override 大全 标准文案 } } 大全 public void actionPerformed(ActionEvent e) { MyJPanel.init4(panel_4); cl_panel_y.show(panel_y, \"c4\"); } }); b5.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { MyJPanel.init5(panel_5); cl_panel_y.show(panel_y, \"c5\"); } }); b6.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { MyJPanel.init6(panel_6); cl_panel_y.show(panel_y, \"c6\"); } }); b7.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { MyJPanel.init7(panel_7); cl_panel_y.show(panel_y, \"c7\"); } }); bExit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); 标准文案 class MyJPanel package test; import java.awt.CardLayout; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.List; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.SwingConstants; import java.awt.Color; class MyJPanel{ // 显示 static void init1(JPanel panel){ //JPanel panel=new JPanel(); panel.setBackground(new Color(255, 255, 255)); panel.setBounds(0, 0, 373, 382); panel.setLayout(null); JLabel l = new JLabel(\" ===\下\列\是\所\有\查\看\的\所\有\数\据\信\息===\");//Label l.setFont(new Font(\"宋体\ l.setBounds(15, 10, 336, 29); panel.add(l); JTextArea textArea = new JTextArea();//TextArea textArea.setFont(new Font(\"Monospaced\ textArea.setBackground(new Color(255, 255, 255)); textArea.setBounds(25, 49, 326, 311); 大全 标准文案 List textArea.append(Sql.listToString(list,'\\n')); panel.add(textArea); panel.repaint(); } // 查找ID static void init2(JPanel panel){ // JPanel panel=new JPanel(); panel.setBackground(new Color(255, 255, 255)); panel.setBounds(0, 0, 373, 202); panel.setLayout(null); JLabel l1 = new JLabel(\"输入查找的ID:\"); l1.setBounds(15, 39, 201, 35); l1.setFont(new Font(\"宋体\ panel.add(l1); JLabel l2=new JLabel(\"学号 姓名 Java OS\"); l2.setBounds(47, 80, 290, 31); l2.setFont(new Font(\"宋体\ panel.add(l2); JTextField textField = new JTextField(); textField.setBounds(208, 39, 72, 35); textField.setColumns(10); panel.add(textField); JLabel l0 = new JLabel(); l0.setFont(new Font(\"宋体\ l0.setBounds(21, 120, 331, 35); JButton b = new JButton(\"Y\"); b.setFont(new Font(\"宋体\ 大全 Math 标准文案 b.setHorizontalAlignment(SwingConstants.LEFT); b.setBackground(new Color(255, 255, 255)); b.setBounds(301, 39, 45, 35); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0){ String s=textField.getText(); long id=Long.parseLong(s); Sql.FindByID(id,l0); } }); panel.add(b); panel.add(l0); } // 查找Name static void init3(JPanel panel) { panel.setBounds(0, 0, 373, 202); panel.setBackground(new Color(255, 255, 255)); panel.setLayout(null); JLabel l1 = new JLabel(\"输入要查找的姓名:\"); l1.setBounds(15, 39, 201, 35); l1.setFont(new Font(\"宋体\ panel.add(l1); JLabel l2=new JLabel(\"学号 姓名 Java OS\"); l2.setBounds(47, 80, 290, 31); l2.setFont(new Font(\"宋体\ panel.add(l2); JTextField textField = new JTextField(); textField.setBounds(208, 39, 72, 35); textField.setColumns(10); panel.add(textField); 大全 Math 标准文案 JLabel l0 = new JLabel(); l0.setFont(new Font(\"宋体\ l0.setBounds(21, 120, 331, 35); panel.add(l0); JButton b = new JButton(\"Y\"); b.setBounds(301, 39, 45, 35); b.setBackground(new Color(255, 255, 255)); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0){ String s=textField.getText(); Sql.FindByName(s,l0); } }); panel.add(b); } // 删除 static void init4(JPanel panel) { panel.setBounds(0, 0, 373, 202); panel.setBackground(new Color(255, 255, 255)); panel.setLayout(null); JLabel l1 = new JLabel(\"请输入你要删除的ID:\"); l1.setBounds(15, 39, 201, 35); l1.setFont(new Font(\"宋体\ panel.add(l1); JTextField textField = new JTextField(); textField.setBounds(95, 84, 72, 35); textField.setColumns(10); panel.add(textField); JLabel l0 = new JLabel(); 大全 标准文案 l0.setFont(new Font(\"宋体\ l0.setBounds(15, 137, 331, 35); panel.add(l0); JButton b = new JButton(\"Y\"); b.setBackground(new Color(255, 255, 255)); b.setHorizontalAlignment(SwingConstants.LEFT); b.setBounds(199, 84, 62, 35); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0){ String s=textField.getText(); long id=Long.parseLong(s); Sql.DeleteByID(id); } }); panel.add(b); } // 排序 static void init5(JPanel p){ //JPanel p = new JPanel(); p.setBackground(new Color(255, 255, 255)); JTextArea a1= new JTextArea(); a1.setFont(new Font(\"Monospaced\ JTextArea a2= new JTextArea(); a2.setFont(new Font(\"Monospaced\ JTextArea a3= new JTextArea(); a3.setFont(new Font(\"Monospaced\ CardLayout card = new CardLayout(3,3); JPanel pane = new JPanel(card); pane.setBackground(new Color(255, 255, 255)); pane.setBounds(45, 65, 360, 500); 大全 标准文案 JButton b1_1; JButton b2_1; JButton b3_1; b1_1 = new JButton(\"按Java排序\"); b1_1.setBackground(new Color(255, 255, 255)); b1_1.setBounds(84, 20, 93, 35); b2_1 = new JButton(\"按Math排序\"); b2_1.setBackground(new Color(255, 255, 255)); b2_1.setBounds(172, 20, 93, 35); b3_1 = new JButton(\"按OS排序\"); b3_1.setBackground(new Color(255, 255, 255)); b3_1.setBounds(264, 20, 87, 35); p.setLayout(null); p.add(b1_1); p.add(b2_1); p.add(b3_1); p.add(pane); pane.add(a1,\"p1\"); pane.add(a2,\"p2\"); pane.add(a3,\"p3\"); b1_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Sql.Sort(a1,1); card.show(pane,\"p1\"); } }); b2_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Sql.Sort(a2,2); card.show(pane,\"p2\"); } }); b3_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Sql.Sort(a3,3); card.show(pane,\"p3\"); } }); 大全 标准文案 大全 } // 添加 static void init6(JPanel p){ //JPanel p=new JPanel(); p.setBackground(new Color(255, 255, 255)); JLabel l0,l1,l2,l3,l4,l5;//输入 姓名 id java math O s JTextField t1,t2,t3,t4,t5;//姓名 id java math O s JButton b=new JButton(\"Y\");//确认 p.setLayout(null); l0=new JLabel(\"请输入相关信息:\"); l0.setFont(new Font(\"宋体\ l0.setBounds(0,0,126,30); l1=new JLabel(\"Name:\"); l1.setFont(new Font(\"宋体\ l1.setHorizontalAlignment(SwingConstants.CENTER); l1.setBounds(30,30,80,30); t1=new JTextField();//name t1.setBounds(144,30,80,30); l2=new JLabel(\" ID:\"); l2.setFont(new Font(\"宋体\ l2.setHorizontalAlignment(SwingConstants.CENTER); l2.setBounds(30,70,80,30); t2=new JTextField();//id t2.setBounds(144,70,80,30); l3=new JLabel(\" Java:\"); l3.setFont(new Font(\"宋体\ l3.setHorizontalAlignment(SwingConstants.CENTER); l3.setBounds(30,110,80,30); t3=new JTextField();//id t3.setBounds(144,110,80,30); l4=new JLabel(\" Math:\"); l4.setFont(new Font(\"宋体\ 标准文案 l4.setHorizontalAlignment(SwingConstants.CENTER); l4.setBounds(30,150,80,30); t4=new JTextField();//id t4.setBounds(144,150,80,30); l5=new JLabel(\" OS:\"); l5.setFont(new Font(\"宋体\ l5.setHorizontalAlignment(SwingConstants.CENTER); l5.setBounds(30,190,80,30); t5=new JTextField();//id t5.setBounds(144,190,80,30); b.setBounds(300,260,50,30); b.setBackground(new Color(255, 255, 255)); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { String n,id,j,m,o; id=t2.getText();long id1 = (long)Integer.parseInt(id);//把String 转化成I n t n=t1.getText(); j=t3.getText();double j1 =(double) Integer.parseInt(j);//把String 转化成I n t m=t4.getText();double m1 =(double) Integer.parseInt(m); o=t5.getText();double o1 =(double) Integer.parseInt(o); Student stu=new Student(); stu.setId(id1); stu.setName(n); stu.setFractionJava(j1); stu.setFractionMath(m1); stu.setFractionOS(o1); Sql.add(stu); JOptionPane.showMessageDialog(null, \"添加成功!\\"WO\ } }); p.add(l0); p.add(l1); 大全 标准文案 p.add(t1); p.add(l2); p.add(t2); p.add(l3); p.add(t3); p.add(l4); p.add(t4); p.add(l5); p.add(t5); p.add(b); } // 更新 static void init7(JPanel panel){ //JPanel p=new JPanel(); //JPanel panel = new JPanel(); panel.setBounds(0, 0, 373, 202); panel.setBackground(new Color(255, 255, 255)); //frame.getContentPane().add(panel); panel.setLayout(null); JLabel lblNewLabel_1 = new JLabel(\"请输入你要更改学生的ID:\"); lblNewLabel_1.setBounds(15, 39, 201, 35); lblNewLabel_1.setFont(new Font(\"宋体\ panel.add(lblNewLabel_1); JTextField textField = new JTextField(); textField.setBounds(208, 39, 72, 35); textField.setColumns(10); panel.add(textField); JTextField textField_1 = new JTextField(); textField_1.setBounds(15, 149, 55, 35); panel.add(textField_1); textField_1.setColumns(10); JTextField textField_2 = new JTextField(); textField_2.setBounds(80, 149, 45, 35); panel.add(textField_2); textField_2.setColumns(10); 大全 标准文案 JTextField textField_3 = new JTextField(); textField_3.setBounds(136, 149, 45, 35); panel.add(textField_3); textField_3.setColumns(10); JTextField textField_4 = new JTextField(); textField_4.setBounds(194, 149, 45, 35); panel.add(textField_4); textField_4.setColumns(10); JLabel lblNewLabel = new JLabel(); lblNewLabel.setFont(new Font(\"宋体\ lblNewLabel.setBounds(15, 94, 331, 35); panel.add(lblNewLabel); JButton Find = new JButton(\"Y\"); Find.setBackground(new Color(255, 255, 255)); Find.setBounds(301, 39, 45, 35); panel.add(Find); JButton Sure = new JButton(\"Y\"); Sure.setBounds(291, 148, 55, 36); panel.add(Sure); Sure.setBackground(new Color(255, 255, 255)); Find.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0){ String s=textField.getText(); long id=Long.parseLong(s); Sql.FindByID(id,lblNewLabel); if(lblNewLabel.getText().equals(\"~~~~~~~查无此人!~~~~~~~~\")){ lblNewLabel.setText(\"这是个错误的ID!!!\"); } else lblNewLabel.setText(\"请依次输Name FractionJava 大全 标准文案 FractionMath FractionOS\"); } }); Sure.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Student stu=new Student(); stu.setId(Long.parseLong(textField.getText())); stu.setName(textField_1.getText()); stu.setFractionJava(Double.valueOf(textField_2.getText()).doubleValue()); stu.setFractionMath(Double.valueOf(textField_3.getText()).doubleValue()); stu.setFractionOS(Double.valueOf(textField_4.getText()).doubleValue()); Sql.UpdateStudent(stu); JOptionPane.showMessageDialog(null, \"修改成功!\\"WO\ } }); } } class Main package test; public class Main { public static void main(String[] args) { new MyJFrame().init(); } } (4)运行结果截图(按每个操作分别截图) 大全 标准文案 大全 标准文案 大全 标准文案 大全 标准文案 大全 标准文案 大全 因篇幅问题不能全部显示,请点此查看更多更全内容