Is it possible to have a java program to show multiple browser?

N

Newbie

Is it possible to have a java program to show multiple browser on one
screen, you like a though security camera monitor screens?
 
J

John B. Matthews

Newbie said:
Is it possible to have a [J]ava program to show multiple browser
on one screen, as on a security camera monitor screen?


Yes, for example:

<code>
package test.my.gui;

import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.GridLayout;
import java.io.IOException;
import java.net.URL;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.text.Document;

/** @author John B. Matthews */
public class HtmlView extends JPanel implements HyperlinkListener {

private static final String EXAMPLE = "http://www.example.com";
private final JEditorPane jep;
private final Document doc;

public HtmlView(String url) {
this.setLayout(new GridLayout(1, 1));
jep = new JEditorPane();
jep.setEditable(false);
jep.addHyperlinkListener(this);
loadPage(jep, url);
doc = jep.getDocument();
JScrollPane sp = new JScrollPane(jep);
sp.setPreferredSize(new Dimension(800, 200));
sp.getVerticalScrollBar().setUnitIncrement(16);
this.add(sp);
}

private void loadPage(JEditorPane jep, String name) {
try {
jep.setPage(name);
} catch (IOException ioe) {
ioe.printStackTrace(System.err);
}
}

@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
HyperlinkEvent.EventType type = e.getEventType();
final URL url = e.getURL();
if (type == HyperlinkEvent.EventType.ENTERED) {
System.out.println("URL: " + url);
} else if (type == HyperlinkEvent.EventType.ACTIVATED) {
System.out.println("Following link...");
try {
jep.setPage(url);
} catch (IOException ioException) {
System.err.println("Invalid link");
jep.setDocument(doc);
}
}
}

public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(new GridLayout(3, 1));
f.add(new HtmlView(EXAMPLE));
f.add(new HtmlView(EXAMPLE));
f.add(new HtmlView(EXAMPLE));
f.pack();
f.setVisible(true);
}
});
}
}
</code>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top