Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

UnknownHostException in JEditorPane  RSS feed

 
Sanjeev Arora
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
In the program below where I try to simulate a browser, I get the following message in a new error window when I run my program: Can't build HTML pane for java.net.UnknownHostException:www.yahoo.com" TARGET=_blank rel="nofollow">http://www.yahoo.com/:java.net.UnknownHostException:www.yahoo.com
Further, when I click on the 'OK' button, I get a browser window but the pane does not display the contents of the URL. Can someone please help me?
The program is pasted below:
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
public class arora1 extends JFrame implements HyperlinkListener,
ActionListener {
public static void main(String[] args) {
if (args.length == 0)
new arora1("http://www.yahoo.com/");
else
new arora1(args[0]);
}
private JButton backButton, homeButton;
private JTextField urlField;
private JEditorPane htmlPane;
private String initialURL;
public anurag58(String initialURL) {
super("Arora Browser Version 1.0");
this.initialURL = initialURL;
// addWindowListener(new ExitListener());
// WindowUtilities.setNativeLookAndFeel();
JPanel topPanel = new JPanel();
topPanel.setBackground(Color.lightGray);
homeButton = new JButton("Home");
backButton = new JButton("Back");
homeButton.addActionListener(this);
JLabel urlLabel = new JLabel("URL:");
urlField = new JTextField(30);
urlField.setText(initialURL);
urlField.addActionListener(this);
topPanel.add(backButton);
topPanel.add(homeButton);
topPanel.add(urlLabel);
topPanel.add(urlField);
getContentPane().add(topPanel, BorderLayout.NORTH);
try {
htmlPane = new JEditorPane(initialURL);
htmlPane.setEditable(false);
htmlPane.addHyperlinkListener(this);
JScrollPane scrollPane = new JScrollPane(htmlPane);
getContentPane().add(scrollPane, BorderLayout.CENTER);
} catch(IOException ioe) {
warnUser("Can't build HTML pane for " + initialURL
+ ": " + ioe);
}
Dimension screenSize = getToolkit().getScreenSize();
int width = screenSize.width * 8 / 10;
int height = screenSize.height * 8 / 10;
setBounds(width/8, height/8, width, height);
setVisible(true);
}
public void actionPerformed(ActionEvent event) {
String url;
if (event.getSource() == urlField)
url = urlField.getText();
else // Clicked "home" button instead of entering URL
url = initialURL;
try {
htmlPane.setPage(new URL(url));
urlField.setText(url);
} catch(IOException ioe) {
warnUser("Can't follow link to " + url + ": " + ioe);
}
}
public void hyperlinkUpdate(HyperlinkEvent event) {
if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
try {
htmlPane.setPage(event.getURL());
urlField.setText(event.getURL().toExternalForm());
} catch(IOException ioe) {
warnUser("Can't follow link to "
+ event.getURL().toExternalForm() + ": " + ioe);
}
}
}
private void warnUser(String message) {
JOptionPane.showMessageDialog(this, message, "Error",
JOptionPane.ERROR_MESSAGE);
}
}
----------------------------------------------------------------
Thanks,
Sanjeev
 
Sanjeev Arora
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone please help me with my problem?
Thanks,
Sanjeev
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!