📄 invoceventdemo.java
字号:
import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.util.*;public class InvocEventDemo extends JFrame implements ActionListener{ private JLabel label; private JButton button; private JPanel southPanel, centerPanel; public InvocEventDemo() { button = new JButton("Time"); button.setBorder(BorderFactory.createRaisedBevelBorder()); button.addActionListener(this); label = new JLabel(""); label.setFont(new Font("Serif", Font.PLAIN, 12)); label.setForeground(Color.black); southPanel = new JPanel(); southPanel.add(button); centerPanel = new JPanel(); centerPanel.add(label); getContentPane().add(southPanel, BorderLayout.SOUTH); getContentPane().add(centerPanel, BorderLayout.CENTER); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 300, 200); setVisible(true); }/* When the JButton is pressed, an ActionEvent is generated and *//* sent to the actionPerformed() method. This method creates an *//* InvocationEvent object which is then dispatched. The event *//* calls the run() method of the GetTime class which displays *//* the current time. */ public void actionPerformed(ActionEvent event) { InvocationEvent ie = new InvocationEvent(this, new GetTime()); ie.dispatch(); } class GetTime implements Runnable { public void run() { Date d = new Date(); label.setText(d.toString()); centerPanel.invalidate(); centerPanel.validate(); } } public static void main(String args[]) { InvocEventDemo demo = new InvocEventDemo(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -