2011-03-09 41 views
1

我鑽研佈局&試圖瞭解他們的工作。佈局是否像Java Swing中的JPanel一樣?也就是說,我們在哪裏宣佈主面板&將所有小部件添加到此?Mosync:爲什麼慣於此顯示我的佈局

我不明白的一件事是當我們創建一個移動應用程序時,我們創建了一個佈局&列表框。這兩個對象之間的關係是什麼?

  • Layout對象是否包含Listbox,那麼我們將所有的小部件添加到列表框?
  • 抑或列表框有一個佈局定義,那麼我們根據佈局
  • 小部件添加到它們對齊列表框&還是我們中的Java Swing添加所有部件的佈局是怎樣的?

PS:以下我的實驗,我的小工具沒有顯示?它只是一個空白的黑屏。爲什麼會發生?

#include <MAUtil/Moblet.h> 
#include <MAUI/Layout.h> 
#include <MAUI/ListBox.h> 
#include <MAUI/Label.h> 
#include <MAUI/EditBox.h> 
#include <MAUI/Screen.h> 
#include <MAUtil/Environment.h> 
#include <madmath.h> 
#include <conprint.h> 


using namespace MAUtil; 
using namespace MAUI; 

class TemperatureScreen : public Screen //, public PointerListener 
{ 
    public: 
     TemperatureScreen() 
     { 
      MAExtent screenDim = maGetScrSize(); 
      Layout* mainLayout = new Layout(0, 0, EXTENT_X(screenDim), EXTENT_Y(screenDim), NULL, 1, 3); 
      ListBox* mainListBox = new ListBox(0, 0, 100, 200, mainLayout, 
             ListBox::LBO_VERTICAL, ListBox::LBA_LINEAR, 
             true); 
      mainListBox -> setPaddingLeft(10); 
      mainListBox -> setPaddingRight(10); 
      mainListBox -> setPaddingTop(10); 
      mainListBox -> setPaddingBottom(10); 
      mainListBox -> setBackgroundColor(900); 
      mainLayout -> setBackgroundColor(300); 

      Label *celLabel  = new Label(10, 300, 50, 20, mainLayout); 
      Label *fahLabel  = new Label(10, 300, 50, 20, mainLayout); 
      EditBox *celEdit = new EditBox(10, 300, 50, 20, mainLayout); 
      EditBox *fahEdit = new EditBox(10, 300, 50, 20, mainLayout); 
      Label *toCelsiusRb = new Label(10, 300, 50, 20, mainLayout); 
      Label *toFahRb  = new Label(10, 300, 50, 20, mainLayout); 
      Label *convertLabel = new Label(10, 300, 50, 20, mainLayout); 
      Label *exitLabel = new Label(10, 300, 50, 20, mainLayout); 

      celLabel  -> setCaption("Celcius"); 
      fahLabel  -> setCaption("Fahrenheit"); 
      convertLabel -> setCaption("Convert"); 
      exitLabel -> setCaption("Exit"); 
      /*celLabel -> addPointerListener(this); 
      fahLabel  -> addPointerListener(this); 
      convertLabel -> addPointerListener(this); 
      exitLabel -> addPointerListener(this);*/ 

      mainLayout -> add(celLabel); 
      mainLayout -> add(fahLabel); 
      mainLayout -> add(convertLabel); 
      mainLayout -> add(exitLabel); 
     } 

}; 

class TemperatureMoblet : public Moblet 
{ 
    public: 
     TemperatureMoblet() 
     { 
      instance = new TemperatureScreen(); 
      instance -> show(); 
     } 

     ~TemperatureMoblet() 
     { 
      delete instance; 
     } 

     void keyPressEvent(int keyCode, int nativeCode) 
     { 
      // todo: handle key presses 
      printf("Blah"); 
     } 

     void keyReleaseEvent(int keyCode, int nativeCode) 
     { 
      // todo: handle key releases 
     } 

    private: 
     TemperatureScreen *instance; 
}; 

extern "C" int MAMain() 
{ 
    Moblet::run(new TemperatureMoblet()); 
    return 0; 
}; 

回答

相關問題