日期:2014-05-20 浏览次数:20916 次
package org.gui; import java.awt.*; import java.awt.event.*; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class TestBiao extends Frame{ /** * @param args */ public TestBiao(){ this.setSize(400, 400); this.setVisible(true); this.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ setVisible(false); System.exit(0); } }); TestCanvas tc = new TestCanvas(); this.add(tc); } public static void main(String[] args) { // TODO Auto-generated method stub new TestBiao(); } } class TestCanvas extends Canvas{ long startTime = 0; long endTime = 0; Date dd,dn = null; String show = ""; boolean bTrue =true; SimpleDateFormat sf = null; public TestCanvas(){ this.setVisible(true); this.enableEvents(AWTEvent.MOUSE_EVENT_MASK); sf = new SimpleDateFormat("HH:mm:ss"); try { dd = (Date)sf.parseObject("00:00:00"); } catch (ParseException e) { e.printStackTrace(); } } public void paint(Graphics g){ System.out.println("进入paint方法.."); if(bTrue){ g.fill3DRect(0, 0, 80, 30, true); g.setColor(Color.WHITE); g.drawString("00:00:00", 20, 20); }else{ g.fill3DRect(0, 0, 80, 30, true); g.setColor(Color.WHITE); g.drawString(show, 20, 20); } } protected void processMouseEvent(MouseEvent e){ if(e.getID()==MouseEvent.MOUSE_PRESSED){ System.out.println("鼠标点击.."); bTrue = true; startTime = System.currentTimeMillis(); }else if(e.getID()==MouseEvent.MOUSE_RELEASED){ System.out.println("鼠标释放.."); bTrue = false; } } }