dwt learning question,please help

Sam Hu samhu.samhu at gmail.com
Thu Aug 28 18:14:23 PDT 2008


Recently I read a DWT example ,a simple window form contains a label which has a gif image.when form resize,the label either show the whole picture or a messagebox hints the form is too small which can not show the whole image.When I comile the source,an Exception was thrown with info" Array Index out of bounds.",I have no clue about this exception message.Who can help? Thanks.

//*******************************
// smile.gif is in the same folder with source file

module resizeapp; 

import dwt.DWT; 
import dwt.widgets.Display; 
import dwt.widgets.Shell; 
import dwt.widgets.Label; 
import dwt.graphics.Image; 
import dwt.graphics.ImageData; 
import dwt.layout.GridLayout; 
import dwt.layout.GridData; 
import dwt.events.ControlAdapter; 
import dwt.events.ControlEvent; 

import dwt.widgets.MessageBox; 
import tango.core.Exception; 

class MainForm 
{ 
private: 
Display display; 
Shell shell; 
Label label; 
Image image; 

void InitializeComponents() 
{ 
display=new Display; 
shell =new Shell(display); 
image=new Image(display,r"smile.gif"); 

shell.setLayout(new GridLayout); 
label=new Label(shell,DWT.NONE); 
label.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); 
label.setImage(image); 
shell.setData(label); 

shell.addControlListener(new class ControlAdapter{ 
public void controlResized(ControlEvent e) 
{ 
Shell shell=cast(Shell)e.getSource; 

Label label=cast(Label)shell.getData; 
Rectangle rect=shell.getClientArea; 
ImageData data=label.getImage.getImageData; 

if(rect.width<data.width || rect.height<data.height) 
{ 
shell.setText("Too small"); 
label.setText("Oh~ No"); 

} 
else 
{ 
shell.setText("Smile everyday!"); 
label.setImage(label.getImage); 
} 

} 
}); 
shell.pack; 
shell.open; 

while(! shell.isDisposed) 
{ 
if(! display.readAndDispatch) 
display.sleep; 
} 
if(!(image is null)) 
image.dispose; 
display.dispose; 

} 
public: 
this() 
{ 
InitializeComponents; 
} 
} 
int main(char[][] args) 
{ 
try 
{ 
MainForm mainForm=new MainForm; 
} 
catch(Exception e) 
{ 
MessageBox.showError(e.toString,"Fatal Error"); 
return -1; 
} 

return 0; 
} 
//***************************************** 


More information about the Digitalmars-d-dwt mailing list