开发一个托盘程序《操作系统》实验报告 实验1Word文件下载.docx

上传人:b****5 文档编号:19803530 上传时间:2023-01-10 格式:DOCX 页数:27 大小:937.23KB
下载 相关 举报
开发一个托盘程序《操作系统》实验报告 实验1Word文件下载.docx_第1页
第1页 / 共27页
开发一个托盘程序《操作系统》实验报告 实验1Word文件下载.docx_第2页
第2页 / 共27页
开发一个托盘程序《操作系统》实验报告 实验1Word文件下载.docx_第3页
第3页 / 共27页
开发一个托盘程序《操作系统》实验报告 实验1Word文件下载.docx_第4页
第4页 / 共27页
开发一个托盘程序《操作系统》实验报告 实验1Word文件下载.docx_第5页
第5页 / 共27页
点击查看更多>>
下载资源
资源描述

开发一个托盘程序《操作系统》实验报告 实验1Word文件下载.docx

《开发一个托盘程序《操作系统》实验报告 实验1Word文件下载.docx》由会员分享,可在线阅读,更多相关《开发一个托盘程序《操作系统》实验报告 实验1Word文件下载.docx(27页珍藏版)》请在冰豆网上搜索。

开发一个托盘程序《操作系统》实验报告 实验1Word文件下载.docx

1)获取系统时间,每1秒钟刷新1次。

2)获取CPU基本信息,至少包括:

CPU主频,CPU序列号,CPU型号

3)获取内存信息,至少包括:

内存总量,可用内存量

三、实验过程或算法(源程序)

系统时钟的编程实现:

程序通过调用系统时间的函数类型java.util.Calendar定义了一个时间变量

  System.DateTimecurrentTime=newSystem.DateTime(),并通过API函数CalendarcurrentTime=Calendar.getInstance()来获得当前的系统时间,并且按照固定格式输出。

  在时钟时间的实现中,首先实现了对JPanel类的继承类clock的定义,并且对其paintComponent(Graphicsg)函数进行重载。

代码如下:

