社区
Java SE
帖子详情
大虾请进!急急急!
chaseismydream
2001-07-21 09:33:54
那位大虾会编计数器,编好的也可以!
...全文
138
6
打赏
收藏
大虾请进!急急急!
那位大虾会编计数器,编好的也可以!
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
6 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
pearl_091278
2001-07-23
打赏
举报
回复
光说谢谢啊 ~~~~~~~~~~~~~~~~~`恩~~~~~~~~~~~加分呀~~~西西!
chaseismydream
2001-07-23
打赏
举报
回复
谢谢!
pearl_091278
2001-07-23
打赏
举报
回复
我抄给你落!自己看拉!可花了我不少时间打字哦!不过小M总不食言的!!!!
程序如下:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class TimerTest{
public static void main(String[] args){
JFrame f=new TimerTestFrame();
f.show();
}
}
class TimerTestFrame extends JFrame{
public TimerTestFrame(){
setSize(450,300);
setTitle("TimerTest");
addWindowListener(new WindowAdapter(){
public void WindowClosing(WindowEvent e){
System.exit(0);
}
});
Container c=getContentPane();
c.setLayout(new GridLayout(2,3));
c.add(new ClockCanvas("San Jose","GMT-8"));
c.add(new ClockCanvas("Taipei","GMT+8"));
c.add(new ClockCanvas("Berlin","GMT+1));
c.add(new ClockCanvas("New York","GMT-5"));
c.add(new ClockCanvas("Cairo","GMT+2"));
c.add(new ClockCanvas("Bombay","GMT+5));
}
}
interface TimerListener{
void timeElapsed(Timer t);
}
class Timer extends Thread{
private TimerListener target;
private int interval;
public Timer(int i,TimerListenr t){
target=t;
interval=i;
setDaemon(true);
}
public void run(){
try{
while(!interrupted){
sleep(interval);
target.timeElapsed(this);
}
}catch(InterruptedException e){}
}
}//end class
class ClockCanvas extends JPanel implements TimerListener{
private int seconds=0;
private String city;
private int offset;
private GregorianCalendar calendar;
private final int LOCAL=16;
public ClockCanvas(String c,String tz){
city=c;
calendar=new GregorianCalendar(TimeZone.getTimeZone(tz));
Timer t=new Timer(1000,this);
t.start();
setSize(125,125);
}
public void paintComponent(Graphics g){
super.paintComponent(g);
g.drawOval(0,0,100,100);
double hourAngle=2*Math.PI*(seconds-3*60*60)/(12*60*60);
double minteAngle=2*Math.PI*(seconds-15*60)/(60*60);
double secondAngle=2*Math.PI*(seconds-15)/60;
g.drawLine(50,50,50+(int)(30*Math.cos(hourAngle)),50+(int)(30*Math.sin(hourAngle)));
g.drawLine(50,50,50+(int)(40*Math.cos(minuteAngle)),50+(int(40*Math.sin(minuteAngle)));
g.drawLine(50,50,50_(int)(45*Math.cos(secondAngle)),50+(int)(45*Math.sin(secondAngle)));
g.drawString(city,0,115);
}
public void timeElapsed(Timer t){
calendar.setTime(new Date());
second=calendar.get(Calendar.HOUR)*60*60+calendar.get(Calendar.MINUTE)*60+calendar.get(Calendar.SECOND);
repaint();
}
}//end class
tiangou
2001-07-22
打赏
举报
回复
这是我的所写的程序中的计数器模块,真接调用的,你先仔细看一下:
private int count(HttpServletRequest request,HttpServletResponse response)
{//no12
int counter = 0;
boolean needreadfile=true;
String HomeDirectory="";
String HomeTemp="";
try{
HomeDirectory=request.getRealPath("/");
HomeDirectory+="//";
boolean create=true;
HttpSession CountSession=request.getSession(create);
Integer iNumber=(Integer)CountSession.getValue("SessionCounter.Counter");
try
{
if (iNumber==null)
{
needreadfile=true;
}else {
needreadfile=false;
counter=iNumber.intValue();
}
if(needreadfile)
{ //no11
//read from file
int tmpNumber=0;
DataInputStream is;
String b1="";
try
{
is=new DataInputStream(new FileInputStream(HomeDirectory+"counter.txt"));
try {
b1=is.readLine();
tmpNumber=Integer.parseInt(b1);
}catch (IOException e) {
System.out.println("Read from file error!");
}
}catch (FileNotFoundException e) {
tmpNumber=0;
}
counter=tmpNumber+1;
//write to file
try
{
RandomAccessFile countFile=new RandomAccessFile(HomeDirectory+"counter.txt","rw");
long len=0;
countFile.seek(len);
b1=Integer.toString(counter);
countFile.writeBytes(b1);
countFile.close();
}
catch(IOException e){
System.out.println("Write to file error!");
}
}//yes11
}catch (NumberFormatException e)
{
System.out.println(e.toString());
counter=98;
}
String sTemp=""+counter;
iNumber=Integer.decode(sTemp);
CountSession.putValue("SessionCounter.Counter",iNumber);
}
catch(NumberFormatException e)
{System.out.println("000000000000804error");}
return counter;
}//yes12
pearl_091278
2001-07-21
打赏
举报
回复
哎呀,去买本JAVA2 高级特性那本书上有的。在交大昂立书店有买的。如果你在上海的话~
你要是真的想要,我星期一到公司,把那本书上的计数器抄给你?如何?MM只能帮到这了~~~回见!
xmvigour
2001-07-21
打赏
举报
回复
网上搜索一下!
急
急
急
,请各位
大虾
帮帮忙!
博客主要询问如何使用GDI+绘制立体图,以及绘制时需要调用哪些函数,聚焦于GDI+在立体图绘制方面的应用。
对查询出来的记录行进行分页显示,怎么做???在客户现场,哪位
大虾
帮忙?
急
急
急
...
本文详细介绍如何在Delphi中实现数据库查询结果的分页显示,包括设置每页记录数、计算总页数及当前页的记录范围,并通过示例代码展示了如何利用DBGrid和DataSource组件结合ADODataSet进行分页操作。
大虾
给做个题好么?
急
急
急
. 谢谢谢.
本文包含数据结构基础知识的选择题和填空题,如逻辑结构、线性表等概念,同时涉及软件开发过程中的系统说明书、面向对象分析方法及软件测试等内容。
急
急
急
!!!有关asp字符串处理的问题,请
大虾
指点???
博主从数据库读取到日期格式如2004-5-1 14:25:00等,希望只保留日期部分如2004-5-1,并将值放入
中,寻求详细处理方法。
Java SE
62,622
社区成员
307,257
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章