commonaction.java
来自「java Java书籍里面有很多初学java的资料」· Java 代码 · 共 39 行
JAVA
39 行
import java.awt.*;import javax.swing.*;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;public class commonAction extends JFrame{ public commonAction() { this.setTitle("a common class action outside"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } JButton b01; public void MyButtonActionPerform(ActionEvent e){ b01.setText("you have done"); } public void DrawContent(){ JPanel panel = new JPanel(); b01 = new JButton("first button"); panel.add(b01); this.getContentPane().add(panel); b01.addActionListener(new ButtonAction(this)); this.pack(); this.setVisible(true); } public static void main(String[] args) { commonAction ca = new commonAction(); ca.DrawContent(); }}//普通类实现class ButtonAction implements ActionListener{ commonAction ca; public ButtonAction(commonAction c){ this.ca=c; } public void actionPerformed(ActionEvent e){ ca.MyButtonActionPerform(e); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?