I'm designing a Java project to simulate a proxy server with authentication that has a single interface, inside which multiple internal frames are arranged. How to position a browser within this JFrame
interface?
See the project template:
Andthecode:
\CódigodoBrowserpackageview;importjava.awt.*;importjava.awt.event.*;importjava.io.IOException;importjavax.swing.*;importjavax.swing.event.*;importjavax.swing.text.html.*;publicclassSwingHTMLBrowserextendsJFrameimplementsActionListener,HyperlinkListener{publicJTextFieldaddressBar;publicJEditorPanepane;SwingHTMLBrowser(){super("Swing HTML Browser");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
addressBar = new JTextField();
addressBar.addActionListener(this);
pane = new JEditorPane();
pane.setEditable(false);
pane.addHyperlinkListener(this);
add(addressBar, BorderLayout.NORTH);
add(new JScrollPane(pane));
setSize(new Dimension(400, 400));
}
public void actionPerformed(ActionEvent evt) {
String url = addressBar.getText();
try {
pane.setPage(url);
} catch (IOException t) {
t.printStackTrace();
}
}
@Override
public void hyperlinkUpdate(HyperlinkEvent evt) {
if (evt.getEventType() != HyperlinkEvent.EventType.ACTIVATED) {
return;
}
JEditorPane srcPane = (JEditorPane)evt.getSource();
if (evt instanceof HTMLFrameHyperlinkEvent) {
HTMLDocument doc = (HTMLDocument)pane.getDocument();
doc.processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent)evt);
} else {
String url = evt.getURL().toString();
addressBar.setText(url);
try {
pane.setPage(url);
} catch (Throwable t) {
t.printStackTrace();
}
}
}
public static void main(String args[]) {
SwingHTMLBrowser browser = new SwingHTMLBrowser();
browser.setVisible(true);
}
}