ImageVerifierCode 换一换
格式:DOCX , 页数:33 ,大小:25.30KB ,
资源ID:10997008      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/10997008.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(JAVA课程设计写字留痕.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

JAVA课程设计写字留痕.docx

1、JAVA课程设计写字留痕山东工商学院JAVA程序设计课程设计报告报告题目: JAVA写字留痕 所在院系: 计算机科学与技术学院 所在班级: 网络工程 姓 名: * 一设计思路 1. 作为日记本,为了保密性,设计了登陆界面,只有知道密码才能登陆到主界面,在主界面文本区,右键单击菜单可以进行密码的修改。如上图。2. 主界面用了两个Jpanel。左边的图片,日历等为一个JPanel;右边的文本框,JButton等为另一个JPanel。两个JPanel都是用的GridLayout,主界面的JFram用的是FlowLayout。如上图。3. 当更换日期,关闭窗口,点击保存,都能把当前日期的日记保存到磁盘

2、上。4. 当更换年月后,要先选择日期才能在文本区进行输入,否则会提示选择日期。JLable的显示内容会变为“请选择日期”。如下图。二实现代码1. 登陆界面的代码,只有输入正确的密码才能登陆日记程序。public class PassValidate extends JFrame implements ActionListener JPasswordField passfield; JLabel label,title1,title2,title3,title4; JButton yes,cancle; PassValidate() super(登录); setDefaultCloseOpera

3、tion(3); Toolkit tool=this.getToolkit(); Image im=tool.getImage(icon.jpg); this.setIconImage(im); /更换窗口图标 yes=new JButton(确定); yes.addActionListener(this); cancle=new JButton(取消); cancle.addActionListener(this); Container cc=this.getContentPane(); cc.setLayout(new FlowLayout(); label=new JLabel(请输入密

4、码:); title1=new JLabel( JAVA课程设计-写字留痕 ); title2=new JLabel(-); title3=new JLabel( 默认密码:123 登录后可更改密码 ); title4=new JLabel(-); passfield=new JPasswordField(15); passfield.setEchoChar(*); cc.add(title1); cc.add(title2); cc.add(title3); cc.add(title4); cc.add(label); cc.add(passfield); cc.add(yes); cc.a

5、dd(cancle); setSize(300,200); setVisible(true); setLocation(600, 250); setResizable(false); Override public void actionPerformed(ActionEvent e) / TODO Auto-generated method stub JButton b=(JButton) e.getSource(); if(b=yes) String journalpass = null; File fil=new File(datapass.info); char c=new char(

6、int) fil.length(); try FileReader in =new FileReader(fil); in.read(c); journalpass=new String(c); in.close(); catch (FileNotFoundException e1) / TODO Auto-generated catch block JOptionPane.showMessageDialog(null, 读文件时,没有找到pass.info文件。); /异常提示 e1.printStackTrace(); catch (IOException e1) / TODO Auto-

7、generated catch block JOptionPane.showMessageDialog(null, 读文件时,pass.info文件异常。); /异常提示 e1.printStackTrace(); String value=new String(passfield.getPassword(); if(value.endsWith(journalpass) new JournalTest(); this.dispose(); else passfield.setText(); JOptionPane.showMessageDialog(null, 密码错误,请重新输入。); e

8、lse System.exit(0); 2. 文本区JPanel的实现代码。public class FileEditor extends JPanel implements ActionListener JPanel buttonPanel; static JLabel title; JTextAreaWithMenu t; JButton save,delete,inport,outport; boolean dateexistence=true; int year; int mouth; int day; Hashtable data = new Hashtable(); File fi

9、le=new File(datadata.dat); ObjectOutputStream hashOut; ObjectInputStream hashIn; String journalpass; /构造函数 FileEditor() this.setLayout(new BorderLayout(5,5); journalpassInit(); titleInit(); buttonpanelInit(); t=new JTextAreaWithMenu(24,50); add(title,BorderLayout.NORTH); add(new JScrollPane(t),Borde

10、rLayout.CENTER); add(buttonPanel,BorderLayout.SOUTH); /密码初始 void journalpassInit() File fil=new File(datapass.info); char c=new char(int) fil.length(); try FileReader in =new FileReader(fil); in.read(c); journalpass=new String(c); catch (FileNotFoundException e) / TODO Auto-generated catch block JOp

11、tionPane.showMessageDialog(null, 读文件时,没有找到pass.info文件。); /异常提示 e.printStackTrace(); catch (IOException e) / TODO Auto-generated catch block JOptionPane.showMessageDialog(null, 读文件时,pass.info文件异常。); /异常提示 e.printStackTrace(); ; /测试save /打开hashtable void hashOpen() try hashIn=new ObjectInputStream(new

12、 FileInputStream(file); data=(Hashtable) hashIn.readObject(); if(data.containsKey(Integer.toString(year)+Integer.toString(mouth)+Integer.toString(day) t.setText(data.get(Integer.toString(year)+Integer.toString(mouth)+Integer.toString(day); else t.setText(); hashIn.close(); catch (FileNotFoundExcepti

13、on e) / TODO Auto-generated catch block JOptionPane.showMessageDialog(null, 读文件时,没有找到data文件。); /异常提示 e.printStackTrace(); catch (IOException e) / TODO Auto-generated catch block /JOptionPane.showMessageDialog(null, 读文件时,没有找到data文件,读文件异常。); /异常提示 e.printStackTrace(); catch (ClassNotFoundException e)

14、/ TODO Auto-generated catch block JOptionPane.showMessageDialog(null, 读文件时,没有找到hashtable。); e.printStackTrace(); /标题初始化 void titleInit() title=new JLabel(DateTime.getYear()+年+DateTime.getMouth()+月+DateTime.getDay()+日); title.setFont(new Font(TimesRomn,Font.BOLD,18); title.setHorizontalAlignment(Swin

15、gConstants.CENTER); void setDateexistence(boolean b) dateexistence=b; void setCalendar(int year,int mouth,int day) this.year=year; this.mouth=mouth; this.day=day; t.setDay(day); /四个按钮初始化 void buttonpanelInit() buttonPanel=new JPanel(new FlowLayout(); save=new JButton(保存); save.setFont(new Font(Times

16、Romn,Font.BOLD,12); save.addActionListener(this); delete=new JButton(删除); delete.setFont(new Font(TimesRomn,Font.BOLD,12); delete.addActionListener(this); inport=new JButton(导入); inport.setFont(new Font(TimesRomn,Font.BOLD,12); inport.addActionListener(this); outport=new JButton(导出); outport.setFont

17、(new Font(TimesRomn,Font.BOLD,12); outport.addActionListener(this); buttonPanel.add(save); buttonPanel.add(delete); buttonPanel.add(inport); buttonPanel.add(outport); void setTitle(int year,int mouth,int day) if(day!=0) remove(title); title=new JLabel(year+年+mouth+月+day+日); title.setFont(new Font(Ti

18、mesRomn,Font.BOLD,18); title.setHorizontalAlignment(SwingConstants.CENTER); add(title,BorderLayout.NORTH); validate(); setDateexistence(true); /设置dateexistence else remove(title); title=new JLabel(请选择日期); title.setFont(new Font(TimesRomn,Font.BOLD,18); title.setHorizontalAlignment(SwingConstants.CEN

19、TER); add(title,BorderLayout.NORTH); validate(); setDateexistence(false); /设置dateexistence /钮事件处理 void dataSave() try hashOut= new ObjectOutputStream(new FileOutputStream(file); catch (FileNotFoundException e2) / TODO Auto-generated catch block JOptionPane.showMessageDialog(null, save:写文件时,没有找到data文

20、件。); /异常提示 e2.printStackTrace(); catch (IOException e2) / TODO Auto-generated catch block JOptionPane.showMessageDialog(null, save:写文件时,没有找到data文件,写入异常。); /异常提示 e2.printStackTrace(); if(data.containsKey(Integer.toString(year)+Integer.toString(mouth)+Integer.toString(day)&t.getText().trim().equals()

21、data.remove(Integer.toString(year)+Integer.toString(mouth)+Integer.toString(day); if(!t.getText().trim().equals() try data.put(Integer.toString(year)+Integer.toString(mouth)+Integer.toString(day),t.getText(); hashOut.writeObject(data); hashOut.close(); indatasave); /测试save catch (IOException e1) / T

22、ODO Auto-generated catch block JOptionPane.showMessageDialog(null, save:无法保存文件,Objectoutputstream异常。); /异常提示 e1.printStackTrace(); else try hashOut.close(); catch (IOException e) / TODO Auto-generated catch block e.printStackTrace(); datasave); /测试save void newDate() if(data.get(Integer.toString(yea

23、r)+Integer.toString(mouth)+Integer.toString(day)!=null) t.setText(data.get(Integer.toString(year)+Integer.toString(mouth)+Integer.toString(day); else t.setText(); /删除日记 void dataDelete() /判断是当前日期是否有日记,给提示,然后删除, if(data.containsKey(Integer.toString(year)+Integer.toString(mouth)+Integer.toString(day)

24、if(JOptionPane.showConfirmDialog(null, 询问, 是否删除+year+年+mouth+月+day+日+的日记记录?, JOptionPane.YES_NO_OPTION)=JOptionPane.YES_OPTION) data.remove(Integer.toString(year)+Integer.toString(mouth)+Integer.toString(day); t.setText(); else JOptionPane.showMessageDialog(null, 此日期无日志。); /异常提示 /导入日记 void inport()

25、JFileChooser fc = new JFileChooser(); fc.setFileFilter(new TxtFilter(); int val=fc.showOpenDialog(this); if(val=fc.APPROVE_OPTION) File name=fc.getSelectedFile(); char c=new char(int) name.length(); FileReader in; try in = new FileReader(name); in.read(c); t.setText(new String(c); dataSave(); in.clo

26、se(); catch (FileNotFoundException e) / TODO Auto-generated catch block e.printStackTrace(); catch (IOException e) / TODO Auto-generated catch block e.printStackTrace(); /导出日记 void outport() String pass = JOptionPane.showInputDialog(请输入密码!); if(!pass.equals(journalpass) JOptionPane.showMessageDialog

27、(new JDialog(),密码错误,不能导出!); return ; JFileChooser fc = new JFileChooser(); fc.setFileFilter(new TxtFilter(); fc.showSaveDialog(this); File name = fc.getSelectedFile(); if(name = null) return ; try ObjectInputStream in = new ObjectInputStream(new FileInputStream(file); PrintWriter out = new PrintWriter(new FileOutputStream(name); Hashtable o = (Hashtable)in.readObject(); TreeMap map = new TreeMap(o); Set mapping = map.entrySet(); for (Iterator i = mapping.iterator(); i.hasNext();) Map.Entry me = (Map.Entry)i.next(); out.println(me.getKey(); out.println(String)

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1