重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
用RandomAccessFile类
创新互联-专业网站定制、快速模板网站建设、高性价比阿拉尔网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式阿拉尔网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖阿拉尔地区。费用合理售后完善,10余年实体公司更值得信赖。
例如 RandomAccessFile ran=new RandomAccessFile ("*******");
将指针定义到末尾并获取ran.seek(ran.length()); long end=ran.getFilePointer();
获取倒数第二行指针位置
int j=1;
long a=0;
while((end=0)(j=2))
{
end--;
ran.seek(end);
n=ran.readByte();
if(n=='\n')
{
a=ran.getFilePointer();
j++;
}
}
a就指向了倒数第二行
接着写内容用这个类 我还没试过
不过用其他输入流 声明对象时 参数是true就可以了
这个你可以找找API帮助
你是用J2EE做还是用J2SE做,如果是J2EE的话,JS应该就可以实现这个功能,如果用J2SE的话,那就可能需要你用到画图的类,或者APPLET小程序了,因为对小程序不精通,所以就说一下画图类吧,如果想要做一个动态的时钟的话,那时间控件肯定是不能少的,利用时间控件来控制图片的移动,也就是指针的移动。指针移动其实是在画圆,所以指针的一个坐标已经 确定了,而另一个坐标你就需要自己来想一个算法了,每过一分钟,图片的坐标会走几个像素,用时间控件来改变图片的坐标。这只是我的想法,具体实现起来肯定会有难度,加油。
package 时钟;
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.JApplet;
/**
*
* @author Jiang
*/
public class Clock2 extends JApplet implements Runnable{
double PI=Math.PI;//圆周率
double hourlen=50;//时针长度
double minutelen=70;//分针长度
double secondlen=90;//秒针长度
int yuanxinx=100,yuanxiny=100;//圆心坐标
int banjin=100;//半径长度
int qix,qiy,zhongxh,zhongxm,zhongxs,zhongyh,zhongym,zhongys;//各指针的起点和终点坐标(起点一致)
Thread th;
BufferedImage buf;
int hour,minute,second;//记录当前时间
Calendar calendar;//用于获取当前时间
Graphics g1;//用于内存绘图
public void init(){
hour=minute=second=0;
buf=new BufferedImage(400,400,BufferedImage.TYPE_INT_ARGB);//控制内存绘图区域大小
g1=buf.getGraphics();//创建缓冲绘图区
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){}
//用背景色填充绘图区,擦除上次绘图
g1.setColor(this.getBackground());
//g1.fillRect(yuanxinx-banjin,yuanxiny-banjin,2*banjin,2*banjin);
g1.fillRect(0,0,400,400);
repaint();
}
}
public void paint(Graphics g){
//将图像先画到缓冲区
g1.setColor(this.getForeground());
//绘制时钟刻盘(刻度长度为8)
g1.drawOval(yuanxinx-banjin,yuanxiny-banjin,yuanxinx+banjin,yuanxiny+banjin);
//特殊位置简便画法
//g1.drawLine(yuanxinx-banjin,yuanxiny,yuanxinx-banjin+8,yuanxiny);//9
//g1.drawLine(yuanxinx,yuanxiny-banjin,yuanxinx,yuanxiny-banjin+8);//12
//g1.drawLine(yuanxinx+banjin,yuanxiny,yuanxinx+banjin-8,yuanxiny);//3
//g1.drawLine(yuanxinx,yuanxiny+banjin,yuanxinx,yuanxiny+banjin-8);//6
//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));
g1.drawLine(qixx,qiyy,zhongxx,zhongyy);
//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));
g1.drawLine(qixx,qiyy,zhongxx,zhongyy);
//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));
g1.drawLine(qixx,qiyy,zhongxx,zhongyy);
//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));
g1.drawLine(qixx,qiyy,zhongxx,zhongyy);
//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));
g1.drawLine(qixx,qiyy,zhongxx,zhongyy);
//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));
g1.drawLine(qixx,qiyy,zhongxx,zhongyy);
//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));
g1.drawLine(qixx,qiyy,zhongxx,zhongyy);
//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));
g1.drawLine(qixx,qiyy,zhongxx,zhongyy);
//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));
g1.drawLine(qixx,qiyy,zhongxx,zhongyy);
//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));
g1.drawLine(qixx,qiyy,zhongxx,zhongyy);
//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));
g1.drawLine(qixx,qiyy,zhongxx,zhongyy);
//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));
g1.drawLine(qixx,qiyy,zhongxx,zhongyy);
//g1.drawLine(150,15,140,25);
//g1.drawString(""+qixx+" "+qiyy+" "+zhongxx+" "+zhongyy,200,300);
//获取当前时间
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();
g1.setColor(Color.red);
g1.setFont(new Font(oldfont.getName(),Font.BOLD,oldfont.getStyle()+20));
g1.drawLine(qix,qiy,zhongxh,zhongyh);
g1.setColor(Color.green);
g1.setFont(new Font(oldfont.getName(),Font.BOLD,oldfont.getStyle()+15));
g1.drawLine(qix,qiy,zhongxm,zhongym);
g1.setColor(Color.blue);
g1.setFont(new Font(oldfont.getName(),Font.BOLD,oldfont.getStyle()+10));
g1.drawLine(qix,qiy,zhongxs,zhongys);
//输出时间、日期
g1.setFont(new Font("Time New Roman",Font.BOLD,25));
g1.setColor(Color.PINK);
g1.drawString(""+hour+":"+minute+":"+second,150,240);
g1.setFont(new Font("Time New Roman",Font.BOLD,18));
g1.setColor(Color.green);
g1.drawString("中国标准时间 Chinese Standard Time",25,280);
g1.setFont(new Font("Time New Roman",Font.BOLD,20));
g1.setColor(Color.blue);
g1.drawString(new Date().toString(), 25,320);
//g1.drawString(""+hour+" "+minute+" "+second, 200,200);
g.drawImage(buf, 0,0, this);//将缓冲区图像画到JApplet上
}
public void update(Graphics g){//覆盖方法
paint(g);
}
}