私は、.net プラットフォームでは非常に単純だった非常に基本的な目標を達成しようとしています: 再利用可能なコンポーネントを作成し、それを別の形式で使用します。私は次のことを試みました:
package ***.composites;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
public class CompTest extends Composite {
/**
* Create the composite.
* @param parent
* @param style
*/
public CompTest(Composite parent, int style) {
super(parent, style);
Composite composite = new Composite(this, SWT.NONE);
composite.setBounds(10, 10, 273, 261);
Button btnCheckButton = new Button(composite, SWT.CHECK);
btnCheckButton.setBounds(82, 112, 93, 16);
btnCheckButton.setText("Check Button");
}
@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
}
と
package ***.composites;
import org.eclipse.swt.widgets.Display;
public class WindTest {
protected Shell shell;
private final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
/**
* Launch the application.
* @param args
*/
public static void main(String[] args) {
try {
WindTest window = new WindTest();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Open the window.
*/
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
/**
* Create contents of the window.
*/
protected void createContents() {
shell = new Shell();
shell.setSize(450, 377);
shell.setText("SWT Application");
Composite composite = formToolkit.createComposite(shell, SWT.NONE);
composite.setBounds(10, 10, 173, 105);
formToolkit.paintBordersFor(composite);
}
}
最初の複合クラスを 2 番目の複合クラスに追加するにはどうすればよいですか? デザインモードでそれを行う方法はありますか?私は正しいことをしていますか?