java 备忘录编写源代码及运行界面截图.docx
《java 备忘录编写源代码及运行界面截图.docx》由会员分享,可在线阅读,更多相关《java 备忘录编写源代码及运行界面截图.docx(47页珍藏版)》请在冰点文库上搜索。
java备忘录编写源代码及运行界面截图
importjava.awt.*;
importjava.awt.event.*;
importjava.awt.image.BufferedImage;
importjava.io.*;
importjava.util.*;
importjavax.imageio.ImageIO;
importjavax.swing.*;
publicclassMemorialextendsJFrameimplementsActionListener{
/**
*@paramargs
*/
privateJLabeltitle,picture,mark,jl1,jl2,jl3,jl4;
privateJTextFieldjt1,jt2,jt3;
privateJButtonOk,Cancle;
privatestaticStringname1=null;
privatestaticStringpass1=null;
//结构函数
publicMemorial(){
title=newJLabel("我的备忘录");
picture=newJLabel(newImageIcon("photos/3.jpg"));//布景标签
/*mark=newJLabel(newImageIcon("3.jpg"));*/
jl1=newJLabel("登录名:
");
jl2=newJLabel("登录暗码:
");
jl3=newJLabel();
jl4=newJLabel("看不清");
jt1=newJTextField();
jt2=newJTextField();
jt3=newJTextField();
Ok=newJButton("登录");
Cancle=newJButton("撤消");
}
//页面计划
publicvoidlaunchFrame(){
JPanelp=(JPanel)getContentPane();
jl3.setText(getcode());
jl3.setForeground(Color.cyan);//设置验证码的色彩
jl3.setBorder(BorderFactory.createRaisedBevelBorder());//使验证码凸出显示
jl4.setForeground(Color.magenta);//设置“看不清”标签的前风景为洋红色
jl4.addMouseListener(newaddEvent());//为“看不清”标签添加鼠标监听器
Ok.addActionListener(this);//为“登录”按钮添加监听器
Cancle.addActionListener(this);//为“撤消”按钮添加监听器
Ok.setBorder(BorderFactory.createRaisedBevelBorder());//使按钮凸出显示
Cancle.setBorder(BorderFactory.createRaisedBevelBorder());
//****设置布景图片
p.setLayout(null);//运用setBounds(),必须使计划为null
picture.setBounds(0,0,500,330);
p.add(picture);
p.setOpaque(false);//使内容窗格透明
//把布景图片添加到分层窗格的最底层作为布景
getLayeredPane().add(picture,newInteger(Integer.MIN_VALUE));
//****设置标题
title.setForeground(Color.red);
title.setFont(newFont("汉文行楷",Font.BOLD,20));
title.setBounds(190,20,120,40);
p.add(title);
//****设置图标
BufferedImageicon=null;
try{
icon=ImageIO.read(newFile("photos/9.jpg"));
this.setIconImage(icon);
}catch(Exceptione){
}
jl1.setBounds(140,80,100,25);
p.add(jl1);
jt1.setBounds(240,80,100,25);
p.add(jt1);
jl2.setBounds(140,120,100,25);
p.add(jl2);
jt2.setBounds(240,120,100,25);
p.add(jt2);
jt3.setBounds(140,160,70,25);
p.add(jt3);
jl3.setBounds(250,160,40,25);
p.add(jl3);
jl4.setBounds(300,160,50,25);
p.add(jl4);
Ok.setBounds(150,220,60,30);
p.add(Ok);
Cancle.setBounds(260,220,60,30);
p.add(Cancle);
setTitle("登录界面");
setBounds(300,200,500,330);
setResizable(false);//窗口不克不及被拖动
setVisible(true);
setDefaultClo搜刮引擎优化peration(JFrame.EXIT_ON_CLOSE);
}
//获取验证码
publicStringgetcode(){
Randomrd=newRandom();
Stringstr="";
inta[]=newint[4];
for(inti=0;i<4;i++){
a[i]=rd.nextInt(200);
if((a[i]>=48&&a[i]<=57)||(a[i]>=65&&a[i]<=90)||(a[i]>=97&&a[i]<=122)){
str=str+(char)a[i];
}
else{//获取的字符不在规模内,获取未成功;
i;//i,包管最终获取到四位的验证码
}
}
returnstr;
}
//从文件中读取准确的用户名
publicstaticStringseekname()throwsIOException{
InputStreamfin1=newFileInputStream("message\\用户名.txt");
bytec[]=newbyte[10];
intlen=0;
while((len=fin1.read(c))!
=1){
name1=newString(c,0,len);
}
returnname1;
}
//从文件中读取准确的登录暗码
publicstaticStringseekpass()throwsIOException{
InputStreamfin2=newFileInputStream("message\\登录暗码.txt");
bytec[]=newbyte[10];
intlen=0;
while((len=fin2.read(c))!
=1){
pass1=newString(c,0,len);
}
returnpass1;
}
//断定文本框是否为空
publicbooleanisEmpty(JTextFieldjt){
if(jt.getText().equals("")){
returntrue;
}
returnfalse;
}
//断定操纵是否不法,主如果针对各文本框而言的;若文本框为空,提醒填写信息
publicbooleanisLegal(){
if(isEmpty(jt1)){
JOptionPane.showMessageDialog(null,"用户名不克不及为空!
");
returnfalse;
}elseif(isEmpty(jt2)){
JOptionPane.showMessageDialog(null,"暗码不克不及为空!
");
returnfalse;
}elseif(isEmpty(jt3)){
JOptionPane.showMessageDialog(null,"请输入验证码!
");
returnfalse;
}else{
returntrue;
}
}
//按钮事宜处理
@Override
publicvoidactionPerformed(ActionEvente){
//TODOAutogeneratedmethodstub
Objectsource=e.getSource();
Stringname2=jt1.getText();
Stringpass2=jt2.getText();
Stringcode2=jt3.getText();
Stringcode1=jl3.getText();
if(source==Ok){
if(isLegal()){//挪用isLegal()函数,包管文本框不为空
try{//挪用函数seekname(),seekpass(),文件可能不消失
if(name2.equals(seekname())){
if(pass2.equals(seekpass())){
if(code2.equalsIgnoreCase(code1)){
//在用户登录信息完整准确的前提下,进入备忘录(含日历)
JOptionPane.showMessageDialog(null,"登录成功!
");
Calendarcalendar=Calendar.getInstance();
inty=calendar.get(Calendar.YEAR);
intm=calendar.get(Calendar.MONTH)+1;
intd=calendar.get(Calendar.DAY_OF_MONTH);
newCalendarPad(y,m,d);
this.dispose();//封闭登录界面
}else{
JOptionPane.showMessageDialog(this,"验证码错误,请从新输入!
","错误提醒",JOptionPane.ERROR_MESSAGE);
jl3.setText(getcode());
}
}else{
JOptionPane.showMessageDialog(this,"暗码错误,请从新输入!
","错误提醒",JOptionPane.ERROR_MESSAGE);
}
}else{
JOptionPane.showMessageDialog(this,"您输入的用户名不消失,请从新输入!
","错误提醒",JOptionPane.ERROR_MESSAGE);
}
}catch(HeadlessException|IOExceptione1){
//TODOAutogeneratedcatchblock
e1.printStackTrace();
}
}
}
if(source==Cancle){
//讯问对话框
intchoose=JOptionPane.showConfirmDialog(null,"肯定撤消登录?
",
"讯问",JOptionPane.YES_NO_OPTION);
if(choose==JOptionPane.YES_OPTION)
System.exit(0);//退出登录体系
elseif(choose==JOptionPane.NO_OPTION){
}
}
}
classaddEventextendsMouseAdapter{
@Override
publicvoidmouseClicked(MouseEvente){
//TODOAutogeneratedmethodstub
jl3.setText(getcode());
}
}
publicstaticvoidmain(String[]args){
//TODOAutogeneratedmethodstub
newMemorial().launchFrame();
}
}
importjavax.swing.*;
importjava.awt.*;
importjava.awt.event.*;
publicclassYearextendsJPanel//ActionListener接口
{
privateintyear;
privateJTextFieldshowYear=null;
privateJButtonnextYear,lastYear;
privateCalendarPadcal;
publicYear(CalendarPadc)
{
showYear=newJTextField(4);
this.cal=c;
year=cal.getYear();
nextYear=newJButton("下年");
lastYear=newJButton("上年");
launch();
}
//计划函数
publicvoidlaunch(){
showYear.setForeground(Color.blue);
showYear.setFont(newFont("宋体",Font.BOLD,16));
setLayout(newGridLayout(1,3,5,5));
add(lastYear);
add(showYear);
add(nextYear);
showYear.addActionListener(newaddEvent());
lastYear.addActionListener(newaddEvent());
nextYear.addActionListener(newaddEvent());
lastYear.setBorder(BorderFactory.createRaisedBevelBorder());//使按钮凸出
nextYear.setBorder(BorderFactory.createRaisedBevelBorder());
}
//年
publicvoidsetYear(intyear)
{
this.year=year;
showYear.setText(""+year);
}
publicintgetYear()
{
returnyear;
}
//事宜类
classaddEventimplementsActionListener{
@Override
publicvoidactionPerformed(ActionEvente)
{
if(e.getSource()==lastYear)//对年份进行断定操纵
{
year=year1;
showYear.setText(""+year);
cal.setYear(year);
cal.setCal(year,cal.getMonth());
}
elseif(e.getSource()==nextYear)
{
year=year+1;
showYear.setText(""+year);
cal.setYear(year);
cal.setCal(year,cal.getMonth());
}
elseif(e.getSource()==showYear)
{
try
{
year=Integer.parseInt(showYear.getText());
//年份掌握在必定规模
if(year>=10000&&year<=10000){
showYear.setText(""+year);
cal.setYear(year);
cal.setCal(year,cal.getMonth());
}
else{
JOptionPane.showMessageDialog(null,"输入的年份有误,请从新输入!
","错误提醒",JOptionPane.ERROR_MESSAGE);
showYear.setText("");
}
}
catch(NumberFormatExceptionee)
{
JOptionPane.showMessageDialog(null,"请输入准确的年份格局!
","错误提醒",JOptionPane.ERROR_MESSAGE);
showYear.setText("");
}
}
}
}
}
//对月份的选择
importjavax.swing.*;
importjava.awt.*;
importjava.awt.event.*;
publicclassMonthextendsJPanel//ActionListener接口
{
privateintmonth;
privateJTextFieldshowMonth=null;
privateJButtonlastMonth,nextMonth;
privateCalendarPadcal;
publicMonth(CalendarPadc)
{
this.cal=c;
showMonth=newJTextField();
month=c.getMonth();
nextMonth=newJButton("下月");
lastMonth=newJButton("上月");
launch();
}
//页面计划
publicvoidlaunch(){
showMonth.setEditable(false);//设置月份不成被编辑
showMonth.setForeground(Color.blue);
showMonth.setFont(newFont("宋体",Font.BOLD,16));
setLayout(newGridLayout(1,3,5,5));
add(lastMonth);
add(showMonth);
add(nextMonth);
lastMonth.addActionListener(newaddEvent());
nextMonth.addActionListener(newaddEvent());
lastMonth.setBorder(BorderFactory.createRaisedBevelBorder());
nextMonth.setBorder(BorderFactory.createRaisedBevelBorder());
showMonth.setText(""+month);
}
publicvoidsetMonth(intmonth)
{
if(month<=12&&month>=1)
{
this.month=month;
}
else
{
this.month=1;
}
showMonth.setText(""+month);
}
publicintgetMonth()
{
returnmonth;
}
//事宜处理
classaddEventimplementsActionListener{
@Override
publicvoidactionPerformed(ActionEvente)
{
if(e.getSource()==lastMonth)
{
if(month>=2)
{
month=month1;
cal.setMonth(month);
cal.setCal(cal.getYear(),month);
}
elseif(month==1)
{
month=12;
cal.setMonth(month);
cal.setCal(cal.getYear(),month);
}
showMonth.setText(""+month);
}
elseif(e.getSource()==nextMonth)
{
if(month<12)
{
month=month+1;
cal.setMonth(month);
cal.setCal(cal.getYear(),month);
}
elseif(month==12)
{
month=1;
cal.setMonth(month);
cal.setCal(cal.getYear(),month);
}
showMonth.setText(""+month);
}
}
}
}
//提取当前的年代日时分秒,时钟
importjava.awt.*;
import