????????????????????
???????????? ???????[ 2015/9/8 15:49:49 ] ??????????????????
package com.swing.demo;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;
/**
* ????????????????????
* @author Administrator
*
*/
public class ActionListenerTest {
public static void main(String[] args) {
ActionListenerTest instance = new ActionListenerTest();
instance.show();
}
private void show() {
JFrame frame = new JFrame("????");
Container contentPane = frame.getContentPane();
JButton btn = new JButton("???");
JTextArea textArea = new JTextArea();
textArea.setBackground(Color.white);
textArea.setRows(10);
MyActionListener listener = new MyActionListener();
listener.setBtn(btn);
listener.setTextArea(textArea);
btn.addActionListener(listener);
contentPane.add(btn?? BorderLayout.NORTH);
contentPane.add(textArea?? BorderLayout.SOUTH);
frame.pack();
frame.setVisible(true);
frame.requestFocus();
frame.setSize(400?? 300);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private class MyActionListener implements ActionListener {
private JButton btn;
private JTextArea textArea;
public void setBtn(JButton btn) {
this.btn = btn;
}
public void setTextArea(JTextArea textArea) {
this.textArea = textArea;
}
@Override
public void actionPerformed(ActionEvent e) {
btn.setText("hello world");
textArea.setText(textArea.getText() + "new000" + "
");
}
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11