java - Move from bottom animation JDialog -


i have write animation jdialog, if in listener of jbutton works in constructor no . have try thread , timer , it's not working too.

my code :

testthedialog.java

import java.awt.event.actionlistener; import javax.swing.jframe; import javax.swing.jbutton; import java.awt.event.windowadapter; import java.awt.event.windowevent; import java.awt.event.actionevent;  public class testthedialog implements actionlistener {     jframe mainframe = null;     jbutton mybutton = null;      public testthedialog() {         mainframe = new jframe("testthedialog tester");         mainframe.addwindowlistener(new windowadapter() {                 public void windowclosing(windowevent e) {system.exit(0);}             });         mybutton = new jbutton("test dialog!");         mybutton.addactionlistener(this);         mainframe.setlocationrelativeto(null);         mainframe.getcontentpane().add(mybutton);         mainframe.pack();         mainframe.setvisible(true);     }      public void actionperformed(actionevent e) {         if(mybutton == e.getsource()) {             system.err.println("opening dialog.");             customdialogmessage mydialog = new customdialogmessage(mainframe, true, "+33679149407","azertyuiopqsdfghjklmwxcvbnazertyuiopqsdfghjklmwxcvbn");             system.err.println("after opening dialog.");             if(mydialog.getanswer()) {                 system.err.println("the answer stored in customdialog 'true' (i.e. user clicked yes button.)");             }             else {                 system.err.println("the answer stored in customdialog 'false' (i.e. user clicked no button.)");             }         }     }      public static void main(string argv[]) {          testthedialog tester = new testthedialog();     } } 

customdialogmessage.java :

