🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #614

Applet doesn't working in IE

#614
From: Alex Tyutyunik
Date: Fri, 23 May 2003 07:28
126 lines
4196 bytes
Hello.
Has read here in the book, that applet which it is constant repaint, should
use in addition a stream.
In the book the example was the worker. It works in IE, my - is not.
Look please, what not so.
I did it in JBuilder 7.
If that it is possible - correct please.
The general idea - > To show in HTML the current date and time (UTC) when
midnight hs come -> again to synchronize with a server.

There is the source code:

package javatimer;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.net.*;
import java.io.*;
import java.awt.image.*;
import java.sql.Time;

// TimeServer
class QComputer{
private String Address;
public QComputer() throws UnknownHostException{
Address = "132.163.4.101";
}

public String get_IPAddress(){
return Address;
}
}

public class MyTimer extends Applet implements Runnable {
private QComputer _QComputer;
private Socket sock;
private InputStream in;
private String quote;
private Time nowtime;
private int times[] = new int[3];
private Thread thr = null;

//Construct the applet
public MyTimer() {
try{
_QComputer = new QComputer();
} catch (UnknownHostException e){}
}

public void start() {
try{
// ����������� � IP-�����:13
sock = new Socket(_QComputer.get_IPAddress(),13);
in = sock.getInputStream();
quote = "";
Thread.sleep(700); // Answer delay
thr = new Thread(this);
thr.start();
} catch (Exception e){destroy();}
try{
while (in.available() != 0) {
quote += (char) in.read();
}
int tire = quote.indexOf('-');
int dvoe = quote.indexOf(':');
quote = quote.substring(tire-2,dvoe+6);
int i = quote.indexOf(":");
times[0] = Integer.parseInt(quote.substring(i-2,i));
times[1] = Integer.parseInt(quote.substring(i+1,i+3));
times[2] = Integer.parseInt(quote.substring(i+4,i+6));
nowtime = new Time(times[0],times[1],times[2]);
}
catch (Exception e) {}
}

//Initialize the applet
public void init() {
setBackground(new Color(20,111,168));
}

public void paint(Graphics g) {
g.setColor(new Color(20,111,168));
g.fillRect(0, 0, 300, 100);
g.setColor(Color.white);
if(quote != null && quote.length()>0 && nowtime != null)
g.drawString(quote.substring(0,8) + ' ' + nowtime.toString(), 1,12);
}

public void run() {
for(;){
repaint();
try {
Thread.sleep(1000);
} catch(Exception e) {}
if(nowtime != null) {
String midnight = nowtime.toString();
if(nowtime.toString().substring(0,2) == "00" &&
nowtime.toString().substring(3,5) == "00" &&
nowtime.toString().substring(6,8) == "00") {
try{
sock = new Socket(_QComputer.get_IPAddress(),13);
in = sock.getInputStream();
quote = "";
Thread.sleep(700);
} catch (Exception e){
destroy();
}
try{
while (in.available() != 0) {
quote += (char) in.read();
}
int tire = quote.indexOf('-');
int dvoe = quote.indexOf(':');
quote = quote.substring(tire-2,dvoe+6);
int i = quote.indexOf(":");
times[0] = Integer.parseInt(quote.substring(i-2,i));
times[1] = Integer.parseInt(quote.substring(i+1,i+3));
times[2] = Integer.parseInt(quote.substring(i+4,i+6));
nowtime = new Time(times[0],times[1],times[2]);
} catch (Exception e) {}
} else nowtime.setTime(nowtime.getTime()+1000);
}
}
}
}
Technical Details
Message-ID: <3ecdcd80@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-08!supernews.com!news.tele.dk!news.tele.dk!small.news.tele.dk!colt.net!peernews3.colt.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 1089d0,265743128e00a629,start
X-Google-Attributes: gid1089d0,public
X-Google-ArrivalTime: 2003-05-23 00:39:40 PST
From: "Alex Tyutyunik" <alt7@dise.donbass.com>
Newsgroups: borland.public.jbuilder.java.api
Subject: Applet doesn't working in IE
Date: Fri, 23 May 2003 10:28:03 +0300
Lines: 129
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4522.1200
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200
NNTP-Posting-Host: 195.184.199.199
Message-ID: <3ecdcd80@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1053674880 195.184.199.199 (23 May 2003 00:28:00 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-08!supernews.com!news.tele.dk!news.tele.dk!small.news.tele.dk!colt.net!peernews3.colt.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail