java - Proper method for creating splashscreen with drawImage(g) -
i'm learning construct japplet, though of yet haven't traveled far beneath surface. have image(.png) ideally painted paintcomponent(s) before interface "painted" or rather added within paint() method.
interestingly, japplet loads intended after cloned appletviewer. seems i'm missing understanding of lifecycle, or operational dynamics otherwise.
here's code, swing comp. definitions have been removed brevity:
public class jfriendsphones extends japplet implements actionlistener, mouselistener { public void init(){ submit.addactionlistener(this); querybyname.addactionlistener(this); querybynum.addactionlistener(this); setvisible(true); introduction = getgraphics(); prepareimage(intro, this); intro = getimage( getcodebase(), "introduction.png"); setvisible(true); validate(); } public void start(){ } public void paint(graphics g){ paintcomponent(g); } public void stop(){ } public void destroy(){ } public void actionperformed( actionevent ev ){ object source = ev.getsource(); returnlab.setvisible(false); resultspan.setbackground(color.white); if( true ){ if( querybyname.gettext().equals("") != true && querybynum.gettext().equals("") != true ){ outcomelab.settext("search 1 term"); querybyname.settext(""); querybynum.settext(""); } else if( querybyname.gettext().equals("") == true && querybynum.gettext().equals("") == true){ outcomelab.settext("enter search term"); } else { if(querybyname.gettext().equals("") == false){ for( int = 0; < 5; i++ ){ if(querybyname.gettext().equalsignorecase(friends[i])){ resultspan.setbackground(new color(190,255,200)); outcomelab.settext("1-result found:"); returnlab.settext(frnumbers[i]); returnlab.setvisible(true); found = true; } } if(found == false){ resultspan.setbackground(new color(240,100,100)); outcomelab.settext("0-matches"); } } else { for( int = 0; < 5; i++ ){ if(querybynum.gettext().equalsignorecase(frnumbers[i])){ resultspan.setbackground(new color(190,255,200)); outcomelab.settext("1-result found:"); returnlab.settext(friends[i]); returnlab.setvisible(true); found = true; } } if( found == false){ resultspan.setbackground(new color(240,100,100)); outcomelab.settext("0-matches"); } } } } found = false; } public void componentresized( componentevent cev){ repaint(); } @override public void componentmoved(componentevent e) { contain.repaint(); } @override public void componentshown(componentevent e) { paintcomponent(introduction); } @override public void componenthidden(componentevent e) { // todo auto-generated method stub } public void mouseclicked( mouseevent clicked){ repaint(); } @override public void mousepressed(mouseevent e) { } @override public void mousereleased(mouseevent e) { } @override public void mouseentered(mouseevent e) { } @override public void mouseexited(mouseevent e) { } public void paintcomponent(graphics gr){ super.paintcomponents(gr); if(initialized == false){ gr.drawimage(intro, 10, 10, 280, 430, this); validate(); initialized = true; } else { titl_instrpan.add(titlelab); titl_instrpan.add(instructlab); titl_instrpan.add(instructlab2); inputpan.add(bynamelab); inputpan.add(querybyname); inputpan.add(bynumlab); inputpan.add(querybynum); inputpan.add(regionpan); inputpan.add(submit); resultspan.add(outcomelab, borderlayout.north); resultspan.add(returnlab, borderlayout.south); resultspan.setbackground(color.white); mainpanel.add(titl_instrpan, borderlayout.north); mainpanel.add(inputpan, borderlayout.center); mainpanel.add(resultspan, borderlayout.south); contain.add(mainpanel); setvisible(true); validate(); } } end class jfriendsphones
you have messed default painting mechanism of swing not invoking super.paint(...).
anyway, don't override paint(..) of japplet!!! there no need this.
Comments
Post a Comment