package CounterDemo;
import java.io.IOException;
import java.io.StringReader;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.html.*;
import java.awt.Color;
import java.util.*;
import java.text.*;
public class Screen {
private JEditorPane jep;
private JScrollPane jsp;
private JFrame frame;
private String text = "<font size=\"+1\">";
Screen(final String s, final int lx, final int uy, final int sx, final int sy) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI(s, lx, uy, sx, sy);
}
});
}
public void setText(final String s) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
text = s;
jep.setText("<font size=\"+1\">" + s);
}});
}
public void createAndShowGUI(String title, int lx, int uy, int sx, int sy) {
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);
//Create and set up the window.
frame = new JFrame(title);
frame.setBackground(Color.white);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Some text.
jep = new JEditorPane("text/html", text);
jep.setCaretPosition(0);
jep.setEditable(false);
jsp = new JScrollPane(jep);
jsp.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
frame.add(jsp);
// CSS stylesheet for this text
String styles = "a { text-decoration: none; }";
StyleSheet s = ((HTMLEditorKit)jep.getEditorKit()).getStyleSheet();
try {
s.loadRules(new StringReader(styles), null);
} catch (IOException e) { /* should never happen */ }
//Display the window.
frame.pack();
frame.setSize(sx, sy);
frame.setLocation(lx, uy);
frame.setVisible(true);
}
}
|