Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / April 2007

Tip: Looking for answers? Try searching our database.

java.net.ConnectException

Thread view: 
Srik - 25 Apr 2007 13:03 GMT
When i run the following code, i get -  java.net.ConnectException:
Connection refused

import java.net.URL;

import javax.swing.JDialog;
import javax.swing.JEditorPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLFrameHyperlinkEvent;

public class EditorPaneTest {

    EditorPaneTest()
    {
        JEditorPane edit = new JEditorPane();
        String str = "<html><body><A        href=http://
www.google.co.in>Googly</A></body></html>";
        edit.setContentType("text/html");
        edit.setText(str);
        edit.setEditable(false);
        edit.addHyperlinkListener(new Hyperactive());
        JDialog disalog = new JDialog();
        disalog.getContentPane().add(edit);
        disalog.show();
    }
    public static void main(String args[])
    {
        new EditorPaneTest();
    }
    class Hyperactive implements HyperlinkListener {

       public void hyperlinkUpdate(HyperlinkEvent e) {
           System.out.println("hyper link update");
             if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
{
             JEditorPane pane = (JEditorPane) e.getSource();
             if (e instanceof HTMLFrameHyperlinkEvent) {
                 HTMLFrameHyperlinkEvent  evt = (HTMLFrameHyperlinkEvent)e;
                 HTMLDocument doc = (HTMLDocument)pane.getDocument();
                 doc.processHTMLFrameHyperlinkEvent(evt);
             } else {
                 try {
                 pane.setPage(e.getURL().getHost());
                 } catch (Throwable t) {
                 t.printStackTrace();
                 }
             }
             }
         }
   }
}

I dont know if i have to configure anything or start any service. I am
running this from Eclipse in Linux platform. Can anyone please explain
what i need to do?
Andrew Thompson - 25 Apr 2007 14:34 GMT
>When i run the following code, i get -  java.net.ConnectException:
>Connection refused

Do you?  I get different results.  I get
java.net.MalformedURLException: no protocol: www.google.co.in

Which is largely due to this..

...
>        public void hyperlinkUpdate(HyperlinkEvent e) {
>            System.out.println("hyper link update");
...
>             } else {
>                 try {
>                 pane.setPage(e.getURL().getHost());

That line should be ..
    pane.setPage(e.getURL());

By the way.  Please..
- Don't include 'tab' characters in source posted to usenet.
- Always capitalise the word 'I'.

Another couple of points are that
 disalog.show();
..has been deprecated.  Try instead..
 disalog.setVisible(true);

You might try setting the JEditorPane into a JPanel
and calling setPreferredSize() on the JPanel, so the
GUI does not become compacted down to a title bar.

You should call pack() or validate() before setting the
GUI visible.

HTH

Signature

Andrew Thompson
http://www.athompson.info/andrew/

Andrew Thompson - 25 Apr 2007 14:36 GMT
...
>Another couple of points are that
...

Oh, and JEditorPane is entirely unsuited to displaying
web pages that are not directly controlled and carefully
optimised by you,  to account for the limitations of this
component.

Signature

Andrew Thompson
http://www.athompson.info/andrew/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.