元のコンポーネントと同じ名前の .ser
ファイルを作成した場合、<component>.class.getName()
の引数を使用してBeanをインスタンス化できます。
オブジェクトの元のクラスがすでにロードされている場合は、Javaビジュアル・エディタにシリアライズされたインスタンスが表示されないことがあります。ただし、コードの実行およびデバッグは予定どおりに機能します。
たとえば、beans.instantiate()
を使用して、クラス名と .ser
ファイル名が同一の、シリアライズされたボタンBeanをインスタンス化する場合、コードは次のように表示されます。
public class ButtonBoxFrame extends JFrame {
XYLayout xYLayout1;
Button button1;
Button button2;
Button button3;
public ButtonBoxFrame() {
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
xYLayout1 = (XYLayout)
beans.instantiate(getClass().getClassLoader(),
XYLayout.class.getName());
button1 = (Button)beans.instantiate(getClass().getClassLoader(),
Button.class.getName());
button2 = (ButtonControl)
beans.instantiate(getClass().getClassLoader(),
Button.class.getName());
button3 = (ButtonControl)
beans.instantiate(getClass().getClassLoader(),
Button.class.getName());
...
}
new
キーワードを使用してオブジェクトをインスタンス化するコードであれば、次のようになります。
public class ButtonBoxFrame extends JFrame {
XYLayout xYLayout1 = new XYLayout();
Button button1 = new Button;
Button button2 = new Button;
Button button3 = new Button;
public ButtonBoxFrame() {
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception{
...
}
Copyright © 1997, 2004, Oracle. All rights reserved.