Tuesday, December 8, 2009

Are You Supposed To Get Dry On The Shot

Window splash with NetBeans

image A splash window is a display window, without the classic buttons and it will serve to give a better presentation to our project.

This window should be placed at the beginning of our application, to start we need to design what will be our display picture which for reasons of time I chose NetBeans, and this we will add a progress bar

  1. Open the NetBeans and create a new project, which it believes not to uncheck the class main: image
  2. Create the folder where our image will be testing it right click on Source Package → New → Other so leave a window in which we choose Other → Folder and finally we give the name you want: image image
  3. Splash Now create a package in which we will add a JFrame and create a class for the thread you'll use, so they should be well: image
  4. We will work on our frame, which you right click and give → BorderLayout setLayout done put two panels: one on the south and one in the center (follow the order to avoid complications). After you have added the panels to each BorderLayout we will give as the frame. Done this we will place in the south a JProgressBar panel which we will call that progress and the central panel a label, we should look like: image
  5. To change the name we give JProgresBar right click on the bar and choose "Change Variable name" then we will leave the following window in which we place the name of the bar: image
  6. In the central panel will place a label to which we will Put a picture, view this entry to see how an image รง Place: image
  7. JFrame In the designer we will add code to do this we click on button image source, and and in the JFrame class (which call Principal) we add an object Thread:
     import java.awt.Color; 

    public class Main extends javax.swing.JFrame {
    HiloProgreso
    thread;


  8. We
  9. to the manufacturer and we add the following code: public
     Main () {

    / / default method
    initComponents ();
    iniciarSplash ();
    / / Create an object which
    HiloProgreso / / we pass as parameter the progress bar thread = new HiloProgreso
    (progress);
    / / Start the thread
    hilo.start () ;
    / / We give our size and position
    this.setLocation Frame (200.200);
    this.setSize (472.249);
    / / Free resources
    thread = null;}



  10. create a get method for our JProgressBar, for it or add it directly or do that NetBeans generates it, for this right click on the select Refactor → attribute → select Encapsulate Fields and in the window that appears just select the set and get methods that we want to generate image NetBeans image


  11. then appears as follows line of code: public
     javax.swing.JProgressBar getjProgressBar1 () {return 
    progress;}



  12. Now if we can creat our method starting Splash:
     iniciarSplash public void () {
    this.getjProgressBar1 ( ). setBorderPainted (true);
    this.getjProgressBar1 (). SetForeground (new Color (50, 50, 153, 100));
    this.getjProgressBar1 (). SetStringPainted (true);}



  13. NetBeans we should be marking Error This is because we have not created our class HiloProgreso; for this package click Splash → New → Java Class and the class name we give HiloProgreso and we do that extends Thread, in this class must create a reference to progress bar that we pass parameters to which we declare a JProgressBar progress:
     Splash package; 
    import
    javax.swing.JProgressBar;
    public
    HiloProgreso class extends Thread {
    JProgressBar
    progress;



  14. Now let's create our constructor method which will have as parameters a progreso1 bar, it should be noted as given the partnership that is the reference the object passed as parameter the reference assigned to the previously believed and that I can use all the methods (the super method is to call the constructor of the Thread class and by law must be the first line in the constructor of the class daughter):
     HiloProgreso public class extends Thread {
    JProgressBar
    progress;
    public
    HiloProgreso (JProgressBar progreso1)

    {super ();
    this.progreso = progreso1;}



  15. done this we will create the run method that will serve to draw the thread:
     public void run () {

    for (int i = 1; i \u0026lt;= 100; i + +) {

    progreso.setValue (i);
    pause (100);
    }}



  16. And finally we break our method, which As the name suggests will give us pause for no progress bar reaches 100% n let us run the application:
     public void pause (int mlSeg) 

    {try {

    / / pause for the splash
    Thread.sleep (mlSeg)
    } catch (Exception e) {}}



  17. This done press F6 and you see something like this: image


  18. The example can be downloaded from here:





btn_6







* If the download link does not work, please go to the shared folder that section is right, this will send them directly to my shared folder in the shared folder → go to Examples Java Examples → → → Cap_18_NetBeans Splash.



* For an application call ended after splash time I would ask you to modify the application and to do that (no later than tomorrow I'm changing)

0 comments:

Post a Comment