Hi everybody,
Tryed to make this program: Simple browser: you type the URL at the top and then get a new window with this web page.
But my output is just JFrame(Even color did not get changed)
help me please to find the problem.
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
public class ReadServerFile extends JFrame{
private JTextField enterField;
private JEditorPane contentsArea;
public ReadServerFile() {
super("Simple Web Browser");
setSize(400,500);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocation(300,100);
setBackground(Color.WHITE);
enterField = new JTextField("Enter URL here");
enterField.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
getThePage(e.getActionCommand());
}
}
);
add(enterField, BorderLayout.NORTH);
contentsArea = new JEditorPane();
contentsArea.setEditable(false);
contentsArea.addHyperlinkListener(
new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent e) {
if(e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
getThePage(e.getURL().toString());
}
}
);
add(new JScrollPane(contentsArea), BorderLayout.CENTER);
}
public void getThePage(String location) {
try {
contentsArea.setPage(location);
enterField.setText(location);
}
catch(IOException e) {
JOptionPane.showMessageDialog(this, "Bad URL",
"Error with this URL", JOptionPane.ERROR_MESSAGE);
}
}
public static void main(String[] args) {
ReadServerFile application = new ReadServerFile();
}
}