使いまわし用フレームテンプレートの作成

あるフレームクラスを作成し、アプリケーション・アプレットを作成するたびに、一部修正しながら使おうと思っている。今回のソースはhttp://d.hatena.ne.jp/ryamada/20050806とつないで使うことを想定している。
http://d.hatena.ne.jp/bioinformatics/20050811
今回のこの作業は、次のような理由から行った。
多くのことを覚えているのは大変なので、そのフレームクラスには、使用頻度の高い諸機能が搭載されており、それを適宜コメントアウトしながら、使うことを想定している。
また、完璧なレイアウトを目指すよりも、アプリを作るたびにレイアウトに時間をかけないことも、アプリの体裁に費やすよりもアプリの動作の早期達成を重視する立場からは非常に大事である。
そのような要請のもと、

また、

  • フレームの基本機能としては、
    • フレームからのオプション選択
    • テキスト情報読み込み
    • テキスト情報のテキストエリア書き出し
    • テキスト編集メニュー
    • ファイル操作メニューまでは、基本動作とみなした。

※ 感想
よそから借りてきたソースのつなぎ合わせに終始したが、swing, awtが入り乱れ、相互不整合のためにかなりの時間を消費した。いまだに、基本機能は未完成である。

                                                          • -

作成ソースの構成

  • frames パッケージに、以下2ソースを置く
    • LPanel クラス(GridBagLayoutベースのPanel extensionクラス)

    • それを用いたMyFrame2 クラス
  • My Frameクラスの呼び出しソース

LPanel.java

/*
 * LPanelは Panelクラスを継承し
 * 			GridBagLayoutを便利に行うためのツールを備えたもの
 * 			http://www.eng.auburn.edu/department/cse/research/graph_drawing/graph_drawing.html
 * 			から
 * 			VGJ may be distributed under the terms of the GNU General Public License, Version 2.
 * 			の条件の下、コピーした
 * File: LPanel.java
 *
 * 5/31/97   Larry Barowski
 * 一部改変 08/11/05 ryamada
 *
*/



   package frames;


   import java.awt.GridBagLayout;
   import java.awt.GridBagConstraints;
   import java.awt.Insets;
   import java.awt.Frame;
   import java.awt.TextField;
   import java.awt.Color;
   import java.awt.Label;
   import java.awt.Container;
   import java.awt.Panel;
   import java.awt.Button;
   import java.awt.Component;
   import java.awt.Checkbox;
   import java.awt.CheckboxGroup;
   import javax.swing.*;
   import java.awt.*;
   import java.awt.Event.*;



