In a Java SWT lab I had previously, it talks about using Composites then adding the main()
public static void main(String[] args){
Display display = new Display();
Shell shell = new Shell(display);
Calculator calc = new Calculator(shell, SWT.NONE);
calc.pack();
shell.pack();
shell.open();
while(!shell.isDisposed()){
if(!display.readAndDispatch()) display.sleep();
}
}
But why do it this way. Shouldn’t I use a Shell? What might be the reasons for this?
So your question is why you should extend
Compositeand shouldn’t extendShell? Well, you can use any approach you want. But, if you put your stuff directly into the shell, it is going to be much harder to reuse this code in some other place. E.g. usingCompositeas base class for your components, allows you to make your code more reusable (you can’t really put a Shell in the middle of another Composite).