Java精妙的代码 一段java代码的详细解说( 二 )


} else {
System.out.println("征集慈善募捐失败,募捐总数未达到10万元 。");
}
scanner.close();
}
}
我需要一段最简单的java代码程序public class HelloWorld{
public static void main(String[] args){
System.out.println("hello world!");
}
}
一. 基本概念
Java是一种可以撰写跨平台应用软件的面向对象的程序设计语言 。Java 技术具有卓越的通用性、高效性、平台移植性和安全性,广泛应用于PC、数据中心、游戏控制台、科学超级计算机、移动电话和互联网,同时拥有全球最大的开发者专业社群 。
二. 体系
Java分为三个体系 , 分别为Java SE(J2SE,Java2 Platform Standard Edition , 标准版),
JavaEE(J2EE , Java 2 Platform, Enterprise Edition,企业版) 。
Java ME(J2ME,Java 2 Platform Micro Edition,微型版) 。
求java的计时器代码,应该比较简单的 , 来看看吧 。package test;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Test5 extends Applet {
private final Panel pan = new Panel();
private final Label time = new Label();
private final Button btnGo = new Button("开始");
private final Button btnPouse = new Button("暂停");
private final Button btnReset = new Button("复位");
private final StopwatchThread swThread = new StopwatchThread();
private class btnGoListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
swThread.go();
btnGo.setEnabled(false);
}
}
private class btnPouseListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
if(btnGo.isEnabled()){
return ;
}
if (btnPouse.getLabel().equals("继续")) {
swThread.go();
btnPouse.setLabel("暂停");
} else if (btnPouse.getLabel().equals("暂停")) {
swThread.noGo();
btnPouse.setLabel("继续");
}
}
}
private class btnResetListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
swThread.reset();
btnGo.setEnabled(true);
btnGo.setLabel("开始");
btnPouse.setLabel("暂停");
}
}
private class StopwatchThread extends Thread {
private boolean going = false;
private long prevElapsed = 0;
private Date startDate = new Date();
private long elapsedTime() {
return prevElapsed +
【Java精妙的代码 一段java代码的详细解说】(going ? new Date().getTime() - startDate.getTime() : 0);
}
private String msToString(long time) {
System.out.println(time+""+((0*60+2)*1000+999));
if(((99*60+59)*1000+983)=time((99*60+59)*1000+999)=time){//((0*60+2)*1000+983)=time((0*60+2)*1000+999)=time
if (time % 1000990)
time += 2;
swThread.noGo();
}
String ms, sec, min;
if (time % 10 = 5)
time += 5;
ms = Long.toString(time % 1000);
while (ms.length()3)
ms = "0" + ms;
ms = ms.substring(0, ms.length() - 1);
time /= 1000;
sec = Long.toString(time % 60);
if (sec.length() == 1) sec = "0" + sec;
time /= 60;
min = Long.toString(time);
return min + ":" + sec + "." + ms;
}
public void go() {
startDate = new Date();
going = true;
}
public void noGo() {
prevElapsed = elapsedTime();
going = false;
}
public void reset() {
going = false;
prevElapsed = 0;
}
public void run() {
while (true) {
time.setText(msToString(elapsedTime()));
yield();
}
}
}
public void init() {
setLayout(new GridLayout(2,2));
setBackground(Color.lightGray);

推荐阅读