home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Java by Example
/
jbecd.bin
/
JBE-CD
/
NTUsers
/
JBECODE.ZIP
/
JavaByExample
/
chap28
/
ConnectApplet.java
< prev
next >
Wrap
Text File
|
1996-03-15
|
1KB
|
61 lines
import java.awt.*;
import java.applet.*;
import java.net.*;
public class ConnectApplet extends Applet
{
TextField textField;
boolean badURL;
public void init()
{
textField = new TextField("", 40);
Button button = new Button("Connect");
add(textField);
add(button);
badURL = false;
}
public void paint(Graphics g)
{
Font font = new Font("TimesRoman", Font.PLAIN, 24);
g.setFont(font);
int height = font.getSize();
if (badURL)
g.drawString("Bad URL!", 60, 130);
else
{
g.drawString("Type the URL to which", 25, 130);
g.drawString("you want to connect,",
25, 130+height);
g.drawString("and then click the Connect",
25, 130+height*2);
g.drawString("button.", 25, 130 + height*3);
}
}
public boolean action(Event evt, Object arg)
{
String str = textField.getText();
try
{
URL url = new URL(str);
AppletContext context = getAppletContext();
context.showDocument(url);
}
catch (MalformedURLException e)
{
badURL = true;
repaint();
}
return true;
}
}