/**
 * A panel class with convenience functions.
 *	</p>Here is the <a href="../gui/LPanel.java">source</a>.
 *
 *@author	Larry Barowski
**/


   public class LPanel extends Panel
   {
      public Color textColor = Color.white;
      public int spacing = 10;
   
      public GridBagLayout layout;
      public GridBagConstraints constraints;
   
      public LPanel()
      {
         super();
      
         layout = new GridBagLayout();
         constraints = new GridBagConstraints();
         setLayout(layout);
      
         constraints.insets = new Insets(spacing, spacing, spacing,
                                         spacing);
         constraints.fill = GridBagConstraints.NONE;
         constraints.ipadx = constraints.ipady = 0;
         constraints.weightx = constraints.weighty = 1.0;
      }
   
   
      /** Finish initialization. */
      public void finish()
      {
         constraints = null;
         layout = null;
      }
   
   
   
   
   
      /** Add a left aligned label at the start of a line. */
      public Label addLineLabel(String string, int width)
      {
         Label label;
      
         if(width == 0) {
            constraints.gridwidth = GridBagConstraints.REMAINDER;
            constraints.insets.bottom = 0;
         }
         else {
            constraints.gridwidth = width;
            constraints.weightx = 0.0;
         }
      
         constraints.anchor = GridBagConstraints.WEST;
         constraints.insets.top = spacing;
         constraints.insets.left = spacing;
         constraints.insets.right = spacing;
         label = new Label(string);
         layout.setConstraints(label, constraints);
         add(label);
      
         if(width == 0)
            constraints.insets.top = 0;
         constraints.gridwidth = 1;
         constraints.insets.bottom = spacing;
         constraints.weightx = 1.0;
      
         return label;
      }
   
   
      /** Add a panel of evenly-spaced buttons. */
      public Panel addButtonPanel(String labels, int width)
      {
         Panel panel = new Panel();
         GridBagConstraints panel_constraints = new GridBagConstraints();
         panel_constraints.insets = new Insets(0, 0, 0, 0);
         panel_constraints.fill = GridBagConstraints.NONE;
         panel_constraints.ipadx = panel_constraints.ipady = 0;
         panel_constraints.weightx = panel_constraints.weighty = 1.0;
         GridBagLayout panel_layout = new GridBagLayout();
         panel.setLayout(panel_layout);
      
         Button button;
         labels.trim();
         while(labels.length() > 0) {
            int end = labels.indexOf(" ");
            if(end == -1)
               end = labels.length();
         
            String label = labels.substring(0, end);
            button = new Button(label);
            panel_layout.setConstraints(button, panel_constraints);
            panel.add(button);
         
            if(end != labels.length()) {
               labels = labels.substring(end + 1);
               labels.trim();
            }
            else
               break;
         }
      
         constraints.weightx = 0.0;
         constraints.weighty = 0.0;
         constraints.insets.top = spacing * 2;
         constraints.fill = GridBagConstraints.HORIZONTAL;
         if(width == 0)
            constraints.gridwidth = GridBagConstraints.REMAINDER;
         else
            constraints.gridwidth = width;
      
         layout.setConstraints(panel, constraints);
         add(panel);
      
         constraints.weightx = 1.0;
         constraints.weighty = 1.0;
         constraints.insets.top = spacing;
      
         return panel;
      }
   
   
   
   
   
     /** Add a left-aligned, full-width text field. */
      public TextField addTextField(int len, int width, int anchor,
                                    double weightx, double weighty, int fill, int shift)
      {
         TextField textfield = new TextField("", len);
         textfield.setBackground(textColor);
         return (TextField)(addComponent(textfield, width, anchor,
                                         weightx, weighty, fill, shift));
      }
   
   
     /** Add a left-aligned, full-width text field. */
      public TextField addTextField(String text, int len, int width, int anchor,
                                    double weightx, double weighty, int fill, int shift) 
      {
         TextField textfield = new TextField(text, len);
         textfield.setBackground(textColor);
         return (TextField)(addComponent(textfield, width, anchor,
                                         weightx, weighty, fill, shift));
      }
   
   
   
      public Label addLabel(String string, int width, int anchor,
                            double weightx, double weighty, int fill, int shift)
      {
         return (Label)(addComponent(new Label(string), width, anchor,
                                     weightx, weighty, fill, shift));
      }
   
   
   
      public Button addButton(String string, int width, int anchor,
                              double weightx, double weighty, int fill, int shift)
      {
         return (Button)(addComponent(new Button(string), width, anchor,
                                      weightx, weighty, fill, shift));
      }
   
   
      public Checkbox addCheckbox(String string, CheckboxGroup group,
                                  boolean state, int width, int anchor,
                                  double weightx, double weighty, int fill, int shift)
      {
         return (Checkbox)(addComponent(new Checkbox(string, group, state),
                                        width, anchor, weightx, weighty, fill, shift));
      }
   
      public JRadioButton addRadioButton(String string, ButtonGroup group,
            boolean state, int width, int anchor,
            double weightx, double weighty, int fill, int shift)
      {
      	JRadioButton rb = new JRadioButton(string,state);
      	group.add(rb);
      	
      	return (JRadioButton)(addComponent(rb,
                  width, anchor, weightx, weighty, fill, shift));
      }

   
   
      public Component addComponent(Component component, int width,
                                    int anchor, double weightx, double weighty, int fill,
                                    int shift)
      {
         constraints.insets.left = spacing;
         constraints.insets.right = spacing;
         if(shift == 1 || shift == 3)
            constraints.insets.left = 0;
         if(shift == 2 || shift == 3)
            constraints.insets.right = 0;
      
         if(anchor < 0)
            constraints.anchor = GridBagConstraints.WEST;
         else if(anchor == 0)
            constraints.anchor = GridBagConstraints.CENTER;
         else
            constraints.anchor = GridBagConstraints.EAST;
      
         if(width == 0)
            constraints.gridwidth = GridBagConstraints.REMAINDER;
         else
            constraints.gridwidth = width;
      
         constraints.weightx = weightx;
         constraints.weighty = weighty;
      
         if(fill == 0)
            constraints.fill = GridBagConstraints.NONE;
         else if(fill == 1)
            constraints.fill = GridBagConstraints.HORIZONTAL;
         else if(fill == 2)
            constraints.fill = GridBagConstraints.VERTICAL;
         else
            constraints.fill = GridBagConstraints.BOTH;
      
         layout.setConstraints(component, constraints);
         add(component);
      
         if(width == 0)
            constraints.insets.top = constraints.insets.bottom = spacing;
      
         return component;
      }
   
   
   
   
   }

