搜档网
当前位置:搜档网 › java日历时钟小程序

java日历时钟小程序

java日历时钟小程序
java日历时钟小程序

Java时钟程序,按类粘贴至编译器编译即可使用。

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.util.Calendar;

import java.util.Date;

import java.util.GregorianCalendar;

import javax.swing.JComboBox;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JButton;

public class Calendar1 extends JPanel implements ActionListener{

JLabel[] daylabel=new JLabel[49];

JLabel lYear=new JLabel("年");

JLabel lMonth=new JLabel("月");

JLabel lback=new JLabel("背景色");

JButton retu=new JButton("返回");

Date nowdate=new Date();

int month=0;

String year=null;

String back=null;

int nowyear=nowdate.getYear()+1900;

int nowmonth=nowdate.getMonth();

boolean bool=false;

JComboBox comboboxyear=new JComboBox();

JComboBox comboboxmonth=new JComboBox();

JComboBox comboboxback=new JComboBox();

JPanel pYearMonth=new JPanel();

//JPanel pMonth=new JPanel();

JPanel pDay=new JPanel();

//JPanel panel=new JPanel();

Calendar c=Calendar.getInstance();

Calendar1(){

//super("日历");

comboboxback.addItem("默认"); comboboxback.addItem("红粉"); comboboxback.addItem("黑夜");

for(int i=nowyear-10;i

comboboxyear.addItem(i+"");

for(int i=1;i<13;i++)

comboboxmonth.addItem(i+"");

comboboxyear.setSelectedIndex(10);

pYearMonth.add(new JLabel(" "));

pYearMonth.add(comboboxyear);

pYearMonth.add(lYear);

comboboxmonth.setSelectedIndex(nowmonth);

pYearMonth.add(comboboxmonth);

pYearMonth.add(lMonth);

pYearMonth.add(new JLabel(" "));

pYearMonth.setBackground(Color.PINK);

pYearMonth.setForeground(Color.red);

comboboxback.setSelectedItem("默认");

pYearMonth.add(new JLabel(" "));

pYearMonth.add(comboboxback);

pYearMonth.add(lback);

pYearMonth.add(retu);

comboboxyear.addActionListener(this);

comboboxmonth.addActionListener(this);

comboboxback.addActionListener(this);

retu.addActionListener(this);

pDay.setLayout(new GridLayout(7,7,10,10));

for(int i=0;i<49;i++){

daylabel[i]=new JLabel(" ");

pDay.add(daylabel[i]);

}

this.setDay();

this.setLayout(new BorderLayout());

//panel.setLayout(new BorderLayout());

this.add(pYearMonth,BorderLayout.NORTH);

this.add(pDay,BorderLayout.CENTER);

//this.setLayout(new BorderLayout());

//this.add(panel);

}

public void setDay(){

if(bool){

year=nowyear+"";

month=nowdate.getMonth();

back="默认";

comboboxmonth.setSelectedIndex(nowmonth);

comboboxyear.setSelectedIndex(10);

}

else{

year=comboboxyear.getSelectedItem().toString();

month=comboboxmonth.getSelectedIndex();

back=comboboxback.getSelectedItem().toString();

}

int year_Y=Integer.parseInt(year)-1900;

Date dt=new Date(year_Y,month,1);

GregorianCalendar calendar=new GregorianCalendar();

Calendar cal=Calendar.getInstance();

cal.set(year_Y,month,1);

//calendar.setTime(dt);

String[] week={"日","一","二","三","四","五","六"};

int day=0,dayweek=0;

day=cal.getActualMaximum(Calendar.DAY_OF_MONTH);

for(int i=0;i<7;i++){//第一行的Label设置为星期

daylabel[i].setForeground(Color.orange);

daylabel[i].setText(week[i]);

daylabel[i].setOpaque(true);

if(back=="默认")

daylabel[i].setBackground(Color.GRAY);

else if(back=="红粉")

daylabel[i].setBackground(Color.darkGray);

else

daylabel[i].setBackground(Color.gray);

}

if(month==0||month==2||month==4||month==6||month==7||month==9||month==11) day=31;

else if(month==3||month==5||month==8||month==10)

day=30;

else{

if(calendar.isLeapYear(year_Y))

day=29;

else day=28;

}

dayweek=7+dt.getDay();

//dayweek=7+cal.get(Calendar.DAY_OF_WEEK);//???

int count=1;

for(int i=dayweek;i

if(i%7==0||(i+1)%7==0){

if(i==dayweek+nowdate.getDate()-1&&month==nowdate.getMonth()){ daylabel[i].setForeground(Color.blue);

daylabel[i].setText(count+"");

daylabel[i].setOpaque(true);

daylabel[i].setToolTipText(judgefestvial(month+1,count));

if(back=="默认")

daylabel[i].setBackground(Color.pink);

else if(back=="红粉")

daylabel[i].setBackground(Color.pink);

else

daylabel[i].setBackground(Color.gray);

}

else{

daylabel[i].setForeground(Color.green);

daylabel[i].setText(count+"");

daylabel[i].setOpaque(true);

daylabel[i].setToolTipText(judgefestvial(month+1,count));

if(back=="默认")

daylabel[i].setBackground(Color.GRAY);

else if(back=="红粉")

{

daylabel[i].setBackground(Color.pink);

daylabel[i].setForeground(Color.gray);

}

else

daylabel[i].setBackground(Color.DARK_GRAY);

}

}

else{

if(i==dayweek+nowdate.getDate()-1&&month==nowdate.getMonth()){ daylabel[i].setForeground(Color.blue);

daylabel[i].setText(count+"");

daylabel[i].setOpaque(true);

daylabel[i].setToolTipText(judgefestvial(month+1,count));

if(back=="默认")

daylabel[i].setBackground(Color.PINK);

else if(back=="红粉")

daylabel[i].setBackground(Color.pink);

else

daylabel[i].setBackground(Color.white);

}

else{

daylabel[i].setForeground(Color.black);

daylabel[i].setText(count+"");

daylabel[i].setOpaque(true);

daylabel[i].setToolTipText(judgefestvial(month+1,count));

if(back=="默认")

daylabel[i].setBackground(Color.white);

else if(back=="红粉")

daylabel[i].setBackground(Color.red);

else

{

daylabel[i].setBackground(Color.BLACK);

daylabel[i].setForeground(Color.white);

}

}

}

}

if(dayweek==0){//为什么是0而不是7

for(int i=day;i<49;i++){

daylabel[i].setText("");

}

}

else{

for(int i=7;i

daylabel[i].setText("");

for(int i=dayweek+day;i<49;i++)

daylabel[i].setText("");

}

}

public String judgefestvial(int j,int k)

{

if(j==1)

{

if(k==1)

return "元旦";

}

if(j==2)

{

if(k==14)

return "情人节";

else if(k==24)

return "国际青年日";

}

if(j==3)

{

if(k==8)

return "国际妇女节";

else if(k==12)

return "中国植树节";

else if(k==23)

return "世界气象日";

}

if(j==4)

{

if(k==1)

return "愚人节";

}

if(j==5&&k==1)

return "国际劳动节";

if(j==6&&k==1)

return "国际儿童节";

if(j==10&&k==1)

return "国庆节";

if(j==12&&k==25)

return "圣诞节";

else

return "无节日";

}

public void actionPerformed(ActionEvent e){

if(e.getSource()==comboboxyear||e.getSource()==comboboxmonth||e.getSource()==combobox back){

bool=false;

//System.out.println(c.get(Calendar.DAY_OF_WEEK));

this.setDay();

}

else if(e.getSource()==retu)

{

bool=true;

this.setDay();

}

}

public static void main(String args[]){

Calendar1 text=new Calendar1();

JFrame jf=new JFrame();

JPanel jpan=new JPanel();

jf.add(text);

jf.setSize(400,400);

jf.setVisible(true);

jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

}

import java.awt.Color;

import java.awt.Font;

import java.awt.Graphics;

import java.awt.image.BufferedImage;

import java.util.Calendar;

import java.util.Date;

import javax.swing.JFrame;

import javax.swing.JPanel;

public class Clock2 extends JPanel implements Runnable{

double PI=Math.PI;//圆周率

double hourlen=25;//时针长度

double minutelen=35;//分针长度

double secondlen=45;//秒针长度

int yuanxinx=200,yuanxiny=200;//圆心坐标

int banjin=50;//半径长度

int qix,qiy,zhongxh,zhongxm,zhongxs,zhongyh,zhongym,zhongys;//各指针的起点和终点坐标(起点一致)

Thread th;

BufferedImage buf;

int hour,minute,second;//记录当前时间

Calendar calendar;//用于获取当前时间

Graphics g1;//用于内存绘图

public void Clock2(){

hour=minute=second=0;

buf=new BufferedImage(400,400,BufferedImage.TYPE_INT_ARGB);//控制内存绘图区域大小

g1=buf.getGraphics();//创建缓冲绘图区

new Thread(this).start();

this.setSize(400,400);

}

public void start(){

if(th==null)

th=new Thread(this);

th.start();//启动线程

}

public void stop(){

th=null;//终止线程

}

public void run(){//线程的覆盖方法

while(true){

try{

th.sleep(1000);

}catch(Exception e){}

//用背景色填充绘图区,擦除上次绘图

repaint();

}

}

public void paint(Graphics g){

super.paintComponent(g);

//将图像先画到缓冲区

g.setColor(this.getForeground());

//绘制时钟刻盘(刻度长度为8)

g.drawOval(121,123,150,150);

//特殊位置简便画法

//1

int qixx=(int)(yuanxinx-banjin*Math.cos((0.5+1.0/6)*PI));

int qiyy=(int)(yuanxiny-banjin*Math.sin((0.5+1.0/6)*PI));

int zhongxx=(int)(yuanxinx-(banjin-8)*Math.cos((0.5+1.0/6)*PI));

int zhongyy=(int)(yuanxiny-(banjin-8)*Math.sin((0.5+1.0/6)*PI));

g.drawLine(qixx,qiyy,zhongxx,zhongyy);

g.drawString("1", zhongxx+3 , zhongyy-10);

//2

qixx=(int)(yuanxinx-banjin*Math.cos((0.5+2.0/6)*PI));

qiyy=(int)(yuanxiny-banjin*Math.sin((0.5+2.0/6)*PI));

zhongxx=(int)(yuanxinx-(banjin-8)*Math.cos((0.5+2.0/6)*PI));

zhongyy=(int)(yuanxiny-(banjin-8)*Math.sin((0.5+2.0/6)*PI));

g.drawLine(qixx,qiyy,zhongxx,zhongyy);

g.drawString("2", zhongxx+10 , zhongyy-2);

//3

qixx=(int)(yuanxinx-banjin*Math.cos((0.5+3.0/6)*PI));

qiyy=(int)(yuanxiny-banjin*Math.sin((0.5+3.0/6)*PI));

zhongxx=(int)(yuanxinx-(banjin-8)*Math.cos((0.5+3.0/6)*PI));

zhongyy=(int)(yuanxiny-(banjin-8)*Math.sin((0.5+3.0/6)*PI));

g.drawLine(qixx,qiyy,zhongxx,zhongyy);

g.drawString("3", zhongxx+10 , zhongyy+3);

//4

qixx=(int)(yuanxinx-banjin*Math.cos((0.5+4.0/6)*PI));

qiyy=(int)(yuanxiny-banjin*Math.sin((0.5+4.0/6)*PI)); zhongxx=(int)(yuanxinx-(banjin-8)*Math.cos((0.5+4.0/6)*PI)); zhongyy=(int)(yuanxiny-(banjin-8)*Math.sin((0.5+4.0/6)*PI));

g.drawLine(qixx,qiyy,zhongxx,zhongyy);

g.drawString("4", zhongxx+10 , zhongyy+10);

//5

qixx=(int)(yuanxinx-banjin*Math.cos((0.5+5.0/6)*PI));

qiyy=(int)(yuanxiny-banjin*Math.sin((0.5+5.0/6)*PI)); zhongxx=(int)(yuanxinx-(banjin-8)*Math.cos((0.5+5.0/6)*PI)); zhongyy=(int)(yuanxiny-(banjin-8)*Math.sin((0.5+5.0/6)*PI));

g.drawLine(qixx,qiyy,zhongxx,zhongyy);

g.drawString("5", zhongxx+5 , zhongyy+15);

//6

qixx=(int)(yuanxinx-banjin*Math.cos((0.5+6.0/6)*PI));

qiyy=(int)(yuanxiny-banjin*Math.sin((0.5+6.0/6)*PI)); zhongxx=(int)(yuanxinx-(banjin-8)*Math.cos((0.5+6.0/6)*PI)); zhongyy=(int)(yuanxiny-(banjin-8)*Math.sin((0.5+6.0/6)*PI));

g.drawLine(qixx,qiyy,zhongxx,zhongyy);

g.drawString("6", zhongxx-5 , zhongyy+20);

//7

qixx=(int)(yuanxinx-banjin*Math.cos((0.5+7.0/6)*PI));

qiyy=(int)(yuanxiny-banjin*Math.sin((0.5+7.0/6)*PI)); zhongxx=(int)(yuanxinx-(banjin-8)*Math.cos((0.5+7.0/6)*PI)); zhongyy=(int)(yuanxiny-(banjin-8)*Math.sin((0.5+7.0/6)*PI));

g.drawLine(qixx,qiyy,zhongxx,zhongyy);

g.drawString("7", zhongxx-10 , zhongyy+20);

//8

qixx=(int)(yuanxinx-banjin*Math.cos((0.5+8.0/6)*PI));

qiyy=(int)(yuanxiny-banjin*Math.sin((0.5+8.0/6)*PI)); zhongxx=(int)(yuanxinx-(banjin-8)*Math.cos((0.5+8.0/6)*PI)); zhongyy=(int)(yuanxiny-(banjin-8)*Math.sin((0.5+8.0/6)*PI));

g.drawLine(qixx,qiyy,zhongxx,zhongyy);

g.drawString("8", zhongxx-20 , zhongyy+10);

//9

qixx=(int)(yuanxinx-banjin*Math.cos((0.5+9.0/6)*PI));

qiyy=(int)(yuanxiny-banjin*Math.sin((0.5+9.0/6)*PI)); zhongxx=(int)(yuanxinx-(banjin-8)*Math.cos((0.5+9.0/6)*PI)); zhongyy=(int)(yuanxiny-(banjin-8)*Math.sin((0.5+9.0/6)*PI));

g.drawLine(qixx,qiyy,zhongxx,zhongyy);

g.drawString("9", zhongxx-20 , zhongyy+3);

//10

qixx=(int)(yuanxinx-banjin*Math.cos((0.5+10.0/6)*PI));

qiyy=(int)(yuanxiny-banjin*Math.sin((0.5+10.0/6)*PI));

zhongxx=(int)(yuanxinx-(banjin-8)*Math.cos((0.5+10.0/6)*PI));

zhongyy=(int)(yuanxiny-(banjin-8)*Math.sin((0.5+10.0/6)*PI));

g.drawLine(qixx,qiyy,zhongxx,zhongyy);

g.drawString("10", zhongxx-25 , zhongyy-4);

//11

qixx=(int)(yuanxinx-banjin*Math.cos((0.5+11.0/6)*PI));

qiyy=(int)(yuanxiny-banjin*Math.sin((0.5+11.0/6)*PI));

zhongxx=(int)(yuanxinx-(banjin-8)*Math.cos((0.5+11.0/6)*PI));

zhongyy=(int)(yuanxiny-(banjin-8)*Math.sin((0.5+11.0/6)*PI));

g.drawLine(qixx,qiyy,zhongxx,zhongyy);

g.drawString("11", zhongxx-15 , zhongyy-13);

//12

qixx=(int)(yuanxinx-banjin*Math.cos((0.5+12.0/6)*PI));

qiyy=(int)(yuanxiny-banjin*Math.sin((0.5+12.0/6)*PI));

zhongxx=(int)(yuanxinx-(banjin-8)*Math.cos((0.5+12.0/6)*PI));

zhongyy=(int)(yuanxiny-(banjin-8)*Math.sin((0.5+12.0/6)*PI));

g.drawLine(qixx,qiyy,zhongxx,zhongyy);

g.drawString("12", zhongxx-5 , zhongyy-13);

//g1.drawLine(150,15,140,25);

//g1.drawString(""+qixx+" "+qiyy+" "+zhongxx+" "+zhongyy,200,300);

//获取当前时间

Calendar calendar=Calendar.getInstance();

hour=calendar.get(Calendar.HOUR);

minute=calendar.get(Calendar.MINUTE);

second=calendar.get(Calendar.SECOND);

//计算指针坐标

qix=qiy=yuanxinx;

zhongxh=(int)(yuanxinx-hourlen*Math.cos((0.5+2.0*hour/12)*Math.PI)); zhongyh=(int)(yuanxiny-hourlen*Math.sin((0.5+2.0*hour/12)*Math.PI)); zhongxm=(int)(yuanxinx-minutelen*Math.cos((0.5+2.0*minute/60)*Math.PI)); zhongym=(int)(yuanxiny-minutelen*Math.sin((0.5+2.0*minute/60)*Math.PI)); zhongxs=(int)(yuanxinx-secondlen*Math.cos((0.5+2.0*second/60)*Math.PI)); zhongys=(int)(yuanxiny-secondlen*Math.sin((0.5+2.0*second/60)*Math.PI));

//绘制指针

Font oldfont=this.getFont();

g.setColor(Color.red);

g.setFont(new Font(oldfont.getName(),Font.BOLD,oldfont.getStyle()+20)); g.drawLine(qix,qiy,zhongxh,zhongyh);

g.setColor(Color.green);

g.setFont(new Font(oldfont.getName(),Font.BOLD,oldfont.getStyle()+15)); g.drawLine(qix,qiy,zhongxm,zhongym);

g.setColor(Color.blue);

g.setFont(new Font(oldfont.getName(),Font.BOLD,oldfont.getStyle()+10));

g.drawLine(qix,qiy,zhongxs,zhongys);

//输出时间、日期

g.setFont(new Font("Time New Roman",Font.BOLD,25));

g.setColor(Color.PINK);

g.drawString(""+hour+":"+minute+":"+second,150,100);

g.setFont(new Font("Time New Roman",Font.BOLD,18));

g.setColor(Color.green);

g.drawString("中国标准时间Chinese Standard Time",25,320);

g.setFont(new Font("Time New Roman",Font.BOLD,20));

g.setColor(Color.blue);

g.drawString(new Date().toString(), 10,25);

//g.drawString(""+hour+" "+minute+" "+second, 200,200);

//g.drawImage(buf, 0,0, this);//将缓冲区图像画到JApplet上

repaint();

}

public void update(Graphics g){//覆盖方法

paint(g);

}

public static void main(String args[]){

JFrame jf=new JFrame();

jf.add(new Clock2());

jf.setSize(400,400);

jf.setVisible(true);

jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

}

import java.awt.BorderLayout;

import java.awt.GridLayout;

import javax.swing.JFrame;

import javax.swing.JPanel;

public class Rili extends JFrame{

Clock2 clock;//新建时钟类对象

Calendar1 calendar; //新建日历类对象

JPanel panel;

Rili(){

panel=new JPanel();

panel.setLayout(new GridLayout());

clock=new Clock2();

calendar=new Calendar1();

panel.add(clock);

panel.add(calendar);

this.add(panel);

//this.add(clock,BorderLayout.WEST);

//this.add(calendar,BorderLayout.EAST);

}

public static void main(String args[]){

Rili r=new Rili();

r.setSize(800,400);

r.setVisible(true);

r.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

}

Java课程设计实验报告及全部源码流程图

课程设计 一、实验目的 1.加深对课堂讲授内容的理解,掌握解决实际应用问题时所应具有的查阅资料、技术标准和规范,以及软件编程、调试等能力,掌握面向对象的编程思想及Java语言程序设计的规律与技巧,为进一步学习web应用开发及今后从事专业工作打下基础。 2. 使用本学期学习的Java SE技术(也可以使用课堂教学中没有学习过的Java技术,但是应当以Java SE技术为主)完成多功能日历GUI程序的设计,使之具有如下基本功能:一年日历用12页显示,每页显示一个月的日历。日历可以按年或月前后翻动,能够显示当前的日期,可以为每页日历选择背景图片。 3.在完成基本功能的基础上发挥自己的想象力与创造力,使程序凸显出与众不同的特点与功能,形成本小组的特性色。 二、实验要求 1.问题描述准确、规范。 2.程序结构合理,调试数据准确、有代表性.。 3.界面布局整齐,人机交互方便。 4.输出结果正确。 5.正确撰写实验报告。 三、实验内容 编写一个GUI程序实现日历的功能。一年日历用12页显示,每页显示一个月的日历。日历可以按年或月前后翻动,能够显示当前的日期以及当前农历,可以为每页日历选择背景图片。可以实现显示时钟,时钟能进行整点报

时。可以实现备忘记事功能,能在每天添加、修改、删除记事等操作。 四、实验步骤 1.在上机实验前,小组成员进行选题讨论,确定小组感兴趣而又伸缩性强的题目多功能日历。 2.在第一次上机实验时讨论分工,分工明确之后,分头合作进行。 3.各成员完成自己的任务后,最后进行统筹合并,以及程序最后的优化。 4. 根据实验结果,写出合肥工业大学实验报告。实验报告应当包括:实验内容,程序流程图,类结构,程序清单,运行结果,以及通过上机取得的经验。 5.详细的上机实验步骤见任务分工及程序设计进度表。 五、实验结果 经过小组成员的共同努力,最终我们小组设计的多功能日历程序能够实现实验的基本要求——一年日历用12页显示,每页显示一个月的日历。日历可以按年或月前后翻动,能够显示当前的日期,可以为每页日历选择背景图片。另外,在完成基本要求的基础上,我们增添了显示农历、显示时钟、添加备忘录、修改备忘录等功能。整体程序运行流畅、功能齐全、符合操作习惯。 下面是程序运行效果截图: 日历主界面(可以实现每个月的日历,可以按年或按月前后翻动,能够显示当前日期,并能够选择背景图片):

java课程设计策画日历记事本

课程设计说明书 课程: Java程序设计 院系:计算机科学学院 专业班级:计算机科学与技术(2)班 组员:张少华、张天阳 2010年6月 26 日

《Java程序设计》课程设计 ——日历记事本 我们开发了一个实现有日历标记的记事本软件,日历记事本面板由日历和和记事本两部分组成。日历部分可以调节年份,月份,日期,星期。记事本可以实行查看,保存,删除等操作,并且每一步操作都有相应提示。本软件是一个实用性很强,简洁,方便的功能软件。 引言 Java是一种纯面向对象的、网络编程首选的语言。Java技术作为软件开的一种革命性技术,已被列为当今世界信息技术的主流之一。为了适应时代潮流,我们应该加强对Java的学习,更好的掌握这门课程。为此,我们成了一个课程小组,经过小组成的商讨之后,我们决定以“日历记事本”为设题材,借此巩固加深我们对Java 的了解。 本次课程设计的实例虽然比较简单,程序设计也不是很复杂,但在此程序的设计过程也是一个学习过程,更是对复杂程序的一个学习过程,还能培养我们的数抽象能力。因此,我们觉得这次课程设计是非常有意义的,能为我们今后学习面向过程的程序设计作一些铺垫。 1、设计的目的与要求; (1)为用户提供一个简便的日历记事本; (2)对java技术的进一步了解和简单的运用; (3)初步的接触软件工程; 2.设计目的与任务 本课程设计所要求达到的目的和任务:通过Java程序设计的一些重要理论基础来实现“日历记事本”的“日历”和“记事本”的双重功能。并通过此次课程设计的训练,使学生巩固和加深对Java这门课程的理解,通过利用所学到的计算科学的理论知识,提高解决实际问题的能力,增强运算、编程和使用技术资料的技能,通过实际问题的分析设计、编程和调试,掌握应用软件的分析方法和工程设计方法,能正确阐述设计和实验结果。通过这次课程设计,培养实事求是、认真、严谨的科学态度和刻苦钻研不断创新的精神,逐步建立正确的全局观念。 3.设计方案 3.1 总体设计

java课程设计 万年历 源代码

华北科技学院 课程设计报告 面向对象程序设计(Java) 班级: 电商B09-3 姓名: 周婷玉 设计题目:__________万年历________________ 设计时间: 2011-12-28 至2012-01-06 指导教师:_______ 郭慧____________ _____ 评语:_________________________________ _________________________________________ _________________________________________ _________________________________________ _________________________________________ 评阅成绩:___________评阅教师:_____________

课程设计说明书 1、课程设计的目的 a)掌握面向对象程序设计基本要素(封装、继承、多态) b)掌握JA VA语言常用类包及其常用方法和JA VA语言基本语法 c)掌握基于AWT的图形用户界面设计 i.常用标准控件的使用,如标签、按钮、菜单、文本框、单选按钮、 滚动条等。 ii.事件处理机制 d)掌握布局、对话框的使用 e)掌握发布JA VA应用程序 2、功能模块简介和系统结构图 需求分析:本程序的要求为: 1.使用图形用户界面 2.能够实现日期与星期的查询 3.实现当日的时间备忘 功能设计: 1.能以月历形式显示日期与星期 2.支持用户自己输入年份,并提供月份的下拉形式来选择查询 3.添加当日行事历,储存与清除功能