import javax.swing.jdialog;   import java.awt.color; import java.awt.dimension; import java.awt.fontmetrics; import java.awt.graphicsenvironment; import java.awt.point; import java.awt.rectangle; import java.awt.toolkit; import java.awt.event.actionlistener; import javax.swing.jpanel; import javax.swing.jframe; import javax.swing.jlabel; import javax.swing.jbutton; import javax.swing.timer;  import java.awt.event.actionevent; import java.util.concurrent.timeunit;  public class customdialogmessage extends jdialog implements actionlistener {     /**      *       */     private static final long serialversionuid = 1l;     private jpanel mypanel = null;     private jbutton closebutton = null;     private jbutton answerbutton = null;     private jbutton plusbutton = null;     private boolean answer = false;     public boolean getanswer() { return answer; }     public int dialogwidth = 300;     public int dialogheight = 100;     string textheader ="you got new message :" ;      public customdialogmessage(jframe frame, boolean modal,string mynumero, string mymessage) {         super(frame, modal);         setundecorated(true);         setbackground(new color(82,82,82,175));         final dimension screensize = toolkit.getdefaulttoolkit().getscreensize();         rectangle winsize = graphicsenvironment.getlocalgraphicsenvironment().getmaximumwindowbounds();         final int taskbarheight = screensize.height - winsize.height;         mypanel = new jpanel();         mypanel.setpreferredsize(new dimension(dialogwidth, dialogheight));         mypanel.setbackground(new color(1,0,0,0));         mypanel.setlayout(null);         getcontentpane().add(mypanel);         jlabel header = new jlabel(textheader);         fontmetrics fm = header.getfontmetrics( header.getfont());         fm.stringwidth("you got new message !");         header.setbounds((dialogwidth- fm.stringwidth(textheader))/2, 0, 200, 30);         mypanel.add(header);         closebutton = new jbutton("close");         closebutton.addactionlistener(this);         closebutton.setbounds(210, 75, 90, 25);         mypanel.add(closebutton);          answerbutton = new jbutton("answer");         answerbutton.addactionlistener(this);         answerbutton.setbounds(0, 75, 90, 25);         mypanel.add(answerbutton);         plusbutton = new jbutton("plus");         plusbutton.addactionlistener(this);         plusbutton.setbounds(105, 75, 90, 25);         mypanel.add(plusbutton);         pack();         setlocation(screensize.width-dialogwidth,screensize.height-dialogheight-taskbarheight);         setvisible(true);     }      public void animation(){         dimension screensize = toolkit.getdefaulttoolkit().getscreensize();         rectangle winsize = graphicsenvironment.getlocalgraphicsenvironment().getmaximumwindowbounds();         int taskbarheight = screensize.height - winsize.height;         int = 0;         while(i<=dialogheight){             try {                 timeunit.milliseconds.sleep(50);             } catch (interruptedexception e1) {                 // todo auto-generated catch block                 e1.printstacktrace();             }             i+=5;             this.setlocation(screensize.width-dialogwidth,screensize.height-i-taskbarheight);         }     }  } 

finally find way : ( think many person ;) )

mainwindow.java

import java.awt.event.actionevent; import java.awt.event.actionlistener; import java.io.ioexception;  import javax.swing.jbutton; import javax.swing.jframe;  public class mainwindow extends jframe {      private static final long serialversionuid = 1l;       public mainwindow() throws ioexception {         // name of window         this.settitle("bluenect");         // size of window         this.setsize(300, 300);         // not resize window         this.setresizable(false);         jbutton button = new jbutton("test notif");         button.addactionlistener(new actionlistener() {           @override           public void actionperformed(actionevent e) {               new popupmessage().makeui("0679149407","azertyu iopqsdf ghjklmw xcvbnaze rtyu iopqsdfghjk lmwxcvbn azertyu iopqsdf ghjklmw xcvbnaze rtyu iopqsdfghjk lmwxcvbn azertyu iopqsdf ghjklmw xcvbnaze rtyu iopqsdfghjk lmwxcvbn azertyu iopqsdf ghjklmw xcvbnaze rtyu iopqsdfghjk lmwxcvbn azertyu iopqsdf ghjklmw xcvbnaze rtyu iopqsdfghjk lmwxcvbn");               //new partialframe().makeui("0679149407","azertyu iopqsdf ghjklmw xcvbnaze rtyu iopqsdfghjk");           }         });         this.getcontentpane().add(button);         // close safely frame         this.setdefaultcloseoperation(jframe.exit_on_close);         // put window on center of display         this.setlocationrelativeto(null);         // set window visible         this.setvisible(true);     }      public static void main(string[] args) {         try {             new mainwindow();         } catch (ioexception e) {             e.printstacktrace();         }        } } 

popupmessage.java

import java.awt.color; import java.awt.dimension; import java.awt.fontmetrics; import java.awt.graphics; import java.awt.graphicsenvironment; import java.awt.rectangle; import java.awt.event.actionevent; import java.awt.event.actionlistener; import javax.swing.*;  public class popupmessage {      private int height = 0;     private rectangle screenrect = graphicsenvironment             .getlocalgraphicsenvironment().getmaximumwindowbounds();     private jpanel panel = new jpanel();     private jlabel text;     private jlabel messagesms;     private string messagefull;     private static jtextarea textarea = new jtextarea();     final jbutton plus = new jbutton("plus");     final jbutton reply = new jbutton("reply");     final jbutton close = new jbutton("exit");     final jbutton send = new jbutton("send");     private int secondclick = 0;     private static jscrollpane scrollpanetextarea = new jscrollpane(textarea);     private dimension paneldimension = new dimension(300, 100);     private jdialog dialog = new jdialog() {          /**      *       */         private static final long serialversionuid = 1l;          @override         public void paint(graphics g) {             g.setclip(0, 0, getwidth(), height);             super.paint(g);         }     };      private timer timer = new timer(1, new actionlistener() {          @override         public void actionperformed(actionevent e) {             height += 5;             if (height == dialog.getheight()) {                 timer.stop();             }             dialog.setlocation(screenrect.width - dialog.getwidth(),                     screenrect.height - height);             dialog.repaint();         }     });      private timer timer2 = new timer(1, new actionlistener() {          @override         public void actionperformed(actionevent e) {             height -= 5;             if (height == 0) {                 timer.stop();                 dialog.dispose();             }             dialog.setlocation(screenrect.width - dialog.getwidth(),                     screenrect.height - height);             dialog.repaint();         }     });      public void makeui(string number, string message) {         dialog.setdefaultcloseoperation(jdialog.dispose_on_close);         dialog.setundecorated(true);         dialog.setbackground(new color(1, 0, 0, 0));         panel.setpreferredsize(paneldimension);         panel.setbackground(new color(22, 83, 206, 200));         panel.setlayout(null);         dialog.setcontentpane(panel);          close.addactionlistener(new actionlistener() {              @override             public void actionperformed(actionevent e) {                 timer2.setinitialdelay(0);                 timer2.start();             }         });         close.setbounds(210, 70, 90, 25);          reply.addactionlistener(new actionlistener() {              @override             public void actionperformed(actionevent e) {                 if (secondclick == 0) {                     textarea.setcolumns(20);                     textarea.setlinewrap(true);                     textarea.setrows(5);                     textarea.setwrapstyleword(true);                     scrollpanetextarea.setbounds((panel.getwidth()-280)/2, messagesms.gety()+messagesms.getheight(), 280, 90);                     panel.add(scrollpanetextarea);                     height = dialog.getheight() + scrollpanetextarea.getheight();                     panel.setpreferredsize(new dimension(panel.getwidth(),                             panel.getheight() + scrollpanetextarea.getheight()));                     dialog.setlocation(dialog.getx(), dialog.gety() - scrollpanetextarea.getheight());                     plus.setbounds(plus.getx(), plus.gety()+scrollpanetextarea.getheight(), plus.getwidth(), plus.getheight());                     close.setbounds(close.getx(), close.gety()+scrollpanetextarea.getheight(), close.getwidth(), close.getheight());                     send.setbounds(0, close.gety(), close.getwidth(), close.getheight());                     panel.remove(reply);                     panel.add(send);                     dialog.pack();                 }             }         });         reply.setbounds(0, 70, 90, 25);          plus.addactionlistener(new actionlistener() {              @override             public void actionperformed(actionevent e) {                 if (secondclick == 0) {                     fontmetrics fm = panel.getfontmetrics(messagesms.getfont());                     int sizemessage = fm.stringwidth(messagesms.gettext());                     int decallage = (sizemessage / 90) * 15;                     height = dialog.getheight() + decallage - fm.getheight()*3;                     panel.setpreferredsize(new dimension(panel.getwidth(),                             panel.getheight() + decallage - fm.getheight()*3));                     messagesms.settext("<html><p align=\"justify\">"                             + messagefull);                     dialog.setlocation(dialog.getx(), dialog.gety() - decallage                             + fm.getheight()*3);                     close.setbounds(close.getx(), close.gety() + decallage - fm.getheight()*3, close.getwidth(), close.getheight());                     send.setbounds(send.getx(), send.gety() + decallage - fm.getheight()*3, send.getwidth(), send.getheight());                      reply.setbounds(reply.getx(), reply.gety() + decallage - fm.getheight()*3, reply.getwidth(), reply.getheight());                     panel.remove(plus);                     scrollpanetextarea.setbounds(scrollpanetextarea.getx(), scrollpanetextarea.gety()+ decallage - fm.getheight()*3, scrollpanetextarea.getwidth(), scrollpanetextarea.getheight());                     messagesms.setbounds(messagesms.getx(), messagesms.gety(), messagesms.getwidth(), decallage);                     dialog.pack();                 }             }         });         plus.setbounds(105, 70, 90, 25);          send.addactionlistener(new actionlistener() {              @override             public void actionperformed(actionevent e) {                 timer2.setinitialdelay(0);                 timer2.start();             }         });          messagefull = message;         text = new jlabel("new message :  " + number);         fontmetrics fm = panel.getfontmetrics(text.getfont());         messagesms = new jlabel("<html><center>" + message + "</center></html>");         int textsize = fm.stringwidth(text.gettext());          text.setbounds((paneldimension.width - textsize) / 2, 0, textsize, 25);          textsize = fm.stringwidth(messagesms.gettext());         if (textsize > 810) {             textsize = 290;         }         messagesms.setbounds((paneldimension.width - textsize) / 2, 20,                 textsize, fm.getheight()*3);          panel.add(close);         panel.add(reply);         if (fm.stringwidth(messagesms.gettext()) > 870) {             int sizechar = fm.stringwidth(messagesms.gettext())                     / messagesms.gettext().length();             int allowedchar = 870 / sizechar;             string temp = message.substring(0, allowedchar - 33) + "...";             messagesms.settext("<html><center>" + temp + "</center></html>");             panel.add(plus);         }         panel.add(messagesms);         panel.add(text);          dialog.pack();         dialog.setvisible(true);         timer.setinitialdelay(0);         timer.start();     } } 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -