Java學生課程設計源碼要點
《Java學生課程設計源碼要點》由會員分享,可在線閱讀,更多相關(guān)《Java學生課程設計源碼要點(15頁珍藏版)》請在裝配圖網(wǎng)上搜索。
1、package com.lb.view; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Login extends JFrame { private TextField f1; private TextField f2; private JButton b1; private JButton b2; private JButton b3; //登陸界面 public Login(){ 列布局 Container cp=getContentPane();//
2、容器 cp.setBackground(Color.cyan); cp.setLayout(new GridLayout(4,1));// Panel p1=new Panel(); Panel p2=new Panel(); Panel p3=new Panel(); Panel p4=new Panel(); f1=new TextField(15); f2=new TextField(15); f2.setEchoChar(*);// 回顯字符為 * b1=new JButton(" 登錄"); b2=new JButton("重置"); b3=new JButto
3、n(" 退出"); p1.add(new Label(" ")); p2.add(new Label("用戶名")); p2.add(f1); p3.add(new Label("密 碼”)); p3.add(f2); p4.add(b1); p4.add(b2); p4.add(b3); cp.add(p1); cp.add(p2); cp.add(p3); cp.add(p4); b1.addActionListener(new Enter()); b2.addActionListener(new ReWrite()); b3.addActionListener
4、(new Close()); } 任艷云")&&(f2.getText()).equals("ren12")) class Enter implements ActionListener{ public void actionPerformed(ActionEvent e) { if((f1.getText()).equals( { XueSheng framel = new XueSheng(); frame1.setBounds(200, 200, 400, 400); framel.setVisible(true); } else JOptionPane.showMes
5、sageDialog(null,” 用戶名或密碼錯誤,請重新登錄! "); } } class ReWrite implements ActionListener{ public void actionPerformed(ActionEvent e) { f1.setText(""); f2.setText(""); f1.requestFocus(); } } class Close implements ActionListener{ public void actionPerformed(ActionEvent e) { JButton bt=(JButton)e.g
6、etSource(); if(bt==b3){ System.exit(0); } } } 〃主函數(shù)程序開始 public static void main(String口 args) { Login log=new Login(); log.setTitle(" 系統(tǒng)登錄"); log.setBounds(200, 200, 300, 300); log.setBackground(Color.red); log.setVisible(true); } //信息管理界面內(nèi)部類進行初始化和保存 class XueSheng extends JFrame imple
7、ments ActionListener { private JButton cx, zj, tc, sc,xg,tj; public XueSheng() { Container c = this.getContentPane(); c.setLayout(new GridLayout(4, 1)); c.setBackground(Color.cyan); c.setFont(new Font("true",Font.TRUETYPE_FONT,13)); JPanel panel1 = new JPanel(); panel1.setBackground(Color.cy
8、an); JLabel label1 = new JLabel(" 歡迎登入成績管理主頁 ”,SwingConstants.CENTER); label1.setFont(new Font("true",Font.TRUETYPE_FONT,15)); panel1.add(label1); JPanel panel2 = new JPanel(); panel2.setBackground(Color.cyan); JPanel panel3 = new JPanel(); panel3.setBackground(Color.cyan); JPanel panel4 = n
9、ew JPanel(); panel4.setBackground(Color.cyan); //添加按鈕 cx = new JButton(" 查詢) panel2.add(cx); zj = new JButton(" 增加) panel2.add(zj); sc = new JButton(" 刪除"); panel3.add(sc); xg = new JButton(" 修改"); panel3.add(xg); tc = new JButton(" 退出"); panel4.add(tc); c.add(panell); c.add(panel2); c.
10、add(panel3); c.add(panel4); cx.addActionListener(this); zj.addActionListener(this); sc.addActionListener(this); xg.addActionListener(this); tc.addActionListener(this); this.setVisible(true); } public void actionPerformed(ActionEvent e) { if (e.getSource() == cx) { Query f = new Query(); }
11、 if(e.getSource()==zj){ Inseter f = new Inseter(); } if(e.getSource()==sc){ Delete d = new Delete(); } if(e.getSource()==xg){ Update x=new Update。; } if(e.getSource()==tc){ shutDown(); } } private void shutDown() { JOptionPane.showMessageDialog(null,” 信息已保存"); this.dispose(); } } }
12、 插入源碼: package com.lb.view; import java.awt.Color; import java.awt.Container; import java.awt.FlowLayout; import java.awt.Font; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.FileNotFoundException; import java.io.IOExcept
13、ion; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingConstants; import com.lb.bean.Student; import com.lb.dao.DaoImpl; class Inseter extends J
14、Frame implements ActionListener { private JTextField STNOText, SNAMEText, MAText, CHIText, JAVAText; private JButton b1, b2, b3; private String STNO, SNAME,MAT, CHI, JAVA; private Student a; public Inseter() { super("添加學生信息) Container c2 = this.getContentPane(); c2.setLayout(new GridLayout(3
15、, 1)); c2.setBackground(Color.cyan); JPanel center = new JPanel(); center.setLayout(new GridLayout(5, 4)); center.setBackground(Color.cyan); JPanel low = new JPanel(new FlowLayout()); low.setBackground(Color.cyan); JLabe11abel1 = new JLabel(" 添加學生信息",SwingConstants.CENTER); label1.setFont(ne
16、w Font("TRUE", Font.TRUETYPE_FONT, 20)); c2.add(label1); STNOText = new JTextField(20);〃30 列文本框 SNAMEText = new JTextField(20); CHIText = new JTextField(20); MAText = new JTextField(20); JAVAText = new JTextField(20); center.add(new JLabel(" ")); 添加標簽學號寫在標簽中間 center.add(new JLabel(" 學號:",Sw
17、ingConstants.CENTER));// center.add(STNOText);// 添加文本框 center.add(new JLabel(" ")); center.add(new JLabel(" ")); center.add(new JLabel(" 姓名:",SwingConstants.CENTER)); center.add(SNAMEText); center.add(new JLabel(" ")); center.add(new JLabel(" ")); center.add(new JLabel(" 語文:",SwingConstants.
18、CENTER)); center.add(CHIText); center.add(new JLabel(" ")); center.add(new JLabel(" ")); center.add(new JLabel(" 數(shù)學:",SwingConstants.CENTER)); center.add(MAText); center.add(new JLabel(" ")); center.add(new JLabel(" ")); center.add(new JLabel("java:", SwingConstants.CENTER)); center.add(JAV
19、AText); center.add(new JLabel(" ")); c2.add(center); b1 = new JButton(" 添加"); b2 = new JButton(" 清除"); b3 = new JButton(" 退出"); low.add(b1); low.add(b2); low.add(b3); c2.add(low); //添加監(jiān)聽 b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); this.setBounds(
20、200, 200, 600, 400); this.setVisible(true); this.setTitle(" 添加學生信息) } public void actionPerformed(ActionEvent e) { if (e.getSource() == b1) { try { inseter(); } catch (FileNotFoundException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } } if (e.getSource() ==
21、 b2) { clearForm(); } if (e.getSource() == b3) { this.dispose(); } } private void inseter() throws FileNotFoundException, IOException { STNO = STNOText.getText(); SNAME = SNAMEText.getText(); CHI = CHIText.getText(); MAT = MAText.getText(); JAVA = JAVAText.getText(); Student stu =new Student
22、。; if (STNO.length() == 0 || SNAME.length() == 0 || MAT.length() == 0 || JAVA.length() == 0 || CHI.length() == 0){ JOptionPane.showMessageDialog(this,” 請?zhí)砑油耆畔?); } else { Student a=new Student(SNAME,STNO, Integer.parseInt(CHI),Integer.parseInt(MAT),Integer.parseInt(JAVA)); DaoImpl di = new DaoI
23、mpl(); di.inseter(a); JOptionPane.showMessageDialog(this," 添加成功! !”); } } private void clearForm() { STNOText.setText(""); SNAMEText.setText(""); MAText.setText(""); CHIText.setText(""); JAVAText.setText(""); } } 刪除源碼: package com.lb.view; import java.awt.Color; import java.awt.Container
24、; import java.awt.Font; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScro
25、llPane; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.SwingConstants; import com.lb.dao.Daolmpl; class Delete extends JFrame implements ActionListener{ private JButton yes; private JButton cancle; private JTextField text1; private String STNO; public Delet
26、e(){ Container c3 = this.getContentPane(); c3.setBackground(Color.pink); c3.setLayout(new GridLayout(3, 1)); c3.setFont(new Font("true",Font.TRUETYPE_FONT,13)); JPanel p1 = new JPanel(); p1.setBackground(Color.pink); JPanel p2 = new JPanel(); p2.setBackground(Color.pink); JLabe11abel1 = new
27、 JLabel(" 刪除學生信息”,SwingConstants.CENTER); label1.setFont(new Font("true",Font.TRUETYPE_FONT,13)); label1.setForeground(Color.blue); c3.add(label1); JLabel label2 = new JLabel(" 請輸入學號"); text1 = new JTextField(10); p1.add(label2); p1.add(text1); c3.add(p1); yes = new JButton(" 確定"); cancle
28、= new JButton(" 退出"); p2.add(yes); p2.add(cancle); c3.add(p2); yes.addActionListener(this); cancle.addActionListener(this); this.setTitle(" 刪除學生信息) this.setBounds(200,200,400,300); this.setVisible(true); } public void actionPerformed(ActionEvent e){ if(e.getSource(尸yes){ DaoImpl di =new
29、DaoImpl(); STNO = text1.getText(); di.delete(STNO); } if(e.getSource(尸cancle){ this.dispose(); } JOptionPane.showMessageDialog(this,” 刪除成功! ??!"); } } 修改源碼: package com.lb.view; import java.awt.Color; import java.awt.Container; import java.awt.Font; import java.awt.GridLayout; import
30、java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingConstants; import com.lb.bean
31、.Student; import com.lb.dao.DaoImpl; class Update extends JFrame implements ActionListener{ private JTextField STNOText, SNAMEText, MAText, CHIText, JAVAText; private JButton b1,b2,b3; public Update(){ Container c4 = this.getContentPane(); c4.setLayout(new GridLayout(5, 1)); c4.setFont(new F
32、ont("true",Font.TRUETYPE_FONT,13)); JPanel up1 = new JPanel(); up1.setBackground(Color.pink); JPanel up2 = new JPanel(); up2.setBackground(Color.pink); JPanel center = new JPanel(new GridLayout(4,4)); center.setBackground(Color.pink); JPanel low = new JPanel(); low.setBackground(Color.pink);
33、 JPanel low1 = new JPanel(); low1.setBackground(Color.pink); JLabe11abel11 = new JLabel(" 需要修改的學號:"); STNOText=new JTextField(15); up2.add(label11); up2.add(STNOText); b1=new JButton(" 查找"); up2.add(b1); c4.add(up1); c4.add(up2); c4.add(center); SNAMEText=new JTextField(22); MAText=new
34、JTextField(22); CHIText=new JTextField(22); JAVAText=new JTextField(22); center.add(new JLabel(" ")); center.add(new JLabel(" 姓名:",SwingConstants.CENTER)); center.add(SNAMEText); center.add(new JLabel(" ")); center.add(new JLabel(" ")); center.add( new JLabel(" 數(shù)學:",SwingConstants.CENTER));
35、 center.add(MAText); center.add(new JLabel(" ")); center.add(new JLabel(" ")); center.add(new JLabel(" 語文:",SwingConstants.CENTER)); center.add(CHIText); center.add(new JLabel(" ")); center.add(new JLabel(" ")); center.add(new JLabel("java:", SwingConstants.CENTER)); center.add(JAVAText); c
36、enter.add(new JLabel(" ")); c4.add(center); b2=new JButton("修改"); b3=new JButton(" 退出"); low1.add(b2); low1.add(b3); c4.add(low); c4.add(low1); bl.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); this.setTitle(" 修改信息) this.setBounds(200, 200, 400, 400); th
37、is.setVisible(true); } public void actionPerformed(ActionEvent e) { if (e.getSource() == b1) { DaoImpl di = new DaoImpl(); String num = STNOText.getText(); Student stu = di.findStudentByNum(num); if(num.equals(stu.getNum())){ SNAMEText.setText(stu.getName()); MAText.setText(String.valueOf(s
38、tu.getShuxue())); CHIText.setText(String.valueOf(stu.getYuwen())); JAVAText.setText(String.valueOf(stu.getJava())); } if (e.getSource() == b2) { if (SNAMEText.getColumns() == 0 || MAText.getColumns() == 0 || JAVAText.getColumns() == 0 || CHIText.getColumns() == 0) { else { Student a=new Stu
39、dent(SNAMEText.getText(),STNOText.getText(), Integer.parseInt(CHIText.getText()),Integer.parseInt(MAText.getText()), Integer.parseInt(JAVAText.getText())); DaoImpl dl = new DaoImpl(); dl.update(a); JOptionPane.showMessageDialog(this,” 修改成功! !!"); } if (e.getSource() == b3) { this.dispose();
40、} 查詢源碼: package com.lb.view; import java.awt.Color; import java.awt.Container; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPa
41、ne; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingConstants; import com.lb.bean.Student; import com.lb.dao.Daolmpl; class Query extends JFrame implements ActionListener { private JTextField STNOText, SNAMEText, MAText, CHIText, JAVAText; private String STN
42、O; private JButton b1, b2; public Query() { Container c1 = this.getContentPane(); c1.setLayout(new GridLayout(4, 1)); JLabe11abel1 = new JLabel(" 查詢學生信息",SwingConstants.CENTER); JLabe11abel0 = new JLabel(" 請輸入你的學號",SwingConstants.CENTER); JPanel pp = new JPanel(new GridLayout(2, 1)); pp.setB
43、ackground(Color.pink); pp.add(label1); pp.add(label0); c1.add(pp); JPanel p1 = new JPanel(); p1.setBackground(Color.pink); STNOText = new JTextField(10); p1.add(STNOText); c1.add(p1); JPanel p2 = new JPanel(); p2.setBackground(Color.pink); b1 = new JButton(" 查詢"); b2 = new JButton(" 退出")
44、; b1.addActionListener(this); b2.addActionListener(this); p2.add(b1); p2.add(b2); c1.add(p2); JPanel center = new JPanel(new GridLayout(4, 4)); center.setBackground(Color.pink); SNAMEText = new JTextField(30); CHIText = new JTextField(30); MAText = new JTextField(30); JAVAText = new JText
45、Field(30); center.add(new JLabel(" ")); center.add(new JLabel(" 姓名", SwingConstants.CENTER)); center.add(SNAMEText); center.add(new JLabel(" ")); center.add(new JLabel(" ")); center.add(new JLabel(" 語文", SwingConstants.CENTER)); center.add(CHIText); center.add(new JLabel(" ")); center.add(n
46、ew JLabel(" ")); center.add(new JLabel(" 數(shù)學", SwingConstants.CENTER)); center.add(MAText); center.add(new JLabel(" ")); center.add(new JLabel(" ")); center.add(new JLabel("java", SwingConstants.CENTER)); center.add(JAVAText); center.add(new JLabel(" ")); c1.add(center); this.setVisible(true
47、); this.setBounds(200, 200, 400, 300); } public void actionPerformed(ActionEvent e){ if (e.getSource() == b1) { STNO = STNOText.getText(); DaoImpl dl = new DaoImpl(); Student stu = dl.findStudentByNum(STNO); if((STNO).equals(stu.getNum())) { SNAMEText.setText(stu.getName()); MAText.setText
48、(String.valueOf(stu.getShuxue())); CHIText.setText(String.valueOf(stu.getYuwen())); JAVAText.setText(String.valueOf(stu.getJava())); } } if (e.getSource() == b2) { this.dispose(); } } } 連庫源碼: package com.lb.dao; import java.sql.Connection; import java.sql.DriverManager; import java.sq
49、l.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import com.lb.bean.Student; public class Daolmpl { public Student login(String num,String pass){ Connection conn = null; PreparedStatement ps = null; ResultSet r
50、s = null; Student stu = new Student。; int sid = 0; try { Class.forName("com.mysql.jdbc.Driver"); conn DriverManager.getConnection("jdbc:mysql://localhost:3306/java","root","root"); String sql = "select * from user where num = ? and pass = ?"; ps = conn.prepareStatement(sql); ps.setString(1, n
51、um); ps.setString(2, pass); rs = ps.executeQuery(); while(rs.next()){ sid = rs.getInt("sid"); } String sql2 = "select * from student where id = "+sid; ps = conn.prepareStatement(sql); rs = ps.executeQuery(); while(rs.next()){ stu.setId(rs.getInt("id")); stu.setJava(rs.getInt("java")); stu
52、.setName(rs.getString("name")); stu.setNum(rs.getString("num")); stu.setShuxue(rs.getInt("shuxue")); stu.setYuwen(rs.getInt("yuwen")); } } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.p
53、rintStackTrace(); }finally{ try { if(ps != null){ ps.close(); } if(conn != null){ conn.close(); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return stu; } public void inseter(Student stu){ Connection conn = null; PreparedStatement ps = null;
54、 try { Class.forName("com.mysql.jdbc.Driver"); conn DriverManager.getConnection("jdbc:mysql://localhost:3306/java","root","root"); String sql ="insert into student values(null,?,?,?,?,?)"; ps = conn.prepareStatement(sql); ps.setString(1, stu.getName()); ps.setString(2,stu.getNum()); ps.setIn
55、t(3, stu.getYuwen()); ps.setInt(4, stu.getShuxue()); ps.setInt(5, stu.getJava()); ps.executeUpdate(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ try
56、 { if(ps != null){ ps.close(); } if(conn != null){ conn.close(); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void delete(String num){ Connection conn = null; PreparedStatement ps = null; try { Class.forName("com.mysql.jdbc.Driver")
57、; conn DriverManager.getConnection("jdbc:mysql://localhost:3306/java","root","root"); String sql = "delete from student where num = ?"; ps = conn.prepareStatement(sql); ps.setString(1, num); ps.executeUpdate(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printSta
58、ckTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ try { if(ps != null){ ps.close(); } if(conn != null){ conn.close(); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void update(Stud
59、ent stu){ Connection conn = null; PreparedStatement ps = null; try { Class.forName("com.mysql.jdbc.Driver"); conn DriverManager.getConnection("jdbc:mysql://localhost:3306/java","root","root"); String sql = "update student set name = ?,yuwen = ?,shuxue = ?,java = ? where num = ?"; ps = conn.pre
60、pareStatement(sql); ps.setString(1, stu.getName()); ps.setInt(2, stu.getYuwen()); ps.setInt(3, stu.getShuxue()); ps.setInt(4, stu.getJava()); ps.setString(5, stu.getNum()); ps.executeUpdate(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } cat
61、ch (SQLException e) {
// TODO Auto-generated catch block e.printStackTrace();
}finally{ try { if(ps != null){ ps.close();
}
if(conn != null){ conn.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block e.printStackTrace();
}
}
}
public List 62、t> li = new ArrayList 63、eStatement(sql);
rs = ps.executeQuery();
while(rs.next()){
Student stu = new Student。; stu.setId(rs.getInt("id"));
stu.setName(rs.getString("name")); stu.setNum(rs.getString("num")); stu.setYuwen(rs.getInt("yuwen")); stu.setShuxue(rs.getInt("shuxue")); stu.setJava(rs.getInt("java"));
li.add(stu 64、);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block e.printStackTrace();
}finally{
try {
if(rs != null){ rs.close();
}
if(ps != null){ ps.close();
}
if(conn != null){ conn.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block e.printStackTrace();
return li;
- 溫馨提示:
1: 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
2: 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
3.本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
5. 裝配圖網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 市教育局冬季運動會安全工作預案
- 2024年秋季《思想道德與法治》大作業(yè)及答案3套試卷
- 2024年教師年度考核表個人工作總結(jié)(可編輯)
- 2024年xx村兩委涉案資金退還保證書
- 2024年憲法宣傳周活動總結(jié)+在機關(guān)“弘揚憲法精神推動發(fā)改工作高質(zhì)量發(fā)展”專題宣講報告會上的講話
- 2024年XX村合作社年報總結(jié)
- 2024-2025年秋季第一學期初中歷史上冊教研組工作總結(jié)
- 2024年小學高級教師年終工作總結(jié)匯報
- 2024-2025年秋季第一學期初中物理上冊教研組工作總結(jié)
- 2024年xx鎮(zhèn)交通年度總結(jié)
- 2024-2025年秋季第一學期小學語文教師工作總結(jié)
- 2024年XX村陳規(guī)陋習整治報告
- 2025年學校元旦迎新盛典活動策劃方案
- 2024年學校周邊安全隱患自查報告
- 2024年XX鎮(zhèn)農(nóng)村規(guī)劃管控述職報告