复制代码代码如下:
Package com.wolf.action;
import java.awt.borderLayout;
import java.awt.dimension;
import java.awt.toolkit;
import java.awt.event.actionEvent;
import java.awt.event.actionListener;
import javax.swing.jdialog;
import javax.swing.timer;
La démonstration de classe publique étend la minuterie {
Final statique privé long SerialVersionUID = 2791827603307165823L;
Demo public (int arg0, actionListener Arg1) {
Super (Arg0, Arg1);
}
public static void main (String [] args) {
MyDialog MyDialog = new MyDialog ();
int hauteur = 150;
TIMERACTION TIMERACTION = NOUVEAU TIMERACTION (MyDialog);
Timer Timer = Nouveau temporisateur (0, temporisation);
timer.start ();
pour (int i = 0; i <10; i ++) {
essayer {
Thread.Sleep (100);
} catch (InterruptedException e) {
e.printStackTrace ();
}
hauteur = hauteur + 5;
TIMERACTION.SETHEight (hauteur);
}
timer.stop ();
Nouvelle démo (1, temporisation);
}
}
classe TIMERACTION implémente ActionListener {
MyDialog MyDialog = null;
private int hauteur = 0;
public void Setheight (int hauteur) {
this.height = hauteur;
}
Timeraction publique (MyDialog MyDialog) {
this.mydialog = mydialog;
}
public void ActionPerformed (événement ActionEvent) {
myDialog.setLocation (((int) mydialog.getScreenSize (). getWidth ()) - 200,
((int) myDialog.getScreenSize (). Getheight () - 20 - hauteur));
MyDialog.SetSize (nouvelle dimension (200, hauteur));
}
}
classe MyDialog étend JDialog {
Final statique privé long SerialVersionUID = 2791827603307165823L;
Private Dimension ScreenSize = Toolkit.getDefaultToolkit (). getScreensize ();
Dimension publique getScreensize () {
Retour écran;
}
public mydialog () {
super();
init ();
}
private void init () {
this.getContentPane (). setLayout (new BorderLayout ());
this.setLocation (((int) scissesize.getwidth ()) - 200,
((int) screensize.getheight () - 20));
this.setVisible (true);
this.setDefaultCloseOperation (jdialog.dispose_on_close);
}
}