home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-03-15 | 1.4 KB | 64 lines |
- import java.awt.*;
- import java.applet.*;
- import java.net.*;
-
- public class ConnectApplet2 extends Applet
- {
- boolean badURL;
-
- public void init()
- {
- GridLayout layout = new GridLayout(2, 2, 10, 10);
- setLayout(layout);
-
- Font font = new Font("TimesRoman", Font.PLAIN, 24);
- setFont(font);
-
- Button button = new Button("Sun");
- add(button);
- button = new Button("Netscape");
- add(button);
- button = new Button("Microsoft");
- add(button);
- button = new Button("Macmillan");
- add(button);
-
- badURL = false;
- }
-
- public void paint(Graphics g)
- {
- if (badURL)
- g.drawString("Bad URL!", 60, 130);
- }
-
- public boolean action(Event evt, Object arg)
- {
- String str;
-
- if (arg == "Sun")
- str = "http://www.sun.com";
- else if (arg == "Netscape")
- str = "http://www.netscape.com";
- else if (arg == "Microsoft")
- str = "http://www.microsoft.com";
- else
- str = "http://www.mcp.com";
-
- try
- {
- URL url = new URL(str);
- AppletContext context = getAppletContext();
- context.showDocument(url);
- }
- catch (MalformedURLException e)
- {
- badURL = true;
- repaint();
- }
-
- return true;
- }
- }
-
-