Java编写的扫雷小程序

J a v a编写的扫雷小程序Prepared on 21 November 2021

整个程序使用了4个类: Game 用于启动程序, 界面的布置,各种行列的算法。 ExtendButton 继承了Jbutton 用于新建button的各种属性 ShowNum 监听到某个button后,计算出此button周围有几个雷,不同的雷对应不通的图片,类得到button上应加载的图片地址 ViewReSet 此类用于新建一个窗口,用户输入自己想要的行、列、雷数,然后用新的行列雷数new 一个新的Game biaose dise1 dise2 dise3 dise4 dise5 dise6 dise7 dise8 dise lei biaoji

/**************************************************************** 运行类创建游戏主窗体 */ package class Game extends JFrame implements ActionListener{ private Container myContainer; private GridLayout myLayout; private JPanel myPanelMain; private JPanel myPanel; private JToolBar myTool; private JLabel time; private JLabel labelTime; private JLabel bombNum; private JLabel labelBombNum; private JMenuBar menuBar; private JMenu menuE, menuH; private JMenuItem menuItemCZ, menuItemSZ; private int numBomb, countTime, leaveBomb, numEnd; private int myRows, myColumns; private int xis, yis; private Timer timer; private ExtendButton[] myButton = null; etPostion(i); [i].setIcon((new ShowNum(10)).getImageIcon()); [i].setButton_num(0); [i].SetVisited(false); [i].SetStatus(false); ddMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { if (() == ) {

java日历制作源代码

import java.util.Scanner; public class rili{ public static void main(String[] args){ Scanner in=new Scanner(System.in); System.out.println("请输入年份,并回车:"); int year=in.nextInt(); System.out.println("请输入月份,并回车:"); int month=in.nextInt(); int sum=0; for(int i=1900;i

java小程序设计

课程设计报告 设计题目:用Java编的计算器 院系 班级 设计者 学号 指导教师 设计时间

前言: 通过上课学习了java程序设计的基本原理和模式,这次又以java语言为基本结合其图形应用界面来设计一个包括加、减、乘、除。还有带括号以及带负号、小数运算的计算程序。 系统功能和使用说明: 一.硬件环境: 本系统适用于现应用各种类型的计算机,内存容量为128MB以上,不必配备的外部附加设备。二.软件环境: 本系统的设计采用的是JAVA语言,应在JDK 5.0或者其更高版软件环境下本使用。 三.系统流程图: 1.下图是本程序的运行后的界面,其标注是此组件在程序中的名字 2.系统流程图中各个模块的功能说明: 本程序一共包括:构造方法A5i13w(),setup(), windowClosing(), actionPerformed(), appendchar(), countall(), counting(), Iscountnum()和一个windowcloser类。 (1). A5i13w()是构造方法,在程序创建其对象时就调用,初始化次程序的事件的监听机制。 (2). setup()是我定义的方法,是用来初始化程序的图形应用界面,由A5i13w()来调用。 (3). windowClosing()是用来响应用户的关闭功能。 (4). actionPerformed()是用来处理每个事件的响应的方法 (5). appendchar()方法的作用是在用户产生事件后向Textshow追加产生此事件的字符串 (6).countall()的意义是在用户按“=”号后,从最里层括号向最外层逐层把括号里的内容传递给counting()方法,并负责对括号本身是否符合数学语法要求进行检验。 (7).counting()方法的作用是首先对无括号的数学表达式有关的数学计算符号进行调整,并检验所有的数学符号,如发现错误的数学符号立即在Labelnow中显示出来。

Java图形用户界面编程练习

实验八Java图形用户界面编程练习 实验目的 1、掌握 Java 的 GUI 设计技术 2、掌握 AWT 和 Swing 的应用技巧 实验要求 1、编写一个程序学习使用处理ActiongEvent事件 2、编写一个程序学习使用布局类 实验内容 1.猜数字游戏 实验目的:练习图形用户界面编程,学习处理ActionEvent事件。 实用要求: 要求程序中要有2个按钮buttonGetNumber和buttonNumber,用户单击buttonGetNumber 按钮可以得到一个随机数,然后在文本框中输入猜测数字,再单击buttonNumber按钮,程序根据用户的猜测给出提示信息。 运行效果示例: 程序模板:按模板要求,将【代码】替换为Java程序代码。 GuessExample.java import java.awt.*;

import java.awt.event.*; import java.applet.*; public class GuessExample extends Applet implements ActionListener { int number; TextField inputNumber; Label feedBack; Button buttonGetNumber,buttonEnter; public void init() { buttonGetNumber=new Button("得到一个随机数"); feedBack=new Label ("无反馈信息",Label.CENTER); feedBack.setBackground(Color.green); inputNumber=new TextField("0",5); buttonEnter=new Button("确定"); 【代码1】//按钮buttonEnter增加ActionEvent事件监视器,监视器为当前Java Applet。 【代码2】//按钮buttonGetNumber增加ActionEvent事件监视器,监视器为当前Java Applet。 add(new Label("获取1-100之间的随机数:")); add(buttonGetNumber); add(new Label("输入您的猜测:")); add(inputNumber); add(new Label("单击确定按钮:")); add(buttonEnter); add(new Label("反馈信息:")); add(feedBack); } public void actionPerformed(ActionEvent e) { if(【代码3】) //判断事件源是否是buttonGetNumber。 { number=(int)(Math.random()*100)+1; } else if(【代码4】) //判断事件源是否是buttonEnter。 { int guess=0; try { guess=Integer.parseInt(【代码5】); //返回inputNumber中的文本。 if(guess==number) { 【代码6】//feedBack设置提示文本:"猜对了!"。 }

JAVA日历记事本课程设计报告

Java日历记事本课程设计报告 在设计日历记事本时,需要编写6个JA V A源文件:CalendarWindow.java、CalendarPad.java、NotePad.java、CalendarImage.java、Clock.java和CalendarMesssage.java 效果图如下 . CalendarWindow类 import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; import java.io.*; public class CalendarWindow extends JFrame implements ActionListener,MouseListener,FocusListener{ int year,month,day; CalendarMessage calendarMessage; CalendarPad calendarPad; NotePad notePad; JTextField showYear,showMonth; JTextField[] showDay; CalendarImage calendarImage; String picturename; Clock clock; JButton nextYear,previousYear,nextMonth,previousMonth; JButton saveDailyRecord,deleteDailyRecord,readDailyRecord;

JButton getPicture; File dir; Color backColor=Color.white ; public CalendarWindow(){ dir=new File("./dailyRecord"); dir.mkdir(); showDay=new JTextField[42]; for(int i=0;i

java简单图形用户界面代码

package dsr; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import https://www.sodocs.net/doc/b28753236.html,.Socket; public class Login extends JFrame implements ActionListener{ //定义组件 JPanel northPanel,southPanel,centerPanel,centerPanel1,centerPanel11,centerPanel12; JButton loginBtn,registerBtn,cancalBtn; JLabel userLbl,passwordLbl,titleLbl; JTextField userTxt; JPasswordField passwordPwd; static String name; public Login () { super("用户登录"); northPanel=new JPanel(); southPanel=new JPanel(); centerPanel1=new JPanel(); centerPanel11=new JPanel(); centerPanel12=new JPanel(); //标题 titleLbl=new JLabel("欢迎进入考试系统"); titleLbl.setFont(new Font("隶书",Font.BOLD,24)); northPanel.add(titleLbl); this.add(northPanel,BorderLayout.NORTH); //中间部分 centerPanel1.setLayout(new BorderLayout()); userLbl=new JLabel("用户名"); userTxt=new JTextField(12); centerPanel11.add(userLbl); centerPanel11.add(userTxt); centerPanel1.add(centerPanel11,BorderLayout.NORTH); passwordLbl=new JLabel("密码"); passwordPwd=new JPasswordField(12); centerPanel12.add(passwordLbl); centerPanel12.add(passwordPwd);

日历源代码——java

日历源代码——java //import java.sql.Date; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; public class GregorianCalendar日历 { public static void main(String[] args) { //设置不同地区 Locale.setDefault(https://www.sodocs.net/doc/b28753236.html,); //创建当前日历对象 GregorianCalendar now = new GregorianCalendar(); //从当前时期对象是取出时间日期对象 //编辑错误:Type mismatch: cannot convert from java.util.Date to java.sql.Date Date date = now.getTime(); //将时间日期对象按字符形式打印 System.out.println(date.toString()); //重新将时间对象设置到日期对象中 now.setTime(date); //从当前日期对象是取出当前月份、日期 int today = now.get(Calendar.DAY_OF_MONTH); int month = now.get(Calendar.MONTH); //获取本月开始日期 now.set(Calendar.DAY_OF_MONTH, 1); //获取本月开始日期在一周中的编号 int week = now.get(Calendar.DAY_OF_WEEK); //打印日历头并换行设置当前月中第一天的开始位置

java课程设计_简单日历程序

课程设计题目 2. 题目说明 通过编写一个基于JAVA的应用系统综合实例,自定义一个日历组件显示日期和时间并进行适当的功能扩充,实践Java语言编程技术。 3. 系统设计 2.1 设计目标 一个完整的程序应具有以下功能: 1)显示当月日历、当前日期、当前时间; 2)可查寻任意月以及任意年的日历; 3)使用图形化界面能够弹出对话框; 5)正常退出程序。 2.2 设计思想 设计一个类用来构成日历系统的主窗口,然后编写一个框架类显示时间和提示信息。在设计中应用了多种容器和控件。 2.3 系统模块划分 图1:简易日历的程序结构图

2.3.1初始化: public void init()完成界面初始化,形成一个以挂历形式显示当前日期的窗口。 2.3.2 日历描述: (1)public void updateView()改变日期后完成更新界面; (2)抽象类java.util.Calendar获取系统日期并传递日期数据而且在人工改变日期后得出当天是周几; (3)public static void main(String[] args) 主函数完成系统各算法的调用并对主窗口的一些属性进行设置; 2.3.3 滚动时间: 将时间以文本的形式在文本框中滚动播出,并能改变滚动的速度。 4. 使用类及接口 仅仅简单说明类的功能,详细资料请参看《JavaTM 2 Platform Standard Ed. 6》的电子文档,常规的接口与包则省略不屑。 //以下是日历程序块中使用的类 package fancy; import java.awt.*; import java.awt.event.*; import java.util.*; //主要用此包中的日期和时间类 import javax.swing.*; import javax.swing.event.*; import javax.swing.table.*; //以下是对滚动时间程序块所使用的类和接口, 用到定时器类Timer

java图形界面小程序

import java.awt.*; import java.awt.event.*; import javax.swing.*; import https://www.sodocs.net/doc/b28753236.html,ng.*; public class Test51{ Frame f; TextArea center; Label la1,la2,la3; Panel east,south,north; Button b1,b2,b3,b4; Choice l1; TextField t1; public static void main(String[] args){ Test51 mb = new Test51(); mb.go(); } private void go(){ f = new Frame("留言版程序"); f.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent evt){ f.setV isible(false); System.exit(0); } }); f.setBounds(0,0,600,400); f.setLayout(new BorderLayout()); f.setResizable(false); north = new Panel(); south = new Panel(); east = new Panel(); center = new TextArea("留言内容:"); center.setEditable(false); b1 = new Button("清屏"); b2 = new Button("至顶"); b3 = new Button("至尾"); la1 = new Label("留言版"); la2 = new Label("你"); la3 = new Label(" 地说:");

java15个经典小程序

1,编写程序,判断给定的某个年份是否是闰年。 闰年的判断规则如下: (1)若某个年份能被4整除但不能被100整除,则是闰年。 (2)若某个年份能被400整除,则也是闰年。 import java.util.Scanner; class Bissextile{ public static void main(String[] arge){ System.out.print("请输入年份"); int year; //定义输入的年份名字为“year” Scanner scanner = new Scanner(System.in); year = scanner.nextInt(); if (year<0||year>3000){ System.out.println("年份有误,程序退出!"); System.exit(0); } if ((year%4==0)&&(year%100!=0)||(year%400==0)) System.out.println(year+" is bissextile"); else System.out.println(year+" is not bissextile "); } } 2,给定一个百分制的分数,输出相应的等级。 90分以上A级 80~89 B级 70~79 C级 60~69 D级 60分以下E级 import java.util.Scanner; class Mark{ public static void main(String[] args){ System.out.println("请输入一个分数"); //定义输入的分数为“mark”,且分数会有小数 double mark; Scanner scanner = new Scanner(System.in); mark = scanner.nextDouble(); //判断是否有输入错误。 if(mark<0||mark>100){

JAVA SWING图形界面程序设计实验报告(附完整代码)

图形界面(GUI)程序设计 一、课题内容和要求 内容:设计和编写一个用于将人民币转换为等值的美元的程序,界面要求可以输入人民币的金额并可以得到转换后的结果。 要求:学习和理解JAVA SWING中的容器,部件,布局管理器和部件事件处理方法。通过编写和调试程序,掌握JAVA图形界面程序设计的基本方法。二、设计思路分析 class RMBtoDollar:主类,调用主函数。 class change:设置界面,并通过界面上的事件触发实现汇率转换。 三、概要设计 public class RMBtoDollar{ public static void main(String[] args); } class change extends JFrame implements MouseListener { JLabel l1, l2,l3; JTextField tf1, tf2; JButton b; double RMB, Dollar; public change(); public void mousePressed(MouseEvent e); public void mouseClicked(MouseEvent e); public void mouseEntered(MouseEvent e); public void mouseExited(MouseEvent e); public void mouseReleaseed(MouseEvent e);//鼠标释放时进行转换} 四、详细设计 import java.awt.*; import java.awt.event.*;

java GUI图形化界面编程总结

GUI(Graphical User Interface)图形化界面编程总结 Java.A wt:Abstract Window ToolKit(抽象窗口工具包) Javax.Swing: 图形化界面基本设置: 设置窗体大小:setSize(长,宽); 设置窗体位置:setLocation(距离左,距离上);setBounds(长,宽,距离左,距离上); 设置布局:setLayout(new FlowLayout()); 使窗体可见:setVisible(true); 事件监听机制:

事件监听机制的特点: 1,事件源。 2,事件。 3,监听器。 4,事件处理。 事件源:就是awt包或者swing包中的那些图形界面组件。 事件:每一个事件源都有自己特有的对应事件和共性事件。 监听器:将可以触发某一个事件的动作(不只一个动作)都已经封装到了监听器中。 以上三者,在java中都已经定义好了。 直接获取其对象来用就可以了。 我们要做的事情是,就是对产生的动作进行处理 Eg:编写程序,练习图形化界面编程! import java.awt.*; import java.awt.event.*; import java.io.*; class MyWindowDemo { private Frame f; private TextField tf; private Button but; private TextArea ta; private Dialog d; private Label lab; private Button okBut;

MyWindowDemo() { init(); } public void init() { f = new Frame("my window"); f.setBounds(300,100,600,500); f.setLayout(new FlowLayout()); tf = new TextField(60); but = new Button("转到"); ta = new TextArea(25,70); d = new Dialog(f,"提示信息-self",true); d.setBounds(400,200,240,150); d.setLayout(new FlowLayout()); lab = new Label(); okBut = new Button("确定"); d.add(lab); d.add(okBut); f.add(tf); f.add(but); f.add(ta); myEvent(); f.setVisible(true); } private void myEvent() { okBut.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { d.setVisible(false); } }); d.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { d.setVisible(false); } });

java课程设计万年历程序设计报告

山东科技大学 信息学院 JAVA程序设计 学院:信息科学与工程学院 班级:计算机11-3 学号:201101050230

姓名:赵乐

目录 目录 (1) 前言 (1) 1需求分析 (2) 2.概要设计 (3) 3.各模块的功能及程序说明 (5) 4.测试分析 (13) 5.源程序清单 (13) 6.课程设计体会 (22) 前言 Java的前身是Oak,它一开始只是被应用于消费性电子产品中。后来它的开发者们发现它还可以被用于更大范围的Internet上。1995年,Java语言的名字从Oak编程了Java。1997年J2SE1.1发布。1998年J2SE1.2发布,标志Java2的诞生。十多年来,Java编程语言及平台成功地运用在网络计算及移动等各个领域。Java的体系结构由Java语言、Java class、Java API、Java虚拟机组成。它具有简单、面向对象、健壮、安全、结构中立、可移植和高效能等众多优点。Java 支持多线程编程,Java运行时系统在多线程同步方面具有成熟的解决方案。Java 的平台标准有Java ME,Java SE和Java EE。Java发展到今天,它的卓越成就及在业界的地位毋庸置疑。目前在众多的支持Java的开发工具中主要的7有Java Development Kit,NetBeans,Jcreator,JBuilder,JDeveloper和Eclipse等。其中Java Development Kit 简称JDK是大多开发工具的基础。以上的每种开发工具都有优缺点,对于开发者来说,重要的是要根据自己的开发规模、开发内容和软硬件环境等因素来选择一种合适的开发工具。

小日历-JAVA课程设计实验报告

湖南农业大学JAVA课程设计报告 JAV A小日历组件 学生姓名:杨姣姣 学号:200741841210 年级专业:07级电子商务2班 指导老师:王明宇 学院:信息科学技术学院 湖南·长沙 提交日期:2009年11月

目录 1.设计目标 (3) 2.设计思想 (3) 3.类及对象设计 (3) 4.程序源代码 (4) 5.调试记录 (14) 6.总结 (15) 7.参考文献 (17) 8.致谢 (17)

JA V A小日历组件设计 1.设计目标 本课程设计是一个JA VA小日历组件的设计,利用Frame框架类、面板类进行图形化界面设计,实现小日历的公历显示等功能。 2.设计思想 (1)本小日历设计主体结构为:设计一个框架MainFrame,然后在MainFrame里添加一个MainPanel面板。定义一个MainPanel面板类,该面板以边布局格式,所有其他面板、标签等均添加到该面板中。 (2)MainPanel面板北部(上方),添加一个年月面板YearMonthPanel。该年月面板主要放年份显示、月份显示、标题显示。YearMonthPanel面板也使用边布局格式,西部添加一个年份面板,放年份信息;中部添加一个TextPanel面板,放标题文本显示信息;东部添加一个月份面板MonthPanel,放月份下拉框信息。 (3)MainPanel主面板的中部,添加一个DaysPanel面板用于放置月份的天数表格信息。 (4)MainPanel主面板的南部(下方),添加一个InfoPanel面板,主要用于放置显示个人信息。 (5)InfoPanel面板上设计添加一个超级链接标签,链接到个人博客。 3.设计类及对象设计 在本程序中:定义了一个Frame类,主要定义一个窗体框架,用于显示日历信息,并在主函数中只创建一个该窗体对象实现程序功能。 定义了一个主日历面板类Xiaorili,其中包含了日历设计所用到的全局变量、功能函数等,在Frame类里定义了其对象。在该日历面板类里又设计了一个内部类CalendarTable表格类,用于布局日历天的显示格式。 为了设计一个超级链接,定义了一个LinkLable类,单独保存在一个文件LinkTbale.java中,在日历面板类Xiaorili里定义了其对象。

实验二 Java图形界面编程

实验二Java图形界面编程 一、实验目的 熟悉java运行环境,编程掌握Java Swing组件的图形界面编程。 二、实验环境 微机,软件MyEclipse,JDK1.5以上版本即可。 三、实验内容 1)Java Swing容器组件 2)Java Swing标准组件 3)Java Swing布局管理器 4)Java Swing事件监听器 5)JOptionPane类的使用 四、实验要求 (一)界面编程部分 1.编制程序,实现一个类似于windows计算器的计算器图形界面。如下图所示,只需要做出图形界面,不需要实现加减乘除计算过程。(满分为A/2) 操作提示: jp.setLayout(new GridLayout(4,4)); JButton[] numberBtn = new JButton[16];; String[] operatorValue = { "+", "-", "*", "/", "%", "=" }; for (int i = 0; i < 10; i++) numberBtn[i] = new JButton("" + (char) ('0' + i)); jp.add(numberBtn[i]);

…… } for (int i = 10; i < numberBtn.length; i++) { numberBtn[i] = new JButton(operatorValue[i - 10]); jp.add(numberBtn[i]); …… } add(BorderLayout.CENTER,jp); …… (二)事件监听器编程部分 1. 改写本章案例GuessNumber.java,分别用内部类和匿名类作为事件监听者处理相应的事件。(满分为A) 2. 请在这个操作界面的基础上,继续完成下面的题目要求:(满分为A) 1)单击“插入”,“显示”,“查询”,“删除”四个按钮的时候,文本区里面显示“您单击了插入按钮,正在执行插入新记录操作……”。 2)单击“移除组件”按钮,将“插入”,“显示”,“查询”,“删除”四个按钮组件从JPanel中删除掉,并触发ContainerEvent事件,在文本区显示“您单击了移除按钮,从JPanel中移除了插入,显示,删除和查询等按钮……”。 3)单击“重新放置组件”按钮,将“插入”,“显示”,“查询”,“删除”四个按钮组件重新添加到JPanel中,并触发ContainerEvent事件,在文本区显示“您单击了重新放置按钮,向JPanel中重新添加了插入,显示,删除和查询等按钮……”。 4)单击窗口右上角的关闭按钮,可以将JFrame窗口关闭掉。

相关主题