JAVA报告完整.doc_第1页
JAVA报告完整.doc_第2页
JAVA报告完整.doc_第3页
JAVA报告完整.doc_第4页
JAVA报告完整.doc_第5页
已阅读5页,还剩16页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

JAVA语言课程设计 设计题目:学生信息管理系统院(系) 计算机科学与技术学院 专业名称 信息与计算科学 学生姓名 学生学号 指导教师 李玉红 同组姓名 2012年 3 月 18 日一、 课程设计目的1、 复习、巩固Java语言的基础知识,进一步加深对Java语言的理解和掌握;2、课程设计为学生提供了一个既动手又动脑,独立实践的机会,将课本上的理论知识和实际有机的结合起来,锻炼学生的分析解决实际问题的能力。提高学生适应实际,实践编程的能力;3、培养学生在项目开发中团队合作精神、创新意识及能力。二、课程设计的基本要求1、明确题目要求,进行需求分析;2、进行功能设计,编写设计说明;3、进行程序设计与调试;4、对设计过程进行系统的总结;5、界面美观大方;6、完成设计报告三、课程设计的主要内容利用学到的编程知识和编程技巧,通过具体项目的分析、设计和开发,掌握开发Java软件项目开发过程中所需要的软件技术并熟悉软件。以小组为单位,每组1至3名学生,设组长一名,负责该组设计工作的协调、分工等。每组完成二个题目(分别在两个部分中各选一题)。题目可由下面提供的选题中选择或学生自选经教师审核后方可。该组每个同学承担题目的不同部分,每位同学的课程设计报告必需独立完成。四、具体内容 计算器模拟程序功能要求: 该程序显示GUI用户界面,能实现整数的加、减、乘、除四则运算。 (一)、程序主要页面(二)java源代码import java.awt.*;import java.awt.event.*;import javax.swing.*;public class testZ extends JFrame implements ActionListener private JPanel jPanel1,jPanel2; private JTextField resultField; private JButton s1,s2,s3,s4,s5,s6,s7,s8,s9,s0,b1,b2,b3,b4,f1,f2; private boolean end,add,sub,mul,div; private String str; private double num1,num2; public testZ() super(计算器); setSize(300,240); Container con=getContentPane(); con.setLayout(new BorderLayout(); jPanel1=new JPanel(); jPanel1.setLayout(new GridLayout(1,1); jPanel2=new JPanel(); jPanel2.setLayout(new GridLayout(4,4); resultField=new JTextField(0); jPanel1.add(resultField); con.add(jPanel1,BorderLayout.NORTH); s1=new JButton( 1 ); s1.addActionListener(this); s2=new JButton( 2 ); s2.addActionListener(this); s3=new JButton( 3 ); s3.addActionListener(this); s4=new JButton( 4 ); s4.addActionListener(this); s5=new JButton( 5 ); s5.addActionListener(this); s6=new JButton( 6 ); s6.addActionListener(this); s7=new JButton( 7 ); s7.addActionListener(this); s8=new JButton( 8 ); s8.addActionListener(this); s9=new JButton( 9 ); s9.addActionListener(this); s0=new JButton( 0 ); s0.addActionListener(this); b1=new JButton( + ); b1.addActionListener(this); b2=new JButton( - ); b2.addActionListener(this); b3=new JButton( * ); b3.addActionListener(this); b4=new JButton( / ); b4.addActionListener(this); f1=new JButton( . ); f1.addActionListener(this); f2=new JButton( = ); f2.addActionListener(this); jPanel2.add(s1); jPanel2.add(s2); jPanel2.add(s3); jPanel2.add(b1); jPanel2.add(s4); jPanel2.add(s5); jPanel2.add(s6); jPanel2.add(b2); jPanel2.add(s7); jPanel2.add(s8); jPanel2.add(s9); jPanel2.add(b3); jPanel2.add(s0); jPanel2.add(f1); jPanel2.add(f2); jPanel2.add(b4); con.add(jPanel2,BorderLayout.CENTER); public void num(int i) String s = null; s=String.valueOf(i); if(end) /如果数字输入结束,则将文本框置零,重新输入 resultField.setText(0); end=false; if(resultField.getText().equals(0) /如果文本框的内容为零,则覆盖文本框的内容 resultField.setText(s); else /如果文本框的内容不为零,则在内容后面添加数字 str = resultField.getText() + s; resultField.setText(str); public void actionPerformed(ActionEvent e) /数字事件 if(e.getSource()=s1) num(1); else if(e.getSource()=s2) num(2); else if(e.getSource()=s3) num(3); else if(e.getSource()=s4) num(4); else if(e.getSource()=s5) num(5); else if(e.getSource()=s6) num(6); else if(e.getSource()=s7) num(7); else if(e.getSource()=s8) num(8); else if(e.getSource()=s9) num(9); else if(e.getSource()=s0) num(0); /符号事件 else if(e.getSource()=b1) sign(1); else if(e.getSource()=b2) sign(2); else if(e.getSource()=b3) sign(3); else if(e.getSource()=b4) sign(4); /等号 else if(e.getSource()=f1) str=resultField.getText(); if(str.indexOf(.)=1) str+=.; resultField.setText(str); else if(e.getSource()=f2) num2=Double.parseDouble(resultField.getText(); if(add) num1=num1 + num2; else if(sub) num1=num1 - num2; else if(mul) num1=num1 * num2; else if(div) num1=num1 / num2; resultField.setText(String.valueOf(num1); end=true; public void sign(int s) if(s=1) add=true; sub=false; mul=false; div=false; else if(s=2) add=false; sub=true; mul=false; div=false; else if(s=3) add=false; sub=false; mul=true; div=false; else if(s=4) add=false; sub=false; mul=false; div=true; num1=Double.parseDouble(resultField.getText(); end=true; public static void main(String args) testZ th1=new testZ(); th1.show(); 第二部分 图书管理系统要求:使用图形用户界面用数据库建立1或2个图书信息表。(不限使用哪种数据库)能连接数据库并实现查询、增、删、改等功能。 1、登录主页面2、 增加学生页面 3、修改学生页面 2 java源代码 1 登录代码package com.student;import java.awt.Color;import javax.swing.JOptionPane;/* * * author dell */public class Login extends javax.swing.JFrame /* * Creates new form Login */ public Login() initComponents(); this.getContentPane().setBackground(Color.pink); /* * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ SuppressWarnings(unchecked) / private void initComponents() jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jTextField1 = new javax.swing.JTextField(); jPasswordField1 = new javax.swing.JPasswordField(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jButton1.setText(登录); jButton1.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton1ActionPerformed(evt); ); jButton2.setText(取消); jButton2.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton2ActionPerformed(evt); ); jLabel1.setText(用户名:); jLabel2.setText(密码:); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane(); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createSequentialGroup() .addGap(43, 43, 43) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createSequentialGroup() .addComponent(jLabel1) .addGap(18, 18, 18) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup() .addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup() .addGap(59, 59, 59) .addComponent(jButton1) .addGap(34, 34, 34) .addComponent(jButton2) .addContainerGap(169, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(61, 61, 61) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(32, 32, 32) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton1) .addComponent(jButton2) .addGap(60, 60, 60) ); pack(); / private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here: String username=jTextField1.getText().trim(); String pass=jPasswordField1.getText(); if(.equals(username) JOptionPane.showMessageDialog(this, username is not null!); return; new MainJFrame(); this.dispose(); private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here: this.dispose(); /qu xiao /* * param args the command line arguments */ public static void main(String args) /* * Set the Nimbus look and feel */ / /* * If Nimbus (introduced in Java SE 6) is not available, stay with the * default look and feel. For details see * /javase/tutorial/uiswing/lookandfeel/plaf.html */ try for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels() if (Nimbus.equals(info.getName() javax.swing.UIManager.setLookAndFeel(info.getClassName(); break; catch (ClassNotFoundException ex) java.util.logging.Logger.getLogger(Login.class.getName().log(java.util.logging.Level.SEVERE, null, ex); catch (InstantiationException ex) java.util.logging.Logger.getLogger(Login.class.getName().log(java.util.logging.Level.SEVERE, null, ex); catch (IllegalAccessException ex) java.util.logging.Logger.getLogger(Login.class.getName().log(java.util.logging.Level.SEVERE, null, ex); catch (javax.swing.UnsupportedLookAndFeelException ex) java.util.logging.Logger.getLogger(Login.class.getName().log(java.util.logging.Level.SEVERE, null, ex); / /* * Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() public void run() new Login().setVisible(true); ); / Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JPasswordField jPasswordField1; private javax.swing.JTextField jTextField1; / End of variables declaration 2 . 主页面代码package com.student;import java.awt.CardLayout; /import:调用包中的类;awt:建立和设置图形用户界面import java.awt.Color; /color:颜色配置import java.awt.FlowLayout; /flowlayout:指定布局的对齐属性import java.awt.GridLayout; /gridlayout:在网格中徘布控件import java.awt.Toolkit; /toolkit:用于将各种组件绑定到特定本机工具包实现import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.util.Vector;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTable;import javax.swing.JTextField;import javax.swing.table.AbstractTableModel;import javax.swing.JDialog;import java.awt.Frame;/主窗体类public class MainJFrame extends JFrame implements ActionListener /* * param args the command line arguments */定义增删改查的按钮 JButton btn1,btn2,btn3,btn4; JButton jbtn1,jbtn2; /定义面板 JPanel jp1,jp2; /定义增加窗体 JFrame jf=null; /定义增加窗体内部的三个文本域 JTextField jtf1,jtf2,jtf3; /定义主窗体上表 JTable jt=null; /定义滚动条面板 JScrollPane jsp=null; /定义主窗体查询文本域 JTextField jtf=null;/定义与数据库操作的相关对象Connection ct=null;PreparedStatement ps=null;ResultSet rs=null;/主窗体构造函数public MainJFrame()jtf=new JTextField(12);jp2=new JPanel(new FlowLayout();btn1=new JButton(查询);btn2=new JButton(增加);btn3=new JButton(修改);btn4=new JButton(删除);btn2.setBackground(Color.GRAY);btn3.setBackground(Color.GRAY);btn4.setBackground(Color.GRAY);btn1.setBackground(Color.GRAY);btn1.addActionListener(this);btn2.addActionListener(this);btn3.addActionListener(this);btn4.addActionListener(this);int x=Toolkit.getDefaultToolkit().getScreenSize().width;int y=Toolkit.getDefaultToolkit().getScreenSize().height;jp1=new JPanel(new FlowLayout();jp2.add(jtf);jp2.add(btn1);jp2.setBackground(Color.GRAY);jp1.add(btn2);jp1.add(btn3);jp1.add(btn4);jp1.setBackground(Color.LIGHT_GRAY);MyTableModel mt=new MyTableModel(); jt=new JTable(mt);jsp=new JScrollPane(jt);this.add(jsp,Center);this.add(jp1,South);this.add(jp2,North);this.setSize(600,400);this.setLocation(x/2-350,y/2-250);this.setTitle(图书管理系统);this.setResizable(false);this.setVisible(true); /主窗体函数入口 public static void main(String args) / TODO code application logic here MainJFrame m= new MainJFrame(); /监听的实现(相应按钮事件) public void actionPerformed(ActionEvent e) /实现查询功能 if(e.getSource()=btn1) String str=jtf.getText().trim(); String strSQL=select * from book_info where ID=+str+; MyTableModel mt1=new MyTableModel(strSQL); jt.setModel(mt1); /实现修改功能 if(e.getSource()=btn3) int i= jt.getSelectedRow(); String str= (String)jt.getValueAt(i, 0); String str0=JOptionPane.showInputDialog(this, 输入你要修改的书号:, 图书馆管理系统, JOptionPane.CANCEL_OPTION); String str1=JOptionPane.showInputDialog(this, 输入你要修改的书名:, 图书馆管理系统, JOptionPane.CANCEL_OPTION); String str2=JOptionPane.showInputDialog(this, 输入你要修改的作者:, 图书馆管理系统, JOptionPane.CANCEL_OPTION); String strSQL=update book_info set id=+str0+,name=+str1+,author=+str2+ where id=+str+; String strSQL1=select * from book_info; MyTableModel mt1=new MyTableModel(strSQL,strSQL1); jt.setModel(mt1); /实现删除功能 if(e.getSource()=btn4) int i= jt.getSelectedRow(); String str1= (String)jt.getValueAt(i, 0); String str=delete from book_info where id=+str1+; String strSQL1=select * from book_info; MyTableModel mt1=new MyTableModel(str,strSQL1); jt.setModel(mt1); System.out.println(str1); /实现增加功能 if(e.getSource()=btn2) jf=new JFrame(增加信息); JPanel jp4=new JPanel(new GridLayout(3,2); JPanel jp5=new JPanel(new FlowLayout(); JLabel jb1,jb2,jb3; jbtn1=new JButton(确定添加); jbtn2=new JButton(取消添加); jbtn1.addActionListener(this); jbtn2.addActionListener(this); jp5.add(jbtn1); jp5.add(jbtn2); jb1=new JLabel(书号:,JLabel.RIGHT); jb2=new JLabel(书名:,JLabel.RIGHT);

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论