home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Java by Example
/
jbecd.bin
/
JBE-CD
/
NTUsers
/
JBECODE.ZIP
/
JavaByExample
/
chap24
/
DialogApplet.java
< prev
next >
Wrap
Text File
|
1996-03-08
|
2KB
|
99 lines
import java.awt.*;
import java.applet.*;
public class DialogApplet extends Applet
{
DialogFrame frame;
Button button;
public void init()
{
frame = new DialogFrame("Dialog Window");
button = new Button("Show Window");
add(button);
}
public boolean action(Event evt, Object arg)
{
boolean visible = frame.isShowing();
if (visible)
{
frame.hide();
button.setLabel("Show Window");
}
else
{
frame.show();
button.setLabel("Hide Window");
}
return true;
}
}
class DialogFrame extends Frame
{
MenuBar menuBar;
Dialog dialog;
TextField textField;
String str;
DialogFrame(String title)
{
super(title);
menuBar = new MenuBar();
setMenuBar(menuBar);
Menu menu = new Menu("Test");
menuBar.add(menu);
MenuItem item = new MenuItem("Dialog box");
menu.add(item);
str = "";
}
public void paint(Graphics g)
{
resize(300, 250);
g.drawString("THE TEXT YOU ENTERED IS:", 70, 50);
g.drawString(str, 70, 70);
}
public boolean action(Event evt, Object arg)
{
if (evt.target instanceof MenuItem)
{
if (arg == "Dialog box")
ShowDialogBox();
}
else if (evt.target instanceof Button)
{
if (arg == "OK")
{
dialog.hide();
str = textField.getText();
repaint();
}
}
return true;
}
protected void ShowDialogBox()
{
dialog = new Dialog(this, "Test Dialog", true);
FlowLayout layout = new FlowLayout();
dialog.setLayout(layout);
textField = new TextField("", 20);
Button button = new Button("OK");
dialog.add(button);
dialog.add(textField);
dialog.show();
dialog.resize(200, 100);
}
}