MyFrame2

package frames;

import javax.swing.*;




import java.awt.*;
import java.awt.Event.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.net.URL;
import java.io.StringBufferInputStream;
import java.io.FileInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.io.InputStream;
/**
 * 作成日: 2005/08/07
 * @author ryamada
 *
 */
public class MyFrame2 extends Frame{
	/*
	 * フレームの構成
	 * フレームの外枠にタイトル表示欄
	 * メニューバー(メニューバーは1つ)
	 * 本体部分であるContainer
	 * ContainerにLPanelを搭載し、
	 * LPanel上にいろいろな部品を搭載する
	 * 		LPanelは Panelクラスを継承し
	 * 			GridBagLayoutを便利に行うためのツールを備えたもの
	 * 			http://www.eng.auburn.edu/department/cse/research/graph_drawing/graph_drawing.html
	 * 			から
	 * 			VGJ may be distributed under the terms of the GNU General Public License, Version 2.
	 * 			の条件の下、コピーした
	 */
	
	/*
	 * LPanelの使用
	 * 複数のLPanelを作成する
	 * 複数のLPanelをMyFrameのContainer上に配置する
	 * 	BorderLayoutをデフォルトで使用する
	 * 複数のLPanelはLPanel上にLPanelを搭載するなどして入れ子状態を作ることも可能
	 */
	
