import java.awt.BorderLayout; import java.awt.event.*; import javax.swing.*; public class MyApplet extends JApplet { public void init () { JButton btnOK = new JButton ("OK"); final JTextField txt = new JTextField ();
btnOK.addActionListener (new ActionListener () { public void actionPerformed (ActionEvent arg0) { PopFrame main = new PopFrame (); main.setSize(200, 100); main.setModal(true); main.show(); String strValue = main.getValue(); txt.setText(strValue); } }); getContentPane ().add(txt, BorderLayout.NORTH); getContentPane ().add(btnOK, BorderLayout.SOUTH); }
public class PopFrame extends JDialog { JTextField txt = null; JButton btnOK = null;
PopFrame () { txt = new JTextField (); getContentPane ().add(txt, BorderLayout.NORTH); btnOK = new JButton("OK"); getContentPane ().add(btnOK, BorderLayout.SOUTH);
btnOK.addActionListener (new ActionListener () { public void actionPerformed (ActionEvent arg0) { hide (); } }); }
public String getValue () { return (txt.getText()); } } }
http://community.csdn.net/Expert/topic/3402/3402558.xml?temp=.2735559分不够加!
import java.awt.event.*;
import javax.swing.*;
public class MyApplet extends JApplet
{
public void init ()
{
JButton btnOK = new JButton ("OK");
final JTextField txt = new JTextField ();
btnOK.addActionListener (new ActionListener ()
{
public void actionPerformed (ActionEvent arg0)
{
PopFrame main = new PopFrame ();
main.setSize(200, 100);
main.setModal(true);
main.show();
String strValue = main.getValue();
txt.setText(strValue);
}
});
getContentPane ().add(txt, BorderLayout.NORTH);
getContentPane ().add(btnOK, BorderLayout.SOUTH);
}
public class PopFrame extends JDialog
{
JTextField txt = null;
JButton btnOK = null;
PopFrame ()
{
txt = new JTextField ();
getContentPane ().add(txt, BorderLayout.NORTH);
btnOK = new JButton("OK");
getContentPane ().add(btnOK, BorderLayout.SOUTH);
btnOK.addActionListener (new ActionListener ()
{
public void actionPerformed (ActionEvent arg0)
{
hide ();
}
});
}
public String getValue ()
{
return (txt.getText());
}
}
}
单击button -> 调用页面方法 -> 页面方法弹出窗体写文字 ->返回信息给页面 ->页面调用applet给信息 (要单击button -> 调用页面方法这一步必须要类包)