package com.transjam.chatter; import java.io.*; import java.applet.*; import java.net.*; import java.awt.*; import java.awt.event.*; import java.util.*; import com.transjam.util.*; import com.transjam.client.*; import com.transjam.awt.*; /** Applet that logs into the TransJam server and * puts up a Chat interface within the Applet's web page. * @author (C) 1997-2002 Phil Burk, SoftSynth.com, All Rights Reserved */ public class Chatter extends Applet { private ClientHelper helper; private ChatPanel chatPanel; private Client client; /** Define main() so that we can test this Applet like a regular application. * Then we can debug it using an IDE instead of a browser. */ public static void main( String argv[] ) { // Create one of these Applet objects. Chatter applet = new Chatter(); // Test the applet using this browser simulator. AppletTester.test( applet, 500, 400 ); } /** When the Applet starts, login to the server, * display a chat interface, and start chatting. */ public void start() { // Use helper to simplify logging in. helper = new ClientHelper(); // Connect to the server. int maxClientsPerRoom = 10; client = helper.connect( this, "chatter", maxClientsPerRoom ); if( client == null ) { add( new Label("Connection to server failed! Please try again later.") ); } else { // Create a panel for chatting with others. setLayout( new BorderLayout() ); add( "Center", chatPanel = new ChatPanel( client ) ); chatPanel.start(); // Login to the server using a popup Dialog. helper.login(); } // Make the GUI visible. getParent().validate(); getToolkit().sync(); } /** When the Applet is stopped, logout from the server and cleanup the GUI. */ public void stop() { helper.logout(); removeAll(); } }