用RandomAccessFile類
創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比阿拉爾網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式阿拉爾網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋阿拉爾地區(qū)。費用合理售后完善,10余年實體公司更值得信賴。
例如 RandomAccessFile ran=new RandomAccessFile ("*******");
將指針定義到末尾并獲取ran.seek(ran.length()); long end=ran.getFilePointer();
獲取倒數(shù)第二行指針位置
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就指向了倒數(shù)第二行
接著寫內(nèi)容用這個類 我還沒試過
不過用其他輸入流 聲明對象時 參數(shù)是true就可以了
這個你可以找找API幫助
你是用J2EE做還是用J2SE做,如果是J2EE的話,JS應(yīng)該就可以實現(xiàn)這個功能,如果用J2SE的話,那就可能需要你用到畫圖的類,或者APPLET小程序了,因為對小程序不精通,所以就說一下畫圖類吧,如果想要做一個動態(tài)的時鐘的話,那時間控件肯定是不能少的,利用時間控件來控制圖片的移動,也就是指針的移動。指針移動其實是在畫圓,所以指針的一個坐標(biāo)已經(jīng) 確定了,而另一個坐標(biāo)你就需要自己來想一個算法了,每過一分鐘,圖片的坐標(biāo)會走幾個像素,用時間控件來改變圖片的坐標(biāo)。這只是我的想法,具體實現(xiàn)起來肯定會有難度,加油。
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;//圓心坐標(biāo)
int banjin=100;//半徑長度
int qix,qiy,zhongxh,zhongxm,zhongxs,zhongyh,zhongym,zhongys;//各指針的起點和終點坐標(biāo)(起點一致)
Thread th;
BufferedImage buf;
int hour,minute,second;//記錄當(dāng)前時間
Calendar calendar;//用于獲取當(dāng)前時間
Graphics g1;//用于內(nèi)存繪圖
public void init(){
hour=minute=second=0;
buf=new BufferedImage(400,400,BufferedImage.TYPE_INT_ARGB);//控制內(nèi)存繪圖區(qū)域大小
g1=buf.getGraphics();//創(chuàng)建緩沖繪圖區(qū)
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){}
//用背景色填充繪圖區(qū),擦除上次繪圖
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){
//將圖像先畫到緩沖區(qū)
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);
//獲取當(dāng)前時間
calendar=Calendar.getInstance();
hour=calendar.get(Calendar.HOUR);
minute=calendar.get(Calendar.MINUTE);
second=calendar.get(Calendar.SECOND);
//計算指針坐標(biāo)
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("中國標(biāo)準(zhǔn)時間 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);//將緩沖區(qū)圖像畫到JApplet上
}
public void update(Graphics g){//覆蓋方法
paint(g);
}
}
文章題目:用java代碼寫一個指針 java中的指針是什么
文章起源:http://jinyejixie.com/article6/dossjog.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、網(wǎng)站設(shè)計、微信公眾號、定制開發(fā)、網(wǎng)站維護、建站公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)