import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;

public class HTMLButtonDemo {
    
    public static void main (String[] args) {
	// First Window: Shows a button and a label which use HTML
	// for fancier text.
	JFrame f = new JFrame("HTMLButton Demo");
	JButton button1 = new JButton("<html>Hi<br>This is a<br>multi-line button<p>Click to bring up the<p>help window.</html>");
	f.getContentPane().setLayout(new FlowLayout());
	f.getContentPane().add(button1);
	JLabel label1 = new JLabel("<html><h1><center><font color='red'>Labels</font></center></h1>support <font color='green'><b>HTML</b></font> too.</html>");
	f.getContentPane().add(label1);
	f.pack();
	f.setVisible(true);
	f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	// Second window: Reads in an html file, and displays it inside
	// a label inside a JScrollPane.  Notice that the HTML appears
	// very badly formatted.  This is because the JLabel class has
	// no concept of how long a line should be.  You probably
	// want to write your own formatting code to insert <p> markers
	// every 80 characters or so.  Future releases of Java should
	// have improved HTML support.
	final JFrame f2 = new JFrame ("Course project");
	String projectString = "";
	try {
	    BufferedReader in = new BufferedReader(new FileReader("project.html"));
	    String nextLine;
	    while ((nextLine = in.readLine()) != null) {
		projectString += nextLine + "\n";
	    }
	} catch (Exception e) {
	    projectString = e.toString();
	}
	JLabel projectLabel = new JLabel(projectString);
	JScrollPane scrollPane = new JScrollPane(projectLabel);
	f2.getContentPane().add(scrollPane);
	f2.setSize(640,480);

	button1.addActionListener( new ActionListener() {
		public void actionPerformed(ActionEvent e) {
		    f2.setVisible(true);
		}});
    } 
}
