1、写一个类继承JDialog:
如:
package untitled2;
import javax.swing.JDialog;
import javax.swing.JPanel;
import java.awt.Frame;
import java.awt.BorderLayout;
import java.awt.Rectangle;
import javax.swing.JButton;
import javax.swing.JTextArea;
import java.util.Date;
import javax.swing.JScrollPane;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2009</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class Dialog1 extends JDialog {
JPanel panel1 = new JPanel();
JTextArea jTextArea1 = new JTextArea();
JScrollPane jScrollPane1 = new JScrollPane();
public Dialog1(Frame frame, String title, boolean modal) {
super(frame, title, modal);
try {
jbInit();
pack();
}
catch(Exception ex) {
ex.printStackTrace();
}
}
public Dialog1() {
this(null, "", false);
}
void jbInit() throws Exception {
panel1.setLayout(null);
this.getContentPane().setLayout(null);
jScrollPane1.setBounds(new Rectangle(39, 61, 320, 233));
this.getContentPane().add(panel1, null);
panel1.add(jScrollPane1);
jScrollPane1.getViewport().add(jTextArea1);
panel1.setBounds(new Rectangle(0, 0, 400, 300));
acceptConnections();
}
private void acceptConnections() {
new Thread() {
public void run() {
while (true) {
try {
jTextArea1.setText(jTextArea1.getText() +
"\n" + getDate());
} catch (InterruptedException ex) {
}
}
}
}.start();
}
private String getDate() throws InterruptedException {
Thread.sleep(1000);
Date date = new Date();
return date.toLocaleString();
}
2、在applet的按钮中调用自定义的Dialog类:
如:
Frame frame = new Frame();
Dialog1 dlg = new Dialog1(frame, "关于本软件", true);
Dimension dlgSize = dlg.getPreferredSize();
Dimension frmSize = getSize();
Point loc = getLocation();
dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x,
(frmSize.height - dlgSize.height) / 2 + loc.y + 12);
dlg.setSize(new Dimension(300, 200));
dlg.setModal(true);
dlg.setVisible(true);
//等dlg关闭后,会才执行刷新label2
this.jLabel2.setText("dsfdf");










