欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

java右下角弹窗示例分享

程序员文章站 2024-02-28 11:11:16
复制代码 代码如下:package com.wolf.action; import java.awt.borderlayout;import java.awt.dimen...

复制代码 代码如下:

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;

public class demo extends timer {

 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 height = 150;
  timeraction timeraction = new timeraction(mydialog);
  timer timer = new timer(0, timeraction);
  timer.start();
  for (int i = 0; i < 10; i++) {
   try {
    thread.sleep(100);
   } catch (interruptedexception e) {
    e.printstacktrace();
   }
   height = height + 5;
   timeraction.setheight(height);
  }
  timer.stop();
  new demo(1, timeraction);
 }
}

class timeraction implements actionlistener {
 private mydialog mydialog = null;

 private int height = 0;

 public void setheight(int height) {
  this.height = height;
 }

 public timeraction(mydialog mydialog) {
  this.mydialog = mydialog;
 }

 public void actionperformed(actionevent event) {
  mydialog.setlocation(((int) mydialog.getscreensize().getwidth()) - 200,
    ((int) mydialog.getscreensize().getheight() - 20 - height));
  mydialog.setsize(new dimension(200, height));
 }
}

class mydialog extends jdialog {

 private static final long serialversionuid = 2791827603307165823l;

 private dimension screensize = toolkit.getdefaulttoolkit().getscreensize();

 public dimension getscreensize() {
  return screensize;
 }

 public mydialog() {
  super();
  init();
 }

 private void init() {
  this.getcontentpane().setlayout(new borderlayout());
  this.setlocation(((int) screensize.getwidth()) - 200,
    ((int) screensize.getheight() - 20));
  this.setvisible(true);
  this.setdefaultcloseoperation(jdialog.dispose_on_close);
 }

}