	/*
	 * LPanel上に配する基本部品
	 * 	搭載上のmethodを備える
	 * 		単独で機能するButton
	 * 		グループで機能するCheckBox
	 * 		文字列表示用のLabel
	 *  	TextField
	 * 	このほかの部品については、搭載にあたりaddComponent methodを用いる
	 */
	private String filename_;
	private static JTextArea myTextArea_0;
	//Constructor
	public MyFrame2(String title){

		/*
		 * フレームの作成
		 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
		 */
		
		//タイトルを指定
		super(title);//親クラスJFrameのコンストラクタ
		/*
		 * その他の設定
		 * これ以外にフレームに指定することは、表示時のサイズと可視化
		 * ただし、このフレームをクラスとして使用する他のソースで作成・可視化する
		 * setSize(100,1000);//サイズ指定
		 * setVisible(true);//可視化
		 */
		
		/*
		 * メニューバーの作成
		 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
		 */

		//JMenuBar myMenuBar;
		MenuBar myMenuBar = new MenuBar();
			//メニューバーをフレームにセット
			//myMenuBar = new JMenuBar();
			
			setMenuBar(myMenuBar);
			
			/*
			 * メニューバーの設計
			 */

		
		
		//メニュー1,2をメニューバーへ搭載
		
		Menu myMenu1 = new Menu("File");//myMenu1の表示文字列
		Menu myMenu2 = new Menu("Edit");
		Menu myMenu3 = new Menu("CheckBoxMenu");
		/*
		Menu myMenu3 = new Menu("myMenu3");
		Menu myMenu4 = new Menu("myMenu4");
		*/
			//MenuBarへの搭載
			myMenuBar.add(myMenu1);
			myMenuBar.add(myMenu2);
			myMenuBar.add(myMenu3);
			/*
			myMenuBar.add(myMenu3);
			myMenuBar.add(myMenu4);
			*/
		//メニューアイテムをメニューに追加
			//メニュー1
			MenuItem myItem1_1 = new MenuItem("New");
			MenuItem myItem1_2 = new MenuItem("Open");
			MenuItem myItem1_3 = new MenuItem("Save");
			MenuItem myItem1_4 = new MenuItem("Save As");
			MenuItem myItem1_5 = new MenuItem("Exit");
			
			myMenu1.add(myItem1_1);
			myMenu1.add(myItem1_2);
			myMenu1.add(myItem1_3);
			myMenu1.add(myItem1_4);
			myMenu1.add(myItem1_5);
			//メニュー2
			MenuItem myItem2_1 = new MenuItem("Copy");
			MenuItem myItem2_2 = new MenuItem("Paste");
			MenuItem myItem2_3 = new MenuItem("Cut");
			MenuItem myItem2_4 = new MenuItem("Select All");
			MenuItem myItem2_5 = new MenuItem("Delete");
			
			myMenu2.add(myItem2_1);
			myMenu2.add(myItem2_2);
			myMenu2.add(myItem2_3);
			myMenu2.add(myItem2_4);
			myMenu2.add(myItem2_5);
			//メニュー3
			CheckboxMenuItem cbmi1 = new CheckboxMenuItem("CheckBox Menu Item1");
			CheckboxMenuItem cbmi2 = new CheckboxMenuItem("CheckBox Menu Item2");
			CheckboxMenuItem cbmi3 = new CheckboxMenuItem("CheckBox Menu Item3");
			CheckboxMenuItem cbmi4 = new CheckboxMenuItem("CheckBox Menu Item4");
			
			
			myMenu3.add(cbmi1);
			myMenu3.add(cbmi2);
			myMenu3.add(cbmi3);
			myMenu3.add(cbmi4);
	        
	        cbmi1.setState(true);//デフォルトで選択
	        cbmi4.setState(true);//デフォルトで選択


		/*
		 * 本体(コンテナ・パネル・部品)の作成
		 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
		*/
		
		/*
		 * コンテナの作成
		 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
		 */
		//コンテナの作成
		/*
		Container myContainer = null;
			//フレームにコンテナをセット
			myContainer = this.getContentPane();
			//Layout マネージャ
			myContainer.setLayout(new BorderLayout());
		*/
				/*
				 * その他のオプション
				 * myContainer.setLayout(new FlowLayout());
				 * 部品の配置をSetBoundsで座標指定する場合には
				 * myContainer.setLayout(null);
				 */
		
		/*
		 * パネルの作成(複数個のパネル)
		 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
		 */
			/*
			 * パネルの個数 Np,myPListに格納
			 * パネルの色は Color Pcol[]で指定
			 * パネルのレイアウトはGridBagLayout
			 */
		int Np = 4;//パネル数
		LPanel myPList[];
		myPList = new LPanel[Np];
		Color Pcol[] = {Color.LIGHT_GRAY,Color.ORANGE,Color.LIGHT_GRAY,Color.LIGHT_GRAY};
		
		for(int i=0;i<Np;i++){
			LPanel myPanel_i;
			myPanel_i = new LPanel();
			myPanel_i.setBackground(Pcol[i]);
			myPList[i] = myPanel_i;
		}
		/*
		 * 個々のパネルに部品の搭載
		 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
		 */
		/*
		 * 基本部品
		 * 	単独で機能するButton
		 * 	グループで機能するCheckBox
		 * 	文字列表示用のLabel
		 * 	TextField
		 * 追加部品
		 * 	例としてTextAreaを提示
		 */
		
		/*
		 * myPList[0]
		 * 0番目のパネルへの部品の搭載
		 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
		 * チェックボックスグループと
		 * ラジオボタングループを搭載
		 */
		/*
         * LPanel.addCheckbox, LPanel.addRadiobuttonの用法
         * 第1引数:表示文字列
         * 第2引数:所属クループ
         * 第3引数:デフォルトの選択状態(trueはグループ中1つ)
         * 第4引数:占拠するカラム幅(1は1カラム分、2は2カラム分、0は、残っているカラムすべて)
         * 第5引数:表示の左詰(-1)、中央揃え(0)、右詰(1)
         * 第6,7引数:weightx,weighty. フレームの拡張時に他の部品との相対拡大幅(デフォルトを1.0,1.0とする)
         * 第8引数:fill. 
         *   貼り付けるマスが自分自身がより大きい場合に、 自分自身をどのように広げるかを次のいずれかで指定します。
         *   	0 ―― 大きさを変えない
         *   	1 ―― 縦、横いっぱいに広げる
         *   	2 ―― 横方向のみ広げる
         *   	3 ―― 縦方向にのみ広げる
         * 第9引数:shift. 自分自身とマスの枠の間にあけるべき間隔を指定します。
         *   	0 ―― デフォルトのままspacing = 8
         *   	1 ―― 左側のスペースを0にする
         *   	2 ―― 右側のスペースを0にする
         *   	3 ―― 左右両側のスペースをゼロにする
         */
		
		//チェックボックス・グループ
		//myPList[0].spacing = 0;
		myPList[0].addLineLabel("パネル1のチェックボックスグループ:", 0);
        CheckboxGroup ch_group = new CheckboxGroup();
        /*
         * 全部で9個のチェックボックスからなるチェックボックスグループを配する
         * 1段目に2個、2段目に3個、3段目に4個
         * 1段目の1個目は幅1、左詰
         * 1段目の2個目は、残りの幅をすべて占める、左詰表示
         */
        myPList[0].addCheckbox("chBox1-1", ch_group, true, 1, -1, 1.0, 1.0, 0, 0);
        myPList[0].addCheckbox("chBox1-2", ch_group, false, 1, -1, 1.0, 1.0, 0, 0);
        myPList[0].addCheckbox("chBox1-3", ch_group, false, 1, -1, 1.0, 1.0, 0, 0);
        myPList[0].addCheckbox("chBox1-4", ch_group, false, 1, -1, 1.0, 1.0, 0, 0);
        myPList[0].addCheckbox("chBox1-5", ch_group, false, 1, -1, 1.0, 1.0, 0, 0);
        myPList[0].addCheckbox("chBox1-6", ch_group, false, 0, -1, 1.0, 1.0, 0, 0);
        //第4引数に0を与えたので、この行はすべて埋まった
        //したがって次の部品は次の段へ
        
        //1行目と2行目の間には、デフォルトのスペースが入ったが、
        //2行目と3行目との間は0にする
        myPList[0].constraints.insets.bottom = 0;
        myPList[0].addCheckbox("chBox2-1", ch_group, false, 1, -1, 1.0, 1.0, 0, 0);
        myPList[0].addCheckbox("chBox2-2", ch_group, false, 0, -1, 1.0, 1.0, 0, 0);
        
        myPList[0].constraints.insets.top = myPList[0].constraints.insets.bottom = 0;
        myPList[0].addCheckbox("chBox3-1", ch_group, false, 1, -1, 1.0, 1.0, 0,
                0);
        //幅2を与える
        myPList[0].addCheckbox("chBox3-2", ch_group, false, 2, -1, 1.0, 1.0, 0,
                0);
        myPList[0].addCheckbox("chBox3-3", ch_group, false, 1, -1, 1.0, 1.0, 0,
                0);
        myPList[0].addCheckbox("chBox3-4", ch_group, false, 0, -1, 1.0, 1.0, 0,
                0);
        //4行目は幅、2,1,2,残り全て、の設定
        myPList[0].constraints.insets.top = myPList[0].constraints.insets.bottom = 0;
        myPList[0].addCheckbox("chBox4-1", ch_group, false, 2, -1, 1.0, 1.0, 0,
                      0);
        myPList[0].addCheckbox("chBox4-2", ch_group, false, 1, -1, 1.0, 1.0, 0,
                0);
        myPList[0].addCheckbox("chBox4-3", ch_group, false, 2, -1, 1.0, 1.0, 0,
                0);
        myPList[0].addCheckbox("chBox4-4", ch_group, false, 0, -1, 1.0, 1.0, 0,
                      0);
        //5行目は中央揃え
        myPList[0].constraints.insets.top = myPList[0].constraints.insets.bottom = 0;
        myPList[0].addCheckbox("chBox5 中央揃", ch_group, false, 0, 0, 1.0,
                1.0, 0, 0);
        myPList[0].constraints.insets.top = myPList[0].constraints.insets.bottom = 0;
        myPList[0].addCheckbox("chBox6 右詰", ch_group, false, 0, 1, 1.0,
                      1.0, 0, 0);
        myPList[0].constraints.insets.top = myPList[0].constraints.insets.bottom = 0;
        myPList[0].addCheckbox("chBox7 左詰", ch_group, false, 0, -1, 1.0,
                1.0, 0, 0);
        //チェックボックス・グループ
		myPList[0].addLineLabel("パネル1のラジオボタングループ:", 0);
        //3番目のラジオボタンをデフォルトで選択する
        ButtonGroup button_group = new ButtonGroup();
        myPList[0].constraints.insets.top = myPList[0].constraints.insets.bottom = 0;
        myPList[0].addRadioButton("RadioButton0", button_group, false, 1, -1, 1.0,
                1.0, 0, 0);
        
        myPList[0].addRadioButton("RadioButton1", button_group, false, 1, -1, 1.0,
                1.0, 0, 0);
        myPList[0].constraints.insets.top = myPList[0].constraints.insets.bottom = 0;
        myPList[0].addRadioButton("RadioButton2", button_group, true, 0, -1, 1.0,
                1.0, 0, 0);
        
        /*
		 * myPList[1]
		 * 1番目のパネルへの部品の搭載
		 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
		 * チェックボックスグループと
		 * ラジオボタングループを搭載
		 */
        /*
         * LPanel.addTextFieldの用法
         * 第1引数:表示文字列
         * 第2引数:フィールドの幅(半角文字数)
         * 第3引数:占拠するカラム幅(1は1カラム分、2は2カラム分、0は、残っているカラムすべて)
         * 第5引数:表示の左詰(-1)、中央揃え(0)、右詰(1)
         * 第6,7引数:weightx,weighty. フレームの拡張時に他の部品との相対拡大幅(デフォルトを1.0,1.0とする)
         * 第8引数:fill. 
         *   貼り付けるマスが自分自身がより大きい場合に、 自分自身をどのように広げるかを次のいずれかで指定します。
         *   	0 ―― 大きさを変えない
         *   	1 ―― 縦、横いっぱいに広げる
         *   	2 ―― 横方向のみ広げる
         *   	3 ―― 縦方向にのみ広げる
         * 第9引数:shift. 自分自身とマスの枠の間にあけるべき間隔を指定します。
         *   	0 ―― デフォルトのままspacing = 8
         *   	1 ―― 左側のスペースを0にする
         *   	2 ―― 右側のスペースを0にする
         *   	3 ―― 左右両側のスペースをゼロにする
         */
        myPList[1].addLineLabel("パネル1のテキストフィールド:", 0);
        myPList[1].constraints.insets.top = myPList[1].constraints.insets.bottom = 0;
        String txt_df = "ここはデフォルトの文字列50半角文字分のスペース";
        myPList[1].addTextField(txt_df,50,0,-1,1.0,1.0,0,0);
        myPList[1].addLineLabel("パネル1のテキストフィールド:", 0);
        myPList[1].constraints.insets.top = 0;
        String txt_df2 = "ここはデフォルトの文字列75半角文字分のスペース";
        myPList[1].addTextField(txt_df2,75,0,-1,1.0,1.0,0,0);
        
        /*
		 * myPList[2]
		 * 2番目のパネルへの部品の搭載
		 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
		 * ボタンと
		 * ラベルを搭載
		 */
        
        
        myPList[2].constraints.insets.top = myPList[2].constraints.insets.bottom = 0;
        //全幅を占めるボタン1-1、ただし、表示は、1区画分
        myPList[2].addButton("ボタン1-1", 0, -1, 1.0, 1.0, 0, 0);
        myPList[2].constraints.insets.top = myPList[2].constraints.insets.bottom = 0;
        //全幅を占めるボタン2-1、ただし、表示は、全幅分
        myPList[2].addButton("ボタン2-1", 0, -1, 1.0, 1.0, 1, 0);
        myPList[2].constraints.insets.top = myPList[2].constraints.insets.bottom = 0;
        //全幅を5個のボタンで占める。幅はそれぞれ1
        //全幅が5になった
        myPList[2].addButton("ボタン3-1", 1, -1, 1.0, 1.0, 0, 0);
        myPList[2].addButton("ボタン3-2", 1, -1, 1.0, 1.0, 1, 0);
        myPList[2].addButton("ボタン3-3", 1, -1, 1.0, 1.0, 0, 0);
        myPList[2].addButton("ボタン3-4", 1, -1, 1.0, 1.0, 0, 0);
        myPList[2].addButton("ボタン3-5", 0, -1, 1.0, 1.0, 0, 0);
        myPList[2].constraints.insets.top = myPList[2].constraints.insets.bottom = 0;
        //全幅を4個のボタンで占める。幅はそれぞれ1,2,1,残り(1)
        //ただし、ボタン4-2は左詰で隙間がある
        myPList[2].addButton("ボタン4-1", 1, -1, 1.0, 1.0, 0, 0);
        myPList[2].addButton("ボタン4-2", 2, -1, 1.0, 1.0, 0, 0);
        myPList[2].addButton("ボタン4-3", 1, -1, 1.0, 1.0, 0, 0);
        myPList[2].addButton("ボタン4-4", 0, -1, 1.0, 1.0, 0, 0);
        myPList[2].constraints.insets.top = myPList[2].constraints.insets.bottom = 0;
        //全幅を4個のボタンで占める。幅はそれぞれ1,2,1,残り(1)
        //ただし、ボタン4-2は左詰で隙間をfill=1で埋める
        myPList[2].addButton("ボタン5-1", 1, -1, 1.0, 1.0, 0, 0);
        myPList[2].addButton("ボタン5-2", 2, -1, 1.0, 1.0, 1, 0);//fill = 1
        myPList[2].addButton("ボタン5-3", 1, -1, 1.0, 1.0, 0, 0);
        myPList[2].addButton("ボタン5-4", 0, -1, 1.0, 1.0, 0, 0);
        //ラベルを4個
        myPList[2].addLabel("ラベル1",1,-1,1.0,1.0,0,0);
        myPList[2].addLabel("ラベル2",1,-1,1.0,1.0,0,0);
        myPList[2].addLabel("ラベル3",1,-1,1.0,1.0,0,0);
        myPList[2].addLabel("ラベル4",0,-1,1.0,1.0,0,0);
        
     
        /*
		 * myPList[3]
		 * 2番目のパネルへの部品の搭載
		 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
		 * コンポーネントとしてテキストエリアを作成し
		 * それをパネルに追加する
		 */
        
        JTextArea myTextArea_0;
		myTextArea_0 = new JTextArea(8,50);
		myTextArea_0.setLineWrap(true);//折り返しサポート
		JScrollPane myScroll_0 = new JScrollPane(myTextArea_0);//スクロールつき
		
		JTextArea myTextArea_1;
		myTextArea_1 = new JTextArea(10,20);
		myTextArea_1.setLineWrap(true);//折り返しサポート
		JScrollPane myScroll_1 = new JScrollPane(myTextArea_1);//スクロールつき
		
        myPList[3].addLineLabel("テキストエリア:", 0);
        //縦方向にテキストフィールドを広げて表示するために第6引数を2とする
        //フレームの拡大にあたり、他の部品よりも優先(10倍)して拡大するために
        //第4,5引数に10を入れる
        myPList[3].addComponent(myScroll_0,2,-1,10.0,1.0,2,0);
        myPList[3].addComponent(myScroll_1,0,-1,10.0,10.0,2,0);
        
        /*
		 * パネルのコンテナ上の配置
		 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
		 */
        //myPlist[1]をmyPlist[0]に横幅いっぱいを占拠して、左詰、表示幅はいっぱいで搭載する
        myPList[0].addComponent(myPList[1], 0, -1, 1.0, 1.0, 1, 0);
        //myPList[3]を北、[2]を西、[0]を東にボーダーレイアウトする
        //myContainer.add(myMenuBar,BorderLayout.NORTH);
        add(myPList[3],BorderLayout.SOUTH);
        add(myPList[2],BorderLayout.WEST);
        add(myPList[0],BorderLayout.EAST);
        
           
        //設定終了
		for(int i=0;i<Np;i++){
			myPList[i].finish();
		}
			
		validate();

	}
    public boolean action(Event event, Object what)
    
