用jsp 做计算器时 用jsp 做计算器时,两个操作数是用double 类型的,可是运算结果有时小数点后面数太多,求有什么使运算结果精确点? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import javax.swing.*;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;import java.awt.*;import java.util.Date;import java.text.SimpleDateFormat;/** * 秒表功能 * @author Administrator * */public class StopWatch extends JFrame { JButton btnStart, btnStop; JLabel label; Timer timer; public StopWatch() { label = new JLabel("00:00:00.000"); btnStart = new JButton("start"); btnStop = new JButton("stop"); final int delay = 100; final Date startTime = new Date(); final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.S"); final Action taskPerformer = new AbstractAction() { public void actionPerformed(ActionEvent evt) { // 显示时间 Date d = new Date(System.currentTimeMillis() - startTime.getTime() - 28800000); label.setText(sdf.format(d)); label.repaint(); } }; btnStart.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { startTime.setTime(new Date().getTime()); timer = new Timer(delay, taskPerformer); timer.start(); } }); btnStop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (timer != null && timer.isRunning()) timer.stop(); } }); Container c = getContentPane(); c.add(label, BorderLayout.NORTH); c.add(btnStart, BorderLayout.CENTER); c.add(btnStop, BorderLayout.SOUTH); } public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } private static void createAndShowGUI() { StopWatch window = new StopWatch(); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.pack(); window.setVisible(true); }} BigDecimal 可以实现很高精度。 在线求解!jdom解析xml问题 求教一个java Socket通信问题 半角符号 软件包 javax.servlet 不存在的,急!!! 如何设转置TextField默认焦点?如设置转移焦点的键啊,比如默认是TAB,我把它换成回车键改变焦点? java 保存 征求大家的经验(你在哪里需要记录日志) 请问用java做比较漂亮的界面用什么工具方便? ******java里的日期,怎么实现?????****** 怎样得到java application所在的当前目录路径?(不用JFileChooser) 求助大侠们-取余和整除纠错 关于java调用fortran生成.exe出现的问题
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.*;
import java.util.Date;
import java.text.SimpleDateFormat;/**
* 秒表功能
* @author Administrator
*
*/
public class StopWatch extends JFrame {
JButton btnStart, btnStop;
JLabel label;
Timer timer; public StopWatch() {
label = new JLabel("00:00:00.000");
btnStart = new JButton("start");
btnStop = new JButton("stop");
final int delay = 100;
final Date startTime = new Date();
final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.S");
final Action taskPerformer = new AbstractAction() {
public void actionPerformed(ActionEvent evt) {
// 显示时间
Date d = new Date(System.currentTimeMillis()
- startTime.getTime() - 28800000);
label.setText(sdf.format(d));
label.repaint();
}
};
btnStart.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
startTime.setTime(new Date().getTime());
timer = new Timer(delay, taskPerformer);
timer.start();
}
});
btnStop.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (timer != null && timer.isRunning())
timer.stop();
}
}); Container c = getContentPane();
c.add(label, BorderLayout.NORTH);
c.add(btnStart, BorderLayout.CENTER);
c.add(btnStop, BorderLayout.SOUTH);
} public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
}); } private static void createAndShowGUI() {
StopWatch window = new StopWatch();
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.pack();
window.setVisible(true);
}
}