当前位置:网站首页>Swing display time (click once to display once)
Swing display time (click once to display once)
2022-04-23 05:08:00 【FOWng_ lp】
import javax.swing.*;
import java.awt.*;
public class SwingDemo
{
private static void createGUI()
{
MyFrame frame = new MyFrame("Swing Demo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 300);
frame.setVisible(true);
}
public static void main(String[] args)
{
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run()
{
createGUI();
}
});
}
}
import javax.swing.*;
import javax.swing.plaf.multi.MultiButtonUI;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.SimpleTimeZone;
public class MyFrame extends JFrame {
JLabel timetable = new JLabel("00:00:00");
JButton button = new JButton(" Display time ");
public MyFrame(String swing_demo) {
super(swing_demo);
// Content panel
Container contenePane = getContentPane();
contenePane.setLayout(new FlowLayout());
// Add components to the content panel
contenePane.add(button);
contenePane.add(timetable);
//contenePane.add(new JButton(" test 2"));
// Create a listener object
MyButtonListener listener = new MyButtonListener();
button.addActionListener(listener);
}
//ActionListener It's a interface
private class MyButtonListener implements ActionListener{
public void actionPerformed(ActionEvent e){
// When the button is clicked ,Swing The framework will automatically call the listener actionPerformed() Method
System.out.println(" Button clicked ...");
MyFrame.this.showtime();
}
}
public void showtime(){
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
String timetr = sdf.format(new Date());
timetable.setText(timetr);
}
}
版权声明
本文为[FOWng_ lp]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220549345629.html
边栏推荐
- Some experience in using MySQL / tidb database [slowly updating...]
- AQS源码阅读
- 【数据库】MySQL基本操作(基操~)
- COM in wine (2) -- basic code analysis
- Perfect test of coil in wireless charging system with LCR meter
- View, modify and delete [database] table
- configmap
- Redis lost key and bigkey
- 跨境电商 | Facebook 和 Instagram:哪个社交媒体更适合你?
- 持续集成(CI)/持续交付(CD)如何彻底改变自动化测试
猜你喜欢

Restful toolkit of idea plug-in
![Solve valueerror: argument must be a deny tensor: 0 - got shape [198602], but wanted [198602, 16]](/img/99/095063b72390adea6250f7b760d78c.png)
Solve valueerror: argument must be a deny tensor: 0 - got shape [198602], but wanted [198602, 16]

Define defines constants and macros, pointers and structures

【数据库】MySQL基本操作(基操~)
![[2021] Spatio-Temporal Graph Contrastive Learning](/img/7d/67a0bfa0adecee24bbe291a25ae906.png)
[2021] Spatio-Temporal Graph Contrastive Learning

At pgconf Asia Chinese technology forum, listen to Tencent cloud experts' in-depth understanding of database technology

Servlet3 0 + event driven for high performance long polling

Independent station operation | Facebook marketing artifact - chat robot manychat

How can continuous integration (CI) / continuous delivery (CD) revolutionize automated testing

直播带货表格模板-自动显示图片-自动关联系列商品
随机推荐
MySQL 慢查询
Chapter I overall project management of information system project manager summary
How does PostgreSQL parse URLs
Mac enters MySQL terminal command
configmap
C list field sorting contains numbers and characters
2022/4/22
TypeError: ‘Collection‘ object is not callable. If you meant to call the ......
Unique primary key ID of tidb sub table -- solution to failure of sequence and Gorm to obtain primary key
Progress of innovation training (III)
Deep learning notes - object detection and dataset + anchor box
Golang select priority execution
使用zerotier让异地设备组局域网
Sword finger offer: push in and pop-up sequence of stack
This call when the transaction does not take effect
A trinomial expression that causes a null pointer
The difference between static pipeline and dynamic pipeline
Field injection is not recommended using @ Autowired
[2022 ICLR] Pyramid: low complexity pyramid attention for long range spatiotemporal sequence modeling and prediction
Restful toolkit of idea plug-in