1个回答
展开全部
public class ShowTime {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame frame=new JFrame();
Dimension d=new Dimension(400,300);
frame.setSize(d);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JTextField tf=new JTextField();
frame.add(tf, BorderLayout.NORTH);
JButton b=new JButton("显示时间");
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String s;
Calendar cal=Calendar.getInstance();
s=cal.get(Calendar.HOUR_OF_DAY)+":"+cal.get(Calendar.MINUTE)+":"+cal.get(Calendar.SECOND);
tf.setText(s);
//tf.setText(Calendar.getInstance().toString());
}
});
frame.add(b,BorderLayout.CENTER);
frame.setVisible(true);
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame frame=new JFrame();
Dimension d=new Dimension(400,300);
frame.setSize(d);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JTextField tf=new JTextField();
frame.add(tf, BorderLayout.NORTH);
JButton b=new JButton("显示时间");
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String s;
Calendar cal=Calendar.getInstance();
s=cal.get(Calendar.HOUR_OF_DAY)+":"+cal.get(Calendar.MINUTE)+":"+cal.get(Calendar.SECOND);
tf.setText(s);
//tf.setText(Calendar.getInstance().toString());
}
});
frame.add(b,BorderLayout.CENTER);
frame.setVisible(true);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询