    {
    	
       if(event.target instanceof Checkbox)
       {
          CheckboxGroup cbgrp = ((Checkbox)(event.target)).getCheckboxGroup();
          Checkbox selected = cbgrp.getCurrent();
          String label = selected.getLabel();
       
          
          if(label.equals("chBox1-1"))
             ;
          else if(label.equals("chBox1-2"))
             ;
          else if(label.equals("chBox2-1"))
             ;
          else if(label.equals("chBox3-1"))
             ;
       
          
       }
       else if(event.target instanceof CheckboxMenuItem)
       {
          String label = ((CheckboxMenuItem)(event.target)).getLabel();
          boolean state = ((CheckboxMenuItem)(event.target)).getState();
       
          if(label.equals("CheckBox Menu Item1"))
             ;
          else if(label.equals("CheckBox Menu Item2"))
          	;
          else if(label.equals("CheckBox Menu Item3"))
             ;
          else if(label.equals("CheckBox Menu Item3"))
          	;
          
       }
       else if(event.target instanceof MenuItem)
       {
       		MenuItem menuitem = (MenuItem)event.target;
            String label = menuitem.getLabel();
          
             if(label.equals("New")) {
 
             }
             else if(label.equals("Open")) {
                String filename = null;
             
                   FileDialog fd;
                   fd = new FileDialog(this, "Open File", FileDialog.LOAD);
                   //fd = null;
                   try {
                      fd = new FileDialog(this, "Open File", FileDialog.LOAD);
                      fd.show(); }
                   catch(Throwable e) {
                    /*  
                   	MessageDialog dg = new MessageDialog(this,
                         "Error", "It appears your VM does not allow file loading.", true);
                      return true;
                      */
                   }
                   filename = fd.getFile();
                   if(filename == null)
                      return true;
                   filename = fd.getDirectory() + filename;

                   loadFile(filename);
                   return true;
             }
             else if(label.equals("Save") || label.equals("Save As"))
             {
                try
                {
                   String filename;
                   if(label.equals("Save As") || filename_ == null)
                   {
			FileDialog fd;
			fd = new FileDialog(this, "Save File ", FileDialog.SAVE);
			//fd = null;
			try {
                        
						fd = new FileDialog(this, "Save File ", FileDialog.SAVE);
                         fd.show(); }
                      catch(Throwable e) {
                         //MessageDialog dg = new MessageDialog(this,
                            //"Error", "It appears your VM does not allow file saving.", true);
                         //return true;
                      }

                      filename = fd.getFile();
                      if(filename == null)
                         return true;
                   
                      // Work around JDK Windows bug.
                      if(filename.endsWith(".*.*"))
                      {
                         String tmpstr = filename.substring(0, filename.length() - 4);
                         filename = tmpstr;
                      }
                      filename = fd.getDirectory() + filename;
                   }
                   else
                      filename = filename_;
                
                   PrintStream ps = new PrintStream(new FileOutputStream(filename));
                   
                   ps.close();
                
                   filename_ = filename;
                   //setTitle_();
                }
                   catch (IOException e)
                   {
                      //MessageDialog dg = new MessageDialog(this,
                                                          //"Error", e.getMessage(), true);
                   }
             
             }
             else if(label.equals("Exit"))
                Destroy();
            
             else if(label.equals("Copy"))
                ;
             else if(label.equals("Paste"))
                ;
             else if(label.equals("Cut"))
                ;
             else if(label.equals("Select All"))
                ;
             else if(label.equals("Delete"))
             	;
             

       } 
       else if(event.target instanceof Button)
       {
          if(((String)what).equals("ボタン1-1")){
          	//String st = myTextArea_0.getText();
          	//System.out.println(st);
	        MyFrame2 frame = new MyFrame2("st");
	  		frame.addWindowListener(new WindowAdapter(){
	  	   		public void windowClosing(WindowEvent e){
	  	   			System.exit(0);
	  	   		}
	  	   	});
	  	   
	  	   
	  	   try {
	  	   	UIManager.setLookAndFeel(
	  	   			"com.sun.java.swing.plaf.motif.MotifLookAndFeel");
	  	   	SwingUtilities.updateComponentTreeUI(frame);
	  	   	
	  	   } catch (Exception e){
	  	   	
	  	   }
	  	   
	  	   frame.setSize(200,200);
	  	   frame.setVisible(true);
          }else if(((String)what).equals("ボタン1-2"))
          	;
          
       
       }
       return true;
    }
 
