/* A basic extension of the java.applet.Applet class */ import java.awt.*; import java.applet.*; import java.net.*; import java.io.*; import java.awt.event.*; import java.util.*; import MDMSupport.HttpMessage; public class Applet1 extends Applet implements Runnable { Frame4 chatobj=null; public String randid=null; String checkid,listusers; public int slen; TextArea text; Label label; TextField input; Thread thread=null; public String user,usertemp,listid,userid,user1; String mode; public int location; String chstr[]; String chstr1[]; java.awt.Image im; public boolean already=false; public void init() { // Take out this line if you don't use symantec.itools.net.RelativeURL or symantec.itools.awt.util.StatusScroller symantec.itools.lang.Context.setApplet(this); im=getImage(this.getDocumentBase(),"md.gif"); System.out.println("after loading image"); System.out.println("getcode base returns"+getCodeBase()); //{{INIT_CONTROLS setLayout(null); setBackground(new java.awt.Color(208,211,181)); setFont(new Font("Serif", Font.PLAIN, 12)); setSize(123,27); add(textField1); textField1.setBackground(java.awt.Color.white); textField1.setBounds(24,60,144,36); resize(123,27); //setSize(123,27); //}} //{{REGISTER_LISTENERS SymMouse aSymMouse = new SymMouse(); this.addMouseListener(aSymMouse); SymAction lSymAction = new SymAction(); textField1.addActionListener(lSymAction); //}} // Check if this applet was loaded directly from the filesystem. // If so, explain to the user that this applet needs to be loaded // from a server in order to communicate with that server's servlets. URL codebase = getCodeBase(); if (!"http".equals(codebase.getProtocol())) { System.out.println(); System.out.println("*** Whoops! ***"); System.out.println("This applet must be loaded from a web server."); System.out.println("Please try again, this time fetching the HTML"); System.out.println("file containing this servlet as"); System.out.println("\"http://server:port/file.html\"."); System.out.println(); } user=getParameter("user"); if (user==null) user="Unknown"; thread = new Thread(this); int currPriority=thread.currentThread().getPriority(); int newPriority=currPriority==Thread.MIN_PRIORITY?Thread.MIN_PRIORITY:currPriority-1; thread.setDaemon(true); thread.setPriority(newPriority); thread.start(); }//end of init method public void paint(Graphics g) { System.out.println("before painting"); // g.drawImage(im,0,0,this); } //{{DECLARE_CONTROLS java.awt.TextField textField1 = new java.awt.TextField(); //}} class SymMouse extends java.awt.event.MouseAdapter { public void mouseClicked(java.awt.event.MouseEvent event) { Object object = event.getSource(); if (object == Applet1.this) Applet1_MouseClicked(event); } } void Applet1_MouseClicked(java.awt.event.MouseEvent event) { // to do: code goes here. System.out.println("mouse is clicked"); java.util.Date date=new java.util.Date(); Frame1 messframe=new Frame1("MD Messenger "+usertemp+" started at : "+date,this); messframe.setVisible(true); } public void start() { if ((thread!=null) && (thread.isAlive())) { thread.resume(); } else { thread=new Thread(this); thread.setDaemon(true); thread.start(); } } String getNextMessage() { String nextMessage = null; System.out.println("Entered in getNextMessage()"); while (nextMessage == null) { try { System.out.println("This is new"); URL url1 = new URL("http://202.56.229.149/servlet/ChatServletNew"); // URL url = new URL(url1, "servlet/ChatServletNew"); System.out.println("creating the url successs"); HttpMessage msg = new HttpMessage(url1); InputStream in = msg.sendGetMessage(); DataInputStream data = new DataInputStream( new BufferedInputStream(in)); nextMessage = data.readLine(); System.out.println(nextMessage); } catch (SocketException e) { // Can't connect to host, report it and wait before trying again System.out.println("Can't connect to host: " + e.getMessage()); try { Thread.sleep(5000); } catch (InterruptedException ignored) { } } catch (FileNotFoundException e) { // Servlet doesn't exist, report it and wait before trying again System.out.println("Resource not found: " + e.getMessage()); try { Thread.sleep(5000); } catch (InterruptedException ignored) { } } catch (Exception e) { // Some other problem, report it and wait before trying again System.out.println("General exception: " + e.getClass().getName() + ": " + e.getMessage()); try { Thread.sleep(1000); } catch (InterruptedException ignored) { } } } return nextMessage + "\n"; } public void run() { while (true) { String s=this.getNextMessage(); String sub=""; String usename=""; int mlen=s.length(); System.out.println("Inside Run: "+s); if ((s.charAt(0)!='*') && (s.charAt(0)!='^') &&(s.charAt(0)!='#') && (s.charAt(0)!='~')) { int loc1=0; int loc2=0; if (s.charAt(0)=='$') { for (int i=1;i62) { s=s1.substring(0, 61); Frame4.textArea1.appendText(s+"\n"); flag=true; s1=s1.substring(62,s1.length()); len=s1.length(); } if ((len<=62)&& (s!=null) && flag) Frame4.textArea1.appendText(s1); } } } if ((s.charAt(0)=='*') && (s.charAt(0)!='^') && (s.charAt(0)!='#')&& (s.charAt(0)!='~')) { System.out.println(s); chstr=new String[50]; int size=parse(chstr,s); for (int i=0;i\n"); break; } } for (int i=0;i