我用K取JTextfield中的值 可怎么就是得不到在JTextfield输入的值
K始终=0 (原来JTextfield的初值)请教各位
代码下面 大部分是界面代码:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class GUANJI1 implements Runnable,ActionListener
{
JFrame jf;
JLabel jl1,jl2,jl3,jl4,jl5;
JPanel jp1,jp2;
JTextField jt1,jt2,jt3;
JButton jb1,jb2,jb3;
int k=0;
public GUANJI1()
{jf=new JFrame("定时关机");
jf.setResizable(false);
jf.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{System.exit(0);}
});
jl1=new JLabel("当前时间:");
jl1.setHorizontalAlignment(SwingConstants.CENTER);
jl1.setText("当前时间:"+gettime());
jl2=new JLabel("等待:");
jl3=new JLabel("时");
jl4=new JLabel("分");
jl5=new JLabel("秒执行");
jt1=new JTextField();
jt1.setHorizontalAlignment(SwingConstants.RIGHT);
jt1.setText("0");
jt2=new JTextField("0");
jt2.setHorizontalAlignment(SwingConstants.RIGHT);
jt3=new JTextField("0");
jt3.setHorizontalAlignment(SwingConstants.RIGHT);
jp1=new JPanel();
jp1.setLayout(new GridLayout(1,7));
jp1.add(jl2);
jp1.add(jt1);
jp1.add(jl3);
jp1.add(jt2);
jp1.add(jl4);
jp1.add(jt3);
jp1.add(jl5);
jb1=new JButton("关 闭");
jb1.setForeground(Color.red);
jb1.setFont(new Font("dialog",0,14));
jb1.addActionListener(this);
jb2=new JButton("重 启");
jb2.setForeground(Color.red);
jb2.setFont(new Font("dialog",0,14));
jb2.addActionListener(this);
jb3=new JButton("注 销");
jb3.setForeground(Color.red);
jb3.addActionListener(this);
jb3.setFont(new Font("dialog",0,14));
jp2=new JPanel();
jp2.setLayout(new FlowLayout());
jp2.add(jb1);
jp2.add(jb2);
jp2.add(jb3);
jf.add(jl1,BorderLayout.NORTH);
jf.add(jp1,BorderLayout.CENTER);
jf.add(jp2,BorderLayout.SOUTH);
}
public void setv()
{
jf.setVisible(true);
jf.pack();
jf.setLocation(400, 270);
}
static GUANJI1 G=null;
public static void main(String ds[])
{
G=new GUANJI1();
G.setv();
}
public void actionPerformed(ActionEvent e)
{GUANJI2 g=new GUANJI2();
Thread t=new Thread(new GUANJI1());
t.start();
try{
t.join();}
catch(Exception ee)
{ee.printStackTrace();}
if(e.getSource()==jb1)
{
//g.shutdown();
System.out.println("关闭");
}
else if(e.getSource()==jb2)
{
//g.restart();
System.out.println("重启");
}
else
{
//g.zhuxiao();
System.out.println("注销");
}
}
public void run()
{
k=Integer.parseInt(jt1.getText().trim())*3600
+Integer.parseInt(jt2.getText().trim())*60
+Integer.parseInt(jt3.getText().trim());
System.out.println(jt3.getText());
//k=6;
System.out.println(k);
while(true)
{
if(k==0)
break;
try{
k--;
Thread.sleep(1000);
jl1.setText("当前时间:"+gettime());
}
catch(Exception e)
{e.printStackTrace();}
}System.out.print(k);
}
public String gettime()
{
String s;
Calendar c=Calendar.getInstance();
s=Integer.toString(c.get(Calendar.HOUR_OF_DAY))+":"
+Integer.toString(c.get(Calendar.MINUTE))+":"+
Integer.toString(c.get(Calendar.SECOND));
return s;
}
}