2012-09-24 65 views
1

我試圖在LWUIT使用表單玻璃板等待畫面,下面是我使用形式的玻璃板在LWUIT

public class LoadingGlassPane implements Painter { 
    public static boolean isShown = false; 
    public static IForm form; 

    public void paint(Graphics g, Rectangle rect) { 
     System.out.println("paint LoadingGlassPane"); 
     Font font = g.getFont(); 
     int color = g.getColor(); 
     g.setColor(0); 
     g.setFont(Font.getDefaultFont()); 
     g.drawString("Loading...", 20, 120); 
     g.setColor(color); 
     g.setFont(font); 
    } 

    public void installPane(IForm f) { 
     f.setGlassPane(this); 
    } 

    public void uninstallPane(IForm f) { 
     f.setGlassPane(null); 
    } 

    public static IForm getForm() { 
     return form; 
    } 

    public static void setForm(IForm form) { 
     LoadingGlassPane.form = form; 
    } 

    public static boolean isIsShown() { 
     return isShown; 
    } 

    public static void setIsShown(boolean isShown) { 
     LoadingGlassPane.isShown = isShown; 
    } 
} 

public class ProgressGlassPane extends LoadingGlassPane implements Animation, Runnable { 

     int spacing = 20; 
     int fontSpacing = 10; 
     String loadMsg = "Loading..."; 
     //HTMLComponent htmlC; 
    // Dialog loading; 

    // public ProgressGlassPane(Dialog loading) { 
    //  this.loading = loading; 
    // } 
     public ProgressGlassPane() { 
     } 

     public void paint(Graphics g, Rectangle rect) { 
      //while (isShown == true) { 
       System.out.println("paint ProgressGlassPane"); 
       int color = g.getColor(); 
       Font font = g.getFont(); 

       int pos = (int) ((System.currentTimeMillis() % 2700)/300); 
       Font f = Font.getDefaultFont(); 
       //int startX = loading.getAbsoluteX() + (loading.getWidth()/2) - spacing; 
       int startX = (LGB.width/2) - spacing; 
       //int fontStartX = loading.getAbsoluteX() + (loading.getWidth() - f.stringWidth(loadMsg))/2; 
       int fontStartX = (LGB.width - f.stringWidth(loadMsg))/2; 
       //int startY = loading.getAbsoluteY() + (loading.getHeight()/2) - spacing - (f.getHeight() + fontSpacing)/2; 
       int startY = (LGB.height/2) - spacing - (f.getHeight() + fontSpacing)/2; 
       int i = 0; 
       g.setColor(0xffffff); 
       g.fillRect(Math.min(startX - 3, fontStartX), startY - 3, Math.max(spacing * 2 + 7, f.stringWidth(loadMsg)) + 1, spacing * 2 + 7 + f.getHeight() + fontSpacing); 
       g.setColor(0); 
       g.setFont(f); 
       g.drawString(loadMsg, fontStartX, startY); 
       startY += f.getHeight() + fontSpacing; 
       for (int y = 0; y < 3; y++) { 
        for (int x = 0; x < 3; x++) { 
         int thickness = 3; 
         if (i == pos) { 
          thickness = 7; 
         } else if (i == pos - 1) { 
          thickness = 5; 
         } 
         g.fillRect(startX + x * spacing - (thickness/2), startY + y * spacing - (thickness/2), thickness, thickness); 
         i++; 
        } 
       } 
       g.setColor(color); 
       g.setFont(font); 
      // } 
     } 

     public boolean animate() { 
      return true; 
     } 

     public void paint(Graphics g) { 
      paint(g, null); 
     } 

     //void installPane(Form f) { 
     public void installPane(IForm f) { 
      super.installPane(f); 
      //f.setGlassPane(this); 
      f.registerAnimated(this); 

     } 

     //void uninstallPane(Form f) { 
     public void uninstallPane(IForm f) { 
      super.uninstallPane(f); 
      //f.setGlassPane(this); 
      f.deregisterAnimated(this); 
     } 

     public void run() { 
      System.out.println("I'm running"); 
      if (isShown == true && form != null) { 
       installPane(form); 
      } 
      else 
      { 
       uninstallPane(form); 
      } 
     } 
    } 

和代碼從我的表單中

public static ProgressGlassPane progressPane; 
progressPane = new ProgressGlassPane(); 

progressPane.setForm(this); 
progressPane.setIsShown(true); 
progressPane.run(); 

//Some Webservice code I want to run 
progressPane.setIsShown(false); 

我想要做的究竟是什麼,打開玻璃盤,而我加載我的數據和隱藏它,當我完成,但什麼哈ppen它發送請求,並在獲得響應後顯示玻璃窗格,我試圖將我的玻璃窗格放入不同的線程以獨立於主線程運行,並且它也不工作。

回答

1

Web服務代碼是否被阻塞?

如果你在美國東部時間,那麼這是行不通的。您需要從完成中卸載。