🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.api
1 messages
1 total messages Started by Alex Tyutyunik Fri, 23 May 2003 07:28
Applet doesn't working in IE
#614
Author: 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);
}
}
}
}
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads