download ip-demo2
http://rsb.info.nih.gov/ij/download/examples/
===================================================================
extends JFrame 把時間加入文字方塊內
import javax.swing.Timer;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class TimerDemo extends JFrame implements ActionListener {
static JTextField tbx1=new JTextField(10);
Timer t = new Timer(1000,this);
TimerDemo() {
t.start();
}
public static void main(String args[]) {
TimerDemo td = new TimerDemo();
GridLayout grid33= new GridLayout(3,3);
JPanel p1 = new JPanel(grid33); //實作 panel 1
td.setLayout(grid33);
td.setSize(450,450);
td.add(p1); // 在視窗myfrm 內加入 panel 1
p1.add(tbx1); // 在 panel 1內加入文字方塊
td.setVisible(true);
// create a dummy frame to keep the JVM running
// (for demonstation purpose)
//java.awt.Frame dummy = new java.awt.Frame();
//dummy.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == t)
{
//System.out.println
//("Being ticked " + Calendar.getInstance().getTime());
tbx1.setText("Being ticked " + Calendar.getInstance().getTime());
}
}
}
===================================================================
===================================================================
沒有留言:
張貼留言