    public void loadFile(String filename)
    {
            try {
                   File fname = new File(filename);
                   int size = (int)fname.length();
                   int bytes_read = 0;
                   FileInputStream infile = new FileInputStream(fname);
                   byte[] data = new byte[size];
                   while (bytes_read < size)
                      bytes_read += infile.read(data, bytes_read, size - bytes_read);
                
                   StringBufferInputStream stream = new StringBufferInputStream(new String(data, 0));
                   
                }
                   catch (FileNotFoundException e)
                   {
                     // MessageDialog dg = new MessageDialog(this,
                          //"Error", "Error loading file  \"" + filename + "\".", true);
                   }
                
                   catch (IOException e)
                   {
                      //MessageDialog dg = new MessageDialog(this,
                                                          //"Error", e.getMessage(), true);
                   }
                  

    }

    // Function is called on an exit menu choice or delete from the WM menu
    private void Destroy()
    {
       dispose();
    }
 
 

}


MyFrame2を呼び出すmain関数ソース

/*
 * 作成日: 2005/08/06
 *
 * TODO この生成されたファイルのテンプレートを変更するには次へジャンプ:
 * ウィンドウ - 設定 - Java - コード・スタイル - コード・テンプレート
 */
package run;

import java.awt.Color;
import java.awt.Frame;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import frames.*;
/**
 * @author ryamada
 *
 * TODO この生成された型コメントのテンプレートを変更するには次へジャンプ:
 * ウィンドウ - 設定 - Java - コード・スタイル - コード・テンプレート
 */
public class Main {

	public static void main(String[] args) {
		//Frame frame = new Frame("frame_name");
		MyFrame2 frame = new MyFrame2("frame name");
		frame.addWindowListener(new WindowAdapter(){
	   		public void windowClosing(WindowEvent e){
	   			System.exit(0);
	   		}
	   	});
	   
	   
	   try {
	   	UIManager.setLookAndFeel(
	   			"com.sun.java.swing.plaf.motif.MotifLookAndFeel");
	   	SwingUtilities.updateComponentTreeUI(frame);
	   	
	   } catch (Exception e){
	   	
	   }
	   
	   frame.setSize(800,600);
	   frame.setVisible(true);
	   
	  
	}
}