How do I add HTML5 functionality to my browser?
Its still a work in progress, so ignore the event handlers and buttons that seem pointless...
package browser;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class ReadPage extends JFrame {
private JTextField address;
private JEditorPane display;
private JButton refresh;
private JButton go;
private JPanel pnlSearch;
private String homepage;
public void setHome(String home){
homepage = home;
}
public ReadPage() throws HeadlessException {
super("Venster Browser");
setSize(600, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
FlowLayout flo = new FlowLayout();
go = new JButton("-->");
go.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
loadCrap(address.getText());
}
});
go.setSize(20, 35);
Icon icon = new Icon() {
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
g.drawOval(x, y, y, y);
}
@Override
public int getIconWidth() {
return 10;
}
@Override
public int getIconHeight() {
return 10;
}
};
refresh = new JButton(icon);
refresh.setSize(20, 35);
address = new JTextField("www.google.com", 35);
address.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
loadCrap(e.getActionCommand());
}
});
pnlSearch = new JPanel();
pnlSearch.setLayout(flo);
pnlSearch.add(go);
pnlSearch.add(refresh);
pnlSearch.add(address);
pnlSearch.setSize(JFrame.WIDTH, 50);
add(pnlSearch, BorderLayout.NORTH);
display = new JEditorPane();
display.setEditable(false);
display.addHyperlinkListener(new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
if(e.getEventType() == HyperlinkEvent.EventType.ACTIVATED){
loadCrap(e.getURL().toString());
}
}
});
add(new JScrollPane(display), BorderLayout.CENTER);
address.requestFocusInWindow();
setVisible(true);
getRootPane().setDefaultButton(go);
ReadPage.super.addWindowListener(new WindowListener() {
@Override
public void windowOpened(WindowEvent e) {
}
@Override
public void windowClosing(WindowEvent e) {
}
@Override
public void windowClosed(WindowEvent e) {
}
@Override
public void windowIconified(WindowEvent e) {
}
@Override
public void windowDeiconified(WindowEvent e) {
}
@Override
public void windowActivated(WindowEvent e) {
try{
display.setPage(homepage);
}catch(Exception ex){
ex.printStackTrace();
display.setText("Couldn't connect to the internet...");
}
}
@Override
public void windowDeactivated(WindowEvent e) {
}
});
}
private void loadCrap(String userText){
try{
//String newText = "http://" + userText;
//display.setPage(newText);
display.setPage(userText);
address.setText(userText);
}catch(Exception e){
System.out.println("Crap!");
display.setText("Could not connect to the internet...");
e.printStackTrace();
}
}
}