package newdialog; import java.awt.*; import java.awt.event.*; import java.applet.*; public class Applet1 extends Applet { boolean isStandalone = false; Button button1 = new Button(); newDg anewdg; TextField textField1 = new TextField(); //引数値の取得 public String getParameter(String key, String def) { return isStandalone ? System.getProperty(key, def) : (getParameter(key) != null ? getParameter(key) : def); } //アプレットの構築 public Applet1() { } //アプレットの初期化 public void init() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } //コンポーネントの初期化 private void jbInit() throws Exception { button1.setLabel("newDialog"); button1.setBounds(new Rectangle(71, 120, 98, 27)); button1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button1_actionPerformed(e); } }); this.setLayout(null); textField1.setText("textField1"); textField1.setBounds(new Rectangle(56, 71, 129, 23)); this.add(textField1, null); this.add(button1, null); } void button1_actionPerformed(ActionEvent e) { anewdg = new newDg(this); anewdg.setVisible(true); } void getNameEx(){//新規ダイアログから呼び出される //String name=anewdg.namex; textField1.setText(anewdg.textField1.getText()); anewdg.setVisible(false); } }
public class newDg extends Frame { public Applet1 parent;//親の参照 TextField textField1 = new TextField(); Button button1 = new Button(); public newDg(Applet1 pt) {//コンストラクタ try { jbInit(); } catch(Exception e) { e.printStackTrace(); } setSize(200,150); setLocation(100,200); parent=pt; } public newDg() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception {//部品配置 textField1.setText("textField1"); textField1.setBounds(new Rectangle(20, 29, 164, 25)); this.setLayout(null); button1.setLabel("ok"); button1.setBounds(new Rectangle(77, 72, 59, 23)); button1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button1_actionPerformed(e); } }); this.add(textField1, null); this.add(button1, null); } //ボタン処理 void button1_actionPerformed(ActionEvent e) { parent.getNameEx(); //setVisible(false); } }