复制代码代码如下:
paquete com.wolf.action;
import java.awt.borderlayut;
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 demostración de clase pública extiende el temporizador {
Private static final Long SerialVersionUid = 2791827603307165823l;
Public Demo (int arg0, ActionListener arg1) {
super (arg0, arg1);
}
public static void main (string [] args) {
MyDialog myDialog = new MyDialog ();
int altura = 150;
TimerAction TimerAction = New TimerAction (MyDialog);
Temporizador temporizador = nuevo temporizador (0, TimerAction);
timer.start ();
para (int i = 0; i <10; i ++) {
intentar {
Thread.sleep (100);
} capt (interruptedException e) {
E.PrintStackTrace ();
}
altura = altura + 5;
TimerAction.setheight (altura);
}
timer.stop ();
nueva demostración (1, TimerAction);
}
}
class TimerAction implementa ActionListener {
MyDialog privado MyDialog = nulo;
Private int altura = 0;
public void setheight (int altura) {
this.Height = altura;
}
Public TimerAction (MyDialog MyDialog) {
this.mydialog = myDialog;
}
public void ActionPerformed (Evento de ActionEvent) {
myDialog.setLocation (((int) myDialog.getScreensize (). getWidth ()) - 200,
((int) myDialog.getScreensize (). getheight () - 20 - altura));
myDialog.setsize (nueva dimensión (200, altura));
}
}
clase MyDialog extiende Jdialog {
Private static final Long SerialVersionUid = 2791827603307165823l;
Private Dimension Screensize = Toolkit.getDefaultToolkit (). GetsCreensize ();
Public Dimension getScreensize () {
Pantalla de retorno;
}
public myDialog () {
súper();
init ();
}
Private void init () {
this.getContentPane (). SetLayout (new BorderLayout ());
this.setLocation (((int) Screensize.getWidth ()) - 200,
((int) Screensize.getheight () - 20));
this.setVisible (verdadero);
this.setDefaultCloseOperation (jdialog.dispose_on_close);
}
}