publicclassCalenderextendsJPanelimplementsActionListener{

publicstaticfinalStringHOUR_OF_DAY=null;

//定义

JComboBoxMonth=newJComboBox();

JComboBoxYear=newJComboBox();

JLabelYear_l=newJLabel("

年"

);

JLabelMonth_l=newJLabel("

月"

Datenow_date=newDate();

JLabel[]Label_day=newJLabel[49];

intnow_year=now_date.getYear()+1900;

intnow_month=now_date.getMonth();

booleanbool=false;

Stringyear_int=null;

intmonth_int;

JPanelpane_ym=newJPanel();

JPanelpane_day=newJPanel();

publicCalender(){

super();

//设定年月

for(inti=now_year-10;

i<

=now_year+20;

i++){

Year.addItem(i+"

"

}

for(inti=1;

13;

i++){

Month.addItem(i+"

Year.setSelectedIndex(10);

pane_ym.add(newJLabel("

"

));

pane_ym.add(Year);

pane_ym.add(Year_l);

Month.setSelectedIndex(now_month);

pane_ym.add(Month);

pane_ym.add(Month_l);

Month.addActionListener(this);

Year.addActionListener(this);

pane_day.setLayout(newGridLayout(7,7,10,10));

for(inti=0;

49;

Label_day[i]=newJLabel("

pane_day.add(Label_day[i]);

this.setDay();

this.setLayout(newBorderLayout());

pane_day.setOpaque(false);

pane_ym.setOpaque(false);

this.add(pane_day,BorderLayout.CENTER);

this.add(pane_ym,BorderLayout.NORTH);

this.setSize(100,50);

this.setBorder(newTitledBorder("

日历"

setSize(300,300);

}

voidsetDay(){

if(bool){

year_int=now_year+"

;

month_int=now_month;

else{

year_int=Year.getSelectedItem().toString();

month_int=Month.getSelectedIndex();

intyear_sel=Integer.parseInt(year_int)-1900;

Datedt=newDate(year_sel,month_int,1);

GregorianCalendarcal=newGregorianCalendar();

cal.setTime(dt);

Stringweek[]={"

日"

"

一"

"

二"

三"

四"

五"

六"

};

intday=0;

intday_week=0;

7;

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

//月份

if(month_int==0||month_int==2||month_int==4||

month_int==6||

month_int==9||month_int==11){

day=31;

}

elseif(month_int==3||month_int==5||month_int==7||

month_int==8||month_int==10||month_int==1){

day=30;

}else{

if(cal.isLeapYear(year_sel)){

day=29;

}

else{

day=28;

day_week=7+dt.getDay();

intcount=1;

for(inti=day_week;

day_week+day;

count++,i++){

if(i%7==0||i==13||i==20||i==27||

i==48||i==34||i==41){

if(i==day_week+now_date.getDate()-1){

Label_day[i].setForeground(Color.blue);

Label_day[i].setText(count+"

}else{

Label_day[i].setForeground(Color.red);

}

}else{

if(i==day_week+now_date.getDate()-1){

}else{

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

if(day_week==0){

for(inti=day;

Label_day[i].setText("

for(inti=7;

day_week;

for(inti=day_week+day;

}

publicvoidactionPerformed(ActionEvente){

if(e.getSource()==Year||e.getSource()==Month){

bool=false;

this.setDay();

}

 

系统日历的编程实现:

程序通过调用系统时间的函数类型java.util.Date定义了一个时间变量

  Datenow_date=newDate(),并通过API函数now_date.getYear()来获得当前的系统年份,now_date.getMonth()获取系统月份,并且按照固定格式输出。

  在时钟时间的实现中,首先实现了对JPanel类的继承类Calender的定义,并且对其Calender()函数进行重载。

publicclassclockextendsJPanel{

privatestaticfinalColorINTEGRAL_COLOR=newColor(0,128,128);

privateintradius;

//半径

privatedoubles=0.03;

privateCalendarcurrentTime=Calendar.getInstance();

publicclock(intradius){

this.radius=radius;

}

publicvoidsetCurrentTime(Datetime){

this.currentTime.setTime(time);

publicvoidsetCurrentTime(longmillis){

this.currentTime.setTimeInMillis(millis);

publicDimensiongetPreferredSize(){

Insetsinsets=getInsets();

intr=(int)(radius==-1?

0:

radius*(1+s))+1;

returnnewDimension(r*2+insets.left+insets.right,r*2+insets.top+insets.bottom);

protectedvoidpaintComponent(Graphicsg){

super.paintComponent(g);

Graphics2Dg2d=(Graphics2D)g;

paintTime(g2d);

g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);

intwid=getWidth()-insets.left-insets.right;

inthei=getHeight()-insets.top-insets.bottom;

intr=(int)((Math.min(wid,hei))/2/(1+s));

g2d.translate(insets.left+r*(1+s),insets.top+r*(1+s));

g2d.scale(1,-1);

60;

intangle=90-i*6;

doublepos[]=calcPos(r,angle);

paintMinuteDot(r,g2d,pos[0],pos[1],i%5==0);

paintHourPointer(r,g2d);

paintMinutePointer(r,g2d);

paintSecondPointer(r,g2d);

paintCenterPoint(g2d);

g2d.translate(-insets.left-r*(1+s),-insets.top-r*(1+s));

privatevoidpaintCenterPoint(Graphics2Dg2d){

g2d.setColor(Color.BLUE);

Rectangle2Drect=newRectangle2D.Double(-2,-2,4,4);

g2d.fill(rect);

privatevoidpaintMinutePointer(intr,Graphics2Dg2d){

intminute=currentTime.get(Calendar.MINUTE);

intsecond=currentTime.get(Calendar.SECOND);

doubleangle=90-(minute+second/60.0)*6;

ShapepointerShape=createPointerShape(r*0.8,r*0.04,r*0.08,angle);

g2d.setColor(Color.LIGHT_GRAY);

g2d.fill(pointerShape);

g2d.setColor(Color.DARK_GRAY);

g2d.draw(pointerShape);

Stringtime(){

inthour=currentTime.get(Calendar.HOUR);

return("

+hour+"

:

+minute+"

+second);

privatevoidpaintHourPointer(intr,Graphics2Dg2d){

doubleangle=90-(hour+minute/60.0+second/3600.0)*30;

ShapepointerShape=createPointerShape(r*0.6,r*0.06,r*0.1,angle);

privatevoidpaintTime(Graphics2Dg2d){

g2d.setColor(Color.RED);

g2d.setFont(newFont("

宋体"

Font.BOLD,16));

g2d.drawString(time(),60,60);

privateShapecreatePointerShape(doubler1,doubler2,doubler3,doubleangle){

GeneralPathgp=newGeneralPath();

double[]pos=calcPos(r1,angle);

//指针定点

double[]pos1=calcPos(r2,angle+90);

//指针侧边断点

gp.append(newLine2D.Double(pos[0],pos[1],pos1[0],pos1[1]),true);

double[]pos2=calcPos(r3,angle+180);

//指针尾部

gp.lineTo((float)pos2[0],(float)pos2[1]);

double[]pos3=calcPos(r2,angle+270);

//指针的另一侧边断点

gp.lineTo((float)pos3[0],(float)pos3[1]);

gp.closePath();

returngp;

privatevoidpaintSecondPointer(intr,Graphics2Dg2d){

g2d.setColor(Color.BLACK);

intangle=90-second*6;

doublepos[]=calcPos(r*0.9,angle);

doublepos1[]=calcPos(r*0.2,angle+180);

Line2Dline=newLine2D.Double(pos1[0],pos1[1],pos[0],pos[1]);

g2d.draw(line);

privatevoidpaintMinuteDot(intr,Graphics2Dg2d,doublex,doubley,booleanflag){

g2d.setColor(flag?

Color.RED:

Color.BLACK);

if(flag){

Ellipse2Drect=newEllipse2D.Double(x-r*s,y-r*s,r*s*2,r*s*2);

g2d.fill(rect);

}else{

Ellipse2Drect=newEllipse2D.Double(x-r*0.02,y-r*0.02,r*0.04,r*0.04);

privatedouble[]calcPos(doubler,doubleangle){

doubleradian=Math.toRadians(angle);

doublex=r*Math.cos(radian);

doubley=r*Math.sin(radian);

returnnewdouble[]{x,y};

publicvoidshowUI(){

newThread(){

publicvoidrun(){

while(true){

try{

Thread.sleep(1000);

}catch(InterruptedExceptionex){

ex.printStackTrace();

}

setCurrentTime(System.currentTimeMillis());

repaint();

}

}.start();

system主类:

实现了对JFrame类的继承类system的定义,定义了三个选项卡,并定义了三个JPanel:

TimePanel、CPUPanel、MEMPanel,并分别加到三个选项卡上,在每个JPanel上显示时间、CPU、内存的各项信息。

publicclasssystemextendsJFrame{

privateJTabbedPanejtpFigures=newJTabbedPane();

privateJPanelCPUPanel=newJPanel();

privateJPanelMEMPanel=newJPanel();

privateJPanelTimePanel=newJPanel();

ImageIconimageIcon1=newImageIcon("

image/mem.jpg"

ImageIconimageIcon=newImageIcon("

image/cpu.jpg"

ImageIconimageIcon2=newImageIcon("

image/time.jpg"

//ImageIconlogo=newImageIc

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 表格模板 > 调查报告

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

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