1、Java课程实验报告姓名: 易 乃 杰 学号:作业要求:编写一个万年历程序,要求能够查询历史时间,能够添加、查看、删除备忘录。项目概述:这个项目是一个简单的Java万年历,可以实现所有年份的公历日期的查询,并且在相应的日期做备忘录,以及可以显示当前的日期以及时间。程序截图:具体功能介绍:(1)万年历查询:点击图形界面中年份钱下拉框用来调整要查询的年份,点击月份前来调整要查询的月份,然后可以看到这个月的每一天所对应的星期。(2)Clock功能:在万年历下面显示当前的年月日时间,相当于一个时钟的功能。(3)记事本功能。 设计与实现(需要附全部代码,GUI自动生成代码除外):1 类的设计(继承、多态
2、、数据结构):核心类是CalendarWindow. findPassWordDialog等。2 Java IO ;文件访问 2 GUI (用户界面):点下划线来表示GUI用户界面6 其他功能:(无)程序代码:package app;import calendar.CalendarWindow;public class Client public static void main(String args) new CalendarWindow().setVisible(true);第一个包package account;public class Account private String n
3、ame;private String passWord;public Account(String name, String passWord) = name;this.passWord = passWord;public String getName() return name;public void setName(String name) = name;public String getPassWord() return passWord;public void setPassWord(String passWord) this.passWord =
4、 passWord;Overridepublic String toString() return 账户+name+,密码+passWord;Overridepublic boolean equals(Object obj) if (this = obj)return true;if (obj = null)return false;if (getClass() != obj.getClass()return false;Account other = (Account) obj;if (name = null) if ( != null)return false; els
用java基础编写日历实验报告
5、e if (!name.equals()return false;if (passWord = null) if (other.passWord != null)return false; else if (!passWord.equals(other.passWord)return false;return true;第二个包(含三个类)package calendar;public class CalendarWindow extends javax.swing.JFrame implements Observer private Time time;private i
6、nt year;private int month;private int day;private Week week;private Datex current;private ILoginService loginService;private boolean isLogin;private IEventService eventService;/* Creates new form TimeWindow */public CalendarWindow() initComponents();setLocationRelativeTo(null);loginService = new Log
7、inService();eventService=new EventService();init();private void init() table.setGridColor(Color.GREEN);table.setRowHeight(table.getRowHeight() * 2 + 9);time = new Time();week = new Week();current = time.getSystemDate();year = current.getYear();month = current.getMonth();day=current.getDay();TimeUnit
8、 unit = time.getSystemTime();hourText.setText(unit.getHour() + );secondText.setText(unit.getMinute() + );initTable(current);initComboBox();initInfoTextArea(current);/ 初始化ComboBoxprivate void initComboBox() for (int i = 0; i = 0; i-) if (week1.equals(weeksi)index = i;for (int j = index; j 7; j+)oj =
9、numx+;model.addRow(o);for (int i = 1; i 6; i+) o = new Object7;for (int j = 0; j 7; j+)if (numx = Uitll.lastday(today.getYear(), today.getMonth()oj = numx+;model.addRow(o);table.setModel(model);private void exitItemActionPerformed(java.awt.event.ActionEvent evt) System.exit(0);private void yearCombo
10、BoxActionPerformed(java.awt.event.ActionEvent evt) year = Integer.valueOf(yearComboBox.getSelectedItem().toString();Datex temp = new Datex(year, month, 1);initTable(temp);initInfoTextArea(temp);private void monthComboBoxActionPerformed(java.awt.event.ActionEvent evt) month = Integer.valueOf(monthCom
11、boBox.getSelectedItem().toString();Datex temp = new Datex(year, month, 1);initTable(temp);initInfoTextArea(temp);private void todayActionPerformed(java.awt.event.ActionEvent evt) initTable(time.getSystemDate();initInfoTextArea(current);private void loginButtonActionPerformed(java.awt.event.ActionEve
12、nt evt) isLogin = loginService.isOkOfLogin();if (isLogin) JOptionPane.showMessageDialog(this, 已登录,不能重复登录!);return;new loginDialog(this, loginService).setVisible(true);isLogin = loginService.isOkOfLogin();if (isLogin)setTitle(万年历 (登录状态: * 已登录 * );private void eventButtonActionPerformed(java.awt.event
13、.ActionEvent evt) if (isLogin)new EventDialog(this,new Datex(year,month,day),eventService).setVisible(true);else JOptionPane.showMessageDialog(this, 个人文档已加密,如需访问请先登录!);private void tableMouseClicked(java.awt.event.MouseEvent evt) int row = table.getSelectedRow();int column = table.getSelectedColumn(
14、);if (row 0 | column 0)return;try table.setSelectionBackground(Color.WHITE);table.setSelectionMode(1);day = Integer.valueOf(table.getValueAt(row, column).toString();initInfoTextArea(new Datex(year, month, day); catch (Exception e) package calendar;import dateandweek.Datex;import uitl.Uitll;public cl
15、ass Calendarx private Datex current;public Calendarx(int year, int month, int day) if (year = 0)throw new IllegalArgumentException(输入的年份有误!);if (month 12)throw new IllegalArgumentException(输入的月份有误!);if (day Uitll.lastday(year, month)throw new IllegalArgumentException(输入的日期有误!);current = new Datex(ye
16、ar, month, day);public Datex getcurrent() return current;public Datex getPreviousDate() int year = current.getYear();int month = current.getMonth();int day = current.getDay();if (current.getDay() != 1)return new Datex(year, month, day-1);if (current.getMonth() = 1)return new Datex(year - 1, 12, Uitl

17、l.lastday(year - 1, 12);return new Datex(year, month - 1,Uitll.lastday(year,month - 1);public Datex getNextDate() int year = current.getYear();int month = current.getMonth();int day = current.getDay();if (Uitll.lastday(year, month) != day)return new Datex(year, month, day + 1);if (month = 12) return
18、 new Datex(year + 1, 1, 1);return new Datex(year, month + 1, 1);/public int lastday(int year, int month)/ 使用数据表确定最后一天;/int m = 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ;/if (year % 4 = 0)/m2 = 29;/return mmonth;/第三个包(含两个类)package event;public class EventDialog extends javax.swing.JDialog pr
19、ivate Datex current;private IEventService eventService;private JFrame parent;public EventDialog(JFrame parent, Datex current, IEventService eventService) super(parent, true);initComponents();setLocationRelativeTo(parent);this.parent = parent;this.eventService = eventService;this.current = current;in
20、it();private void init() timeText.setText(current.toString();try int i = 0;String stateStrings = new String 一般, 较重要, 很重要 ;String statex = eventService.getState(current);stateText.setText(statex);for (i = 0; i 0|errorNumber20)JOptionPane.showMessageDialog(this, 填写的信息还有错,不能查找!); return;String passWord
21、=;try passWord=loginService.findPassWord(name,problem,answer); catch (Exception e) JOptionPane.showMessageDialog(this,e.getMessage();newPasswordText.setText(passWord);this.setVisible(true);private void nameTextFocusLost(java.awt.event.FocusEvent evt) errorNumber1=0;try name = nameText.getText().trim
22、();if (name.length() 15) nameOk.setText();errorNumber1+; else nameOk.setText();errorNumber1-; catch (Exception e) JOptionPane.showMessageDialog(this, 账户名不合法,此功能无法运行!);private void answerTextFocusLost(java.awt.event.FocusEvent evt) errorNumber2=0;try problem = problemComboBox.getSelectedItem().toStri
23、ng();answer = answerText.getText().trim();if (answer.length() = 0) problemOK.setText();errorNumber2+; else problemOK.setText();errorNumber2-; catch (Exception e) JOptionPane.showMessageDialog(this, 问题选择有误,此功能无法运行!);package login;import account.Account;public interface ILoginService /获得账户Account logi
24、nAccount(String newName,String newPassWord) throws RuntimeException;/获得Self账户Account getAccount() throws RuntimeException;/注册账户void registerAccount(String newName,String newPassWord,String problem,String answer)throws RuntimeException;/判断是否登录成功boolean isOkOfLogin();String findPassWord(String name,St
25、ring problem,String answer)throws RuntimeException;/判断记住密码是否已选择boolean isChooseOfPassWord();/设置记住密码,自动登录void set(String rembPassWord);package login;import java.awt.Color;import javax.swing.JOptionPane;import account.Account;public class loginDialog extends javax.swing.JDialog private ILoginService l
26、oginService;private boolean isRembPassWord = false;public loginDialog(java.awt.Frame parent, ILoginService loginService) super(parent, true);initComponents();setLocationRelativeTo(parent);this.loginService = loginService;initLogin();private void initLogin() try isRembPassWord = loginService.isChoose
27、OfPassWord();if (isRembPassWord)passwordCheckBox.setSelected(true);Account account = loginService.getAccount();if (isRembPassWord = false)return;accountText.setText(account.getName();passwordField.setText(account.getPassWord(); catch (Exception e) JOptionPane.showMessageDialog(this, 登录失败!);private v
28、oid findPasswordMouseExited(java.awt.event.MouseEvent evt) findPassword.setForeground(Color.BLACK);private void findPasswordMouseEntered(java.awt.event.MouseEvent evt) findPassword.setForeground(Color.RED);private void gainAccountMouseExited(java.awt.event.MouseEvent evt) gainAccount.setForeground(C
29、olor.BLACK);private void gainAccountMouseEntered(java.awt.event.MouseEvent evt) gainAccount.setForeground(Color.RED);private void passwordCheckBoxMouseClicked(java.awt.event.MouseEvent evt) String rembPassWord = 关;if (passwordCheckBox.isSelected()rembPassWord = 开;try loginService.set(rembPassWord);
30、catch (Exception e) JOptionPane.showMessageDialog(this, e.getMessage();private void findPasswordMouseClicked(java.awt.event.MouseEvent evt) new findPassWordDialog(this, loginService).setVisible(true);private void gainAccountMouseClicked(java.awt.event.MouseEvent evt) new RegisterAccountDialog(this,
31、loginService).setVisible(true);private void loginButtonActionPerformed(java.awt.event.ActionEvent evt) try String name = accountText.getText();if (name.equals() JOptionPane.showMessageDialog(this, 账户不能空!);return;String passWord = String.valueOf(passwordField.getPassword();if (passWord.equals() JOpti
32、onPane.showMessageDialog(this, 密码不能空!);return;loginService.loginAccount(name, passWord);this.setVisible(false); catch (Exception e) JOptionPane.showMessageDialog(this, e.getMessage();package login;import java.io.*;import java.util.Scanner;import account.Account;public class LoginService implements I
33、LoginService private String newName;private String newPassWord;Overridepublic Account loginAccount(String newName, String newPassWord)throws RuntimeException this.newName = newName;this.newPassWord = newPassWord;return judgeAccount(newName, newPassWord);private String readInfo(String fileName, int n
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/1074.html