当前位置:网站首页>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
边栏推荐
- Define defines constants and macros, pointers and structures
- Implementation of switching windows and capturing data in selenium mode
- 持续集成(CI)/持续交付(CD)如何彻底改变自动化测试
- This call when the transaction does not take effect
- 和谐宿舍(线性dp / 区间dp)
- Making message board with PHP + MySQL
- HRegionServer的详解
- The 8 diagrams let you see the execution sequence of async / await and promise step by step
- How can continuous integration (CI) / continuous delivery (CD) revolutionize automated testing
- Day. JS common methods
猜你喜欢
【数据库】MySQL单表查询
[database] MySQL multi table query (I)
Field injection is not recommended using @ Autowired
【数据库】MySQL基本操作(基操~)
深度学习笔记 —— 数据增广
Independent station operation | Facebook marketing artifact - chat robot manychat
Wine (COM) - basic concept
MySQL circularly adds sequence numbers according to the values of a column
《2021多多阅读报告》发布,95后、00后图书消费潜力攀升
Basic concepts of multithreading (concurrency and parallelism, threads and processes) and entry cases
随机推荐
The WebService interface writes and publishes calls to the WebService interface (2)
JS determines whether the numeric string contains characters
信息学奥赛一本通 1212:LETTERS | OpenJudge 2.5 156:LETTERS
[2022 ICLR] Pyraformer: Low-Complexity Pyramidal Attention for Long-Range 时空序列建模和预测
View, modify and delete [database] table
Docker installation and mysql5 7 installation
Discussion on flow restriction
Progress of innovation training (III)
Detailed explanation of hregionserver
Progress of innovation training (IV)
Innovation training (V) mid term inspection
Various ways of writing timed tasks of small programs
MySQL uses or to query SQL, and SQL execution is very slow
DIY is an excel version of subnet calculator
Learning Android II from scratch - activity
Nacos source code startup error report solution
In aggregated query without group by, expression 1 of select list contains nonaggregated column
信息学奥赛一本通 1955:【11NOIP普及组】瑞士轮 | OpenJudge 4.1 4363:瑞士轮 | 洛谷 P1309 [NOIP2011 普及组] 瑞士轮
Learning Android from scratch -- Introduction
C list field sorting contains numbers and characters