Java Reference
In-Depth Information
private
JTextArea sourceArea;
// the button visual component
private
JButton button;
// the constructor assembles the visual components and
// sets up the event handling
public
TestFrame(){
super
("Html DOM Test Frame");
//Create a text area.
sourceArea
#
new
JTextArea(javaCode);
sourceArea.setFont(
new
Font("Courier", 0, 12));
sourceArea.setLineWrap(
false
);
JScrollPane areaScrollPane
#
new
JScrollPane
(sourceArea);
// create the HTML visualization pane
htmlPane
#
new
JEditorPane();
htmlPane.setEditable(
false
);
htmlPane.addHyperlinkListener(
this
);
JScrollPane editorScrollPane
#
new
JScrollPane
(htmlPane);
htmlPane.setContentType("text/html");
htmlPane.setText(htmlMessage);
// create the button
button
#
new
JButton("Analyze");
button.setActionCommand("Analyze");
button.addActionListener(
this
);
// define the frame layout
GridBagLayout gridbag
#
new
GridBagLayout();
GridBagConstraints c
#
new
GridBagConstraints();
Container frame
#
getContentPane();
frame.setLayout(gridbag);
// add components to frame
c.gridx
#
0;
c.gridy
#
0;
c.weightx
#
1;
c.weighty
#
1;
c.fill
#
GridBagConstraints.BOTH;
gridbag.setConstraints(areaScrollPane,c);
frame.add(areaScrollPane);
c.gridx
#
1;
gridbag.setConstraints(editorScrollPane,c);
frame.add(editorScrollPane);
c.gridx
#
0;
c.gridy
#
1;
c.fill
#
GridBagConstraints.NONE;
c.anchor
#
GridBagConstraints.CENTER;
c.gridwidth
#
2;