ステップ9: フォームを開くボタンの追加 |
![]() 前へ |
![]() 次へ |
このステップでは、CusotmerフォームおよびOrdersフォームを表示するボタンを、メイン・アプリケーション・ウィンドウに追加する方法を説明します。各ボタンの処理ハンドラには、すでに作成したビジネス・コンポーネント接続を使用して動作するJClient固有のコードが含まれます。
ボタンを標準フレームに追加するには、次のようにします。
UIエディタが開き、フレームが表示されます。
JButton1
およびJButton2
のラベルを、Customer
およびOrders
に変更します。
注意: コードを変更するには、ラベルの編集後に[Enter]キーを押す必要があります。
フレームの2つのボタンは、次のように表示されます。
CustomerビューおよびOrdersビューのための処理ハンドラを作成するには、次のようにします。
「actionPerformed」ダイアログが開きます。
コード・エディタが開き、RootAppModule.java
に処理ハンドラが挿入されます。
jButton1_actionPerformed
処理ハンドラ全体を、次のコードに置き換えます。
// Customer button action handler
private void jButton1_actionPerformed(ActionEvent e)
{
JUApplication app = panelBinding.getApplication();
if (app.findFormBinding(CUSTOMER) == null)
{
// instead of 'customerPanelBinding.setApplication(app)', register
// the panelBinding under an explicit key
app.addFormBinding(CUSTOMER, customerPanelBinding);
customerForm.setPanelBinding(customerPanelBinding);
customerPanelBinding.execute();
customerForm.setVisible(true);
}
else
{
customerForm.setVisible(true);
}
}
UIエディタが再び開き、フレームが表示されます。
コード・エディタが開き、RootAppModule.java
に2つ目の処理ハンドラが挿入されます。
jButton2_actionPerformed
処理ハンドラ全体を、次のコードに置き換えます。
// Orders button action handler
private void jButton2_actionPerformed(ActionEvent e)
{
JUApplication app = panelBinding.getApplication();
if (app.findFormBinding(ORDERS) == null)
{
// instead of 'ordersPanelBinding.setApplication(app)', register
// the panelBinding under an explicit key
app.addFormBinding(ORDERS, ordersPanelBinding);
ordersForm.setPanelBinding(ordersPanelBinding);
ordersPanelBinding.execute();
ordersForm.setVisible(true);
}
else
{
ordersForm.setVisible(true);
}
}
//static String definitions
private final static String CUSTOMER = "Customer";
private final static String ORDERS = "Order";
これらの定義によって、処理ハンドラで使用されるキーが初期化されます。処理ハンドラでは、JClientパネル・バインド参照が実行されます。
//initialize variables used to open the frames
FormCustomersView1 customerForm = new FormCustomersView1();
FormOrdersView1OrderItemsView1 ordersForm = new FormOrdersView1OrderItemsView1();
これらの文によって、CusomerフォームおよびOrdersフォームのコンストラクタを処理ハンドラでコールできます。
システム終了時の動作を変更するには、次のようにします。
FormRootAppModule.java
を開き、FormRootAppModule()
コンストラクタを探して、windowClosing()
を次のように編集します。
public FormRootAppModule()
{
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
_popupTransactionDialog();
// System.exit(0);
setVisible(false);
}
});
}
.java
ファイルを表示し、カーソルをファイルの一番上に置いて[Ctrl]を押しながら、[F]を押します。
「検索」ダイアログが表示されます。
System.exit
と入力し、「OK」をクリックします。 windowClosing()
メソッドで最初に検索された文字列を、次のように編集します。
public void windowClosing(WindowEvent e)
{
// _popupTransactionDialog();
// System.exit(0);
setVisible(false);
}
file_exit_action()
メソッドを次のように編集します。
private void file_exit_action(ActionEvent e)
{
// _popupTransactionDialog();
// System.exit(0);
setVisible(false);
}
.java
ファイルを表示し、カーソルをファイルの一番上に置いて[Ctrl]を押しながら、[F]を押します。
「検索」ダイアログが表示されます。
System.exit
と入力し、「OK」をクリックします。 windowClosing()
メソッドで最初に検索された文字列を、次のように編集します。
public void windowClosing(WindowEvent e)
{
// _popupTransactionDialog();
// System.exit(0);
setVisible(false);
}
file_exit_action()
メソッドを次のように編集します。
private void file_exit_action(ActionEvent e)
{
// _popupTransactionDialog();
// System.exit(0);
setVisible(false);
}
アプリケーションを実行するには、次のようにします。
「ビジネス・コンポーネント用のSwingクライアント・チュートリアルのまとめ」を確認したら、このチュートリアルは終了です。