主题:在程序中填一个文本框 不知道怎么弄 知道的帮一下忙 谢谢
在显示的中间区填一个文本框 不需要其他的功能 知道的帮一下忙 谢谢了
发到我的邮箱吧:lookseelook@126.com 谢谢了
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class StopWatch extends WindowAdapter{
static JFrame jf=new JFrame();
static TimeRun t;
private JTextField displayField;
private String lastCommand;
private double result;
public StopWatch (){
jf.setSize(300,500);
jf.setTitle("06073123的秒表");
jf.setVisible(true);
jf.setLocation(500,200);
jf.addWindowListener(this);
}
public static void main(String args[]){
StopWatch w=new StopWatch();
TimeRun t=new TimeRun();
t.run();
}
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
class TimeRun extends Thread implements ActionListener{
JLabel jl=new JLabel("时间");
JTextField jtf=new JTextField(" ");
JLabel jl2=new JLabel("秒");
JButton start=new JButton("开始");
JButton startPauseButton=new JButton("继续");
JButton stop=new JButton("暂停");
JButton clear=new JButton("清零");
JPanel jp1=new JPanel();
JPanel jp2=new JPanel();
private float time=0;
private boolean Run=false;
private String time2str(float t) {
int h = (int)t/36000;
int m = ((int)t-h*36000)/600;
double s = (t%600)/10.00;
return String.format("%02d : %02d : %04.2f", h,m,s);
}
public TimeRun(){
jl.setAlignmentX(JLabel.CENTER_ALIGNMENT);
jl2.setAlignmentX(JLabel.CENTER_ALIGNMENT);
jtf.setHorizontalAlignment(JTextField.CENTER);
jtf.setColumns(15);
jp1.add(jl,BorderLayout.WEST);
jp1.add(jtf,BorderLayout.CENTER);
jp1.add(jl2,BorderLayout.EAST);
jp2.setLayout(new FlowLayout());
jp2.add(start);
jp2.add(stop);
jp2.add(clear);
StopWatch.jf.add(jp1,BorderLayout.CENTER);
StopWatch.jf.add(jp2,BorderLayout.SOUTH);
StopWatch.jf.setVisible(true);
start.addActionListener(this);
stop.addActionListener(this);
clear.addActionListener(this);
}
public void run() {
jtf.setText(time2str(time));
while (!this.isAlive() && !this.isInterrupted()) {
if (Run) {
jtf.setText(time2str(time));
try {
Thread.sleep(100);
} catch (InterruptedException e1) {
}
time += 1;
}
}
}
public void actionPerformed(ActionEvent e){
String event=e.getActionCommand();
if(event=="开始"){
StopWatch.jf.setTitle("Start...");
Run=true;
start.setEnabled(false);
stop.setEnabled(true);
clear.setEnabled(false);
}else if(event=="暂停"){
Run=false;
StopWatch.jf.setTitle("Pause...");
stop.setEnabled(false);
start.setEnabled(true);
clear.setEnabled(true);
}else if(event=="清零"){
time=0;
Run=false;
jtf.setText(""+time);
StopWatch.jf.setTitle("Clean...");
start.setEnabled(true);
stop.setEnabled(false);
clear.setEnabled(false);
}
}
}
发到我的邮箱吧:lookseelook@126.com 谢谢了
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class StopWatch extends WindowAdapter{
static JFrame jf=new JFrame();
static TimeRun t;
private JTextField displayField;
private String lastCommand;
private double result;
public StopWatch (){
jf.setSize(300,500);
jf.setTitle("06073123的秒表");
jf.setVisible(true);
jf.setLocation(500,200);
jf.addWindowListener(this);
}
public static void main(String args[]){
StopWatch w=new StopWatch();
TimeRun t=new TimeRun();
t.run();
}
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
class TimeRun extends Thread implements ActionListener{
JLabel jl=new JLabel("时间");
JTextField jtf=new JTextField(" ");
JLabel jl2=new JLabel("秒");
JButton start=new JButton("开始");
JButton startPauseButton=new JButton("继续");
JButton stop=new JButton("暂停");
JButton clear=new JButton("清零");
JPanel jp1=new JPanel();
JPanel jp2=new JPanel();
private float time=0;
private boolean Run=false;
private String time2str(float t) {
int h = (int)t/36000;
int m = ((int)t-h*36000)/600;
double s = (t%600)/10.00;
return String.format("%02d : %02d : %04.2f", h,m,s);
}
public TimeRun(){
jl.setAlignmentX(JLabel.CENTER_ALIGNMENT);
jl2.setAlignmentX(JLabel.CENTER_ALIGNMENT);
jtf.setHorizontalAlignment(JTextField.CENTER);
jtf.setColumns(15);
jp1.add(jl,BorderLayout.WEST);
jp1.add(jtf,BorderLayout.CENTER);
jp1.add(jl2,BorderLayout.EAST);
jp2.setLayout(new FlowLayout());
jp2.add(start);
jp2.add(stop);
jp2.add(clear);
StopWatch.jf.add(jp1,BorderLayout.CENTER);
StopWatch.jf.add(jp2,BorderLayout.SOUTH);
StopWatch.jf.setVisible(true);
start.addActionListener(this);
stop.addActionListener(this);
clear.addActionListener(this);
}
public void run() {
jtf.setText(time2str(time));
while (!this.isAlive() && !this.isInterrupted()) {
if (Run) {
jtf.setText(time2str(time));
try {
Thread.sleep(100);
} catch (InterruptedException e1) {
}
time += 1;
}
}
}
public void actionPerformed(ActionEvent e){
String event=e.getActionCommand();
if(event=="开始"){
StopWatch.jf.setTitle("Start...");
Run=true;
start.setEnabled(false);
stop.setEnabled(true);
clear.setEnabled(false);
}else if(event=="暂停"){
Run=false;
StopWatch.jf.setTitle("Pause...");
stop.setEnabled(false);
start.setEnabled(true);
clear.setEnabled(true);
}else if(event=="清零"){
time=0;
Run=false;
jtf.setText(""+time);
StopWatch.jf.setTitle("Clean...");
start.setEnabled(true);
stop.setEnabled(false);
clear.setEnabled(false);
}
}
}