Java Reference
In-Depth Information
c.weighty
#
0;
gridbag.setConstraints(button,c);
frame.add(button);
pack();
this
.setSize(800,600);
// add listener for window closing event
addWindowListener(
new
WindowAdapter() {
public void
windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
// Event handler for the button.
// It creates the documentation for the source code
// contained in the text area and puts the result into
// the HTML panel.
public void actionPerformed(ActionEvent e){
Parser parser
#
new JavaLanguage();
Documenter printer
#
new SimpleDocumenter
("cyan","navy","green");
parser.addObserver(printer);
parser.parse(sourceArea.getText());
Element page
#
printer.getResult();
ByteArrayOutputStream buffer
#
new ByteArrayOutputStream();
page.serialize(new PrintStream(buffer));
htmlPane.setText(buffer.toString());
}
// event handler for hyperlinks activation in the HTML
// panel
public void
hyperlinkUpdate(HyperlinkEvent e) {
if
(e.getEventType()
##
HyperlinkEvent.EventType.ACTIVATED) {
JEditorPane pane
#
(JEditorPane) e.getSource();
try
{
pane.setPage(e.getURL());
}
catch
(Throwable t) { t.printStackTrace(); }
}
}
// main program for the application:
// it just creates the window.
public static void
main(String [] args){
TestFrame frame
#
new
TestFrame();
frame.setVisible(
true
);
}
}