IM269 Coursework 3: DateApplet.java
// IM269 - Coursework 3: RMI Client/Server
// Semester A, 7th December 1998
// Eamonn Martin (BSc Computing)
// Student ID: 96/D59682
// efm001@unl.ac.uk
// RMI Hit Counter Client Applet (hits-log creation date)
package hitter;
import java.awt.*;
import java.rmi.*;
import java.text.DateFormat;
import hitter.HitCounter.Info;
public class DateApplet extends java.applet.Applet {
private Info info; // Hits-log info
// Get hits-log info from the HitCounter RMI server (no URL hit-count)
public void init() {
String name = "//" + getCodeBase().getHost() + "/HitCounter";
try {
HitCounter hitter = (HitCounter)Naming.lookup(name);
info = hitter.getInfo(null, getParameter("log"));
} catch (Exception e) {
info = null;
}
setBackground(Color.white);
setForeground(Color.black);
}
// Display the hits-log creation date
public void paint(Graphics g) {
String s = "??/??/??";
if (info!=null) { // RMI succeeded?
DateFormat d = DateFormat.getDateInstance(DateFormat.SHORT);
s = d.format(info.created); // Format log date
}
g.setFont(new Font("Monospaced", Font.PLAIN, 12));
g.drawString(s, 2, 1 + g.getFontMetrics().getMaxAscent());
}
}
Go To: IM269: Programming The Internet