62,614
社区成员
发帖
与我相关
我的任务
分享
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class MyTestFrame extends JFrame {
/**
* @param args
*/
private JPanel panel;
private JButton button;
private JTextField textField;
public MyTestFrame(){
super();
init();
}
private void init(){
setSize(800, 600);
setContentPane(getPanel());
this.setResizable(false);
setTitle("TestFrame");
setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
this.setBackground(Color.WHITE);
this.addWindowListener(new WindowListener() {
public void windowActivated(WindowEvent e) {
}
public void windowClosed(WindowEvent e) {
}
public void windowClosing(WindowEvent e) {
System.exit(0);
}
public void windowDeactivated(WindowEvent e) {
}
public void windowDeiconified(WindowEvent e) {
}
public void windowIconified(WindowEvent e) {
}
public void windowOpened(WindowEvent e) {
}
});
}
private JPanel getPanel(){
if(panel==null){
panel = new JPanel();
panel.setBackground(Color.WHITE);
panel.setLayout(null);
button = new JButton();
button.setBounds(370, 200, 60, 20);
button.setText("OK");
button.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
textField.setText(textField.getText()+"A");
try {
Thread.sleep(500);//模拟业务所需时间
} catch (InterruptedException e1) {
}
}
});
textField = new JTextField();
textField.setBounds(350, 160, 100, 20);
panel.add(button);
panel.add(textField);
}
return panel;
}
public static void main(String[] args) {
new MyTestFrame().setVisible(true);
}
}
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class MyTestFrame extends JFrame {
/**
* @param args
*/
private JPanel panel;
private JButton button;
private JTextField textField;
public MyTestFrame() {
super();
init();
}
private void init() {
setSize(800, 600);
setContentPane(getPanel());
this.setResizable(false);
setTitle("TestFrame");
setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
this.setBackground(Color.WHITE);
this.addWindowListener(new WindowListener() {
public void windowActivated(WindowEvent e) {
}
public void windowClosed(WindowEvent e) {
}
public void windowClosing(WindowEvent e) {
System.exit(0);
}
public void windowDeactivated(WindowEvent e) {
}
public void windowDeiconified(WindowEvent e) {
}
public void windowIconified(WindowEvent e) {
}
public void windowOpened(WindowEvent e) {
}
});
}
private JPanel getPanel() {
if (panel == null) {
panel = new JPanel();
panel.setBackground(Color.WHITE);
panel.setLayout(null);
button = new JButton();
button.setBounds(370, 200, 60, 20);
button.setText("OK");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new Thread() {
public void run() {
try {
button.setEnabled(false);
textField.setText(textField.getText() + "A");
try {
Thread.sleep(500);// 模拟业务所需时间
} catch (InterruptedException e1) {
}
} finally {
button.setEnabled(true);
}
}
}.start();
}
});
textField = new JTextField();
textField.setBounds(350, 160, 100, 20);
panel.add(button);
panel.add(textField);
}
return panel;
}
public static void main(String[] args) {
new MyTestFrame().setVisible(true);
}
}