文本框显示时间

package zwzw;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import javax.swing.*;
public class vv implements ActionListener {
JFrame jf;
JButton jb1,jb2;
JLabel jl1,jl2,jl3,jl5,jl4,jl6,jl7,jl8,jl9;
JPanel jp;
JTextField jt1,jt2,jt3,jt4,jt5,jt6;
SimpleDateFormat m = new SimpleDateFormat("yy");
SimpleDateFormat n = new SimpleDateFormat("MM");
SimpleDateFormat l = new SimpleDateFormat("dd");
SimpleDateFormat x = new SimpleDateFormat("HH");
SimpleDateFormat y = new SimpleDateFormat("mm");
SimpleDateFormat z = new SimpleDateFormat("ss");
public vv(){
jf=new JFrame("时钟");
jl1 = new JLabel("当前时间:");
jl2 = new JLabel("年");
jl3 = new JLabel("月");
jl4 = new JLabel("日");
jl6 = new JLabel("时");
jl7 = new JLabel("分");
jl8 = new JLabel("秒");
jp = new JPanel();
jt1 = new JTextField(8);
jt2 = new JTextField(8);
jt3 = new JTextField(8);
jt4 = new JTextField(8);
jt5 = new JTextField(8);
jt6 = new JTextField(8);
jb1= new JButton("显示");
jb2= new JButton("清除");
jb1.addActionListener(this);
jb2.addActionListener(this);
jp.add(jl1);
jp.add(jt1);
jp.add(jl2);
jp.add(jt2);
jp.add(jl3);
jp.add(jt3);
jp.add(jl4);
jp.add(jt4);
jp.add(jl6);
jp.add(jt5);
jp.add(jl7);
jp.add(jt6);
jp.add(jl8);
jp.add(jb1);
jp.add(jb2);
jf.add(jp);
jf.setSize(500,360);
jf.setVisible(true);
jf.setLocation(300, 200);
}
public static void main(String[] args) {
new vv();
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jb1) {
jt1.setText(m.format(new java.util.Date()).toString());
jt2.setText(n.format(new java.util.Date()).toString());
jt3.setText(l.format(new java.util.Date()).toString());
jt4.setText(x.format(new java.util.Date()).toString());
jt5.setText(y.format(new java.util.Date()).toString());
jt6.setText(z.format(new java.util.Date()).toString());
}else if(e.getSource()==jb2) {
jt1.setText(null);
jt2.setText(null);
jt3.setText(null);
jt4.setText(null);
jt5.setText(null);
jt6.setText(null);
}
}
}

1634302-20190606113752099-1305560507.jpg

1634302-20190606113807849-1468560001.jpg

转载于:https://www.cnblogs.com/isudh5554537/p/10984045.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值