大虾请进!急急急! 哎呀,去买本JAVA2 高级特性那本书上有的。在交大昂立书店有买的。如果你在上海的话~你要是真的想要,我星期一到公司,把那本书上的计数器抄给你?如何?MM只能帮到这了~~~回见! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这是我的所写的程序中的计数器模块,真接调用的,你先仔细看一下: 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 我抄给你落!自己看拉!可花了我不少时间打字哦!不过小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 Java 窗体监听问题 Java新手,前来喷Java 请大家一起来测试这个程序 panle绘图与加组件问题 我是JAVA新手,问个白痴的基础题,希望大家帮忙解答下,不胜感激 executeBatch()的返回值问题 求:是简单的图片显示实例!! jdk 1.5 中, class Foo<T> {} 中的T是表示什么呢? CLASSPATH的问题,郁闷 菜鸟问题(applet的运行) 为什么repaint()后没有重载paint()方法呢?小M求助各位GG!非常急!答对一定给分!!! 如何防止按浏览器右上角的"x" 来关闭浏览器
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
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