java - how to display jbutton on the splashscreen -


how add button splash screen

hi have create java splashscreen , during splash halt/pause , display ok button. have made splash screen run every time compile netbean.

public class main {   static splashscreen mysplash;    // instantiated jvm use                                    // graphics  static graphics2d splashgraphics;  // graphics context overlay of                                    // splash image  static rectangle2d.double splashtextarea;       // area draw text   static rectangle2d.double splashprogressarea;   // area draw progress bar   static font font;                               // used draw our text   public static void main(string[] args)  {    splashinit();           // initialize splash overlay drawing parameters  }   //create button here  private static void splashinit() {    //do coding here mannipulating splash screen   //put ok button here   } } 

how can possibly put button splashscreen? can put jbutton @ jframe or jpanel. possible put button on images splash screen?

reference : splashscreen beginner netbean

"can kind enough instruct me on how make jdialog splash screen? "

in example below, here things do.

  • create jdialog class , make sure undecorated

    public class splashdialog extends jdialog {     ....     setundecorated(true); 
  • give background image

    jlabel background = new jlabel(createimage()); background.setlayout(new borderlayout()); setcontentpane(background); 
  • add jpanel jbutton background. set jpanel not visible, add styling, give jpanel little transparency, when do set visible, can still see background image

    final jpanel panel = new jpanel(new gridbaglayout()); panel.setvisible(false); panel.setbackground(new color(0, 0, 0, 150)); jbutton okbut = new jbutton("ok"); panel.add(okbut); background.add(panel); 
  • use javax.swing.timer set delay button appear.

    timer timer = new timer(5000, new actionlistener(){     public void actionperformed(actionevent e) {         panel.setvisible(true);     } }); timer.setrepeats(false); timer.start(); 
  • make sure frame isn't visible, when button pressed, frame becomes visible , jdialog disposes

    okbut.addactionlistener(new actionlistener(){     public void actionperformed(actionevent e) {         dispose();         parent.setvisible(true);     } }); 

now have simple slash screen

initial splash

enter image description here

splash after 5 seconds

enter image description here

import java.awt.*; import java.awt.event.*; import java.net.malformedurlexception; import java.net.url; import java.util.logging.*; import javax.swing.*;  public class splashdialogdemo {      public splashdialogdemo() {         jpanel panel = new jpanel() {             @override             public dimension getpreferredsize() {                 return new dimension(400, 400);             }         };         panel.setbackground(color.black);          jframe frame = new jframe();         frame.add(panel);         frame.setdefaultcloseoperation(jframe.exit_on_close);         frame.setbackground(color.black);         frame.pack();         frame.setlocationrelativeto(null);          splashdialog splash = new splashdialog(frame, true);     }      public class splashdialog extends jdialog {          public splashdialog(final jframe parent, boolean modal) {             super(parent, modal);              jlabel background = new jlabel(createimage());             background.setlayout(new borderlayout());             setcontentpane(background);              final jpanel panel = new jpanel(new gridbaglayout());             panel.setvisible(false);             panel.setbackground(new color(0, 0, 0, 150));             jbutton okbut = new jbutton("ok");             panel.add(okbut);             background.add(panel);              okbut.addactionlistener(new actionlistener() {                 public void actionperformed(actionevent e) {                     dispose();                     parent.setvisible(true);                 }             });              timer timer = new timer(5000, new actionlistener() {                 public void actionperformed(actionevent e) {                     panel.setvisible(true);                 }             });             timer.setrepeats(false);             timer.start();              addwindowlistener(new windowadapter() {                 @override                 public void windowclosing(windowevent e) {                     system.exit(0);                 }             });              setundecorated(true);             pack();             setlocationrelativeto(parent);             setvisible(true);         }          private imageicon createimage() {             imageicon icon = null;             try {                 url url = new url("http://www.iconsdb.com/icons/download/black/stackoverflow-2-256.png");                 icon = new imageicon(url);             } catch (malformedurlexception ex) {                 logger.getlogger(splashdialogdemo.class.getname()).log(level.severe, null, ex);             }             return icon;         }     }      public static void main(string[] args) {         swingutilities.invokelater(new runnable() {             public void run() {                 try {                     uimanager.setlookandfeel(uimanager.getsystemlookandfeelclassname());                 } catch (classnotfoundexception | instantiationexception | illegalaccessexception | unsupportedlookandfeelexception ex) {                     logger.getlogger(splashdialogdemo.class.getname()).log(level.severe, null, ex);                 }                 new splashdialogdemo();             }         });     } } 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -