File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes web browser JTextField problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "web browser JTextField problem" Watch "web browser JTextField problem" New topic
Author

web browser JTextField problem

Jeff Yan
Ranch Hand

Joined: Nov 05, 2009
Posts: 42
hey, basically i am programming a java web browser using the JEditorPane.
i have a problem with the URL bar, it doesnt read the text that is entered into it to load the new webpage, and i do not know what i am doing wrong!

this is the code for this part of the programme



it comes up with the error about URLBox needing to be final to use it in the inner class, however if it is final will it not change values?? and when i do make it final it says i cannot do it! it is really annoying! any help appreciated


~ Jeff Yan ~
Jeff Yan
Ranch Hand

Joined: Nov 05, 2009
Posts: 42
also, can you make all of this type of program in the constructor? i have not seen the need for any method yet? you create an object of the program and it all works inside the frame from there!?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10248
    
    8

What error do you get if you make it final? What does "i cannot do it" mean? Who cannot do what?


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Jeff Yan
Ranch Hand

Joined: Nov 05, 2009
Posts: 42
i i got the final thing to work now it is just, the text i input into the box doesnt go to the URL that was typed in to the text box! it throws an IOException



it throws the catch(IOException ioe) {JOptionPane.showMessageDialog(null, "URL Unavalible", "alert", JOptionPane.ERROR_MESSAGE); } everytime with EVERY URL entered! which it really shouldnt! any ideas?? the bit that is works fine in other bits of the code, it is just in the URL text box bit which is shown above! it works for the home button i created and used the same bit of code above but the only difference being this:
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10248
    
    8

Does the same URL work from your browser?
If yes, please post the stack trace
Jeff Yan
Ranch Hand

Joined: Nov 05, 2009
Posts: 42
yea the website works in my browser, here is the stack trace:

java.net.MalformedURLException: no protocol: www.ncl.ac.uk
at java.net.URL.<init>(URL.java:567)
at java.net.URL.<init>(URL.java:464)
at java.net.URL.<init>(URL.java:413)
at javax.swing.JEditorPane.setPage(JEditorPane.java:920)
at WebBrowser$6.actionPerformed(WebBrowser.java:106)
at javax.swing.JTextField.fireActionPerformed(JTextField.java:492)
at javax.swing.JTextField.postActionEvent(JTextField.java:705)
at javax.swing.JTextField$NotifyAction.actionPerformed(JTextField.java:820)
at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1633)
at javax.swing.JComponent.processKeyBinding(JComponent.java:2839)
at javax.swing.JComponent.processKeyBindings(JComponent.java:2874)
at javax.swing.JComponent.processKeyEvent(JComponent.java:2802)
at java.awt.Component.processEvent(Component.java:6040)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1850)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:712)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:990)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:855)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:676)
at java.awt.Component.dispatchEventImpl(Component.java:4502)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Jeff Yan
Ranch Hand

Joined: Nov 05, 2009
Posts: 42
ohhh, you have to put http:// infront of every website you enter! do you know how you would go about getting it to recognise the http protocol even if the user enters say www.google.com, or just google.com? because it is kind of frustrating having to type http:// every time.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10248
    
    8


In your code, where you set the page, you can check if the URL starts with http:// else you can add it yourself.
Jeff Yan
Ranch Hand

Joined: Nov 05, 2009
Posts: 42
but what if it is say https://, or ftp:// etc. you get the idea! isnt there some kind of importable method that can obtain the protocol for you and add it??!!
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10248
    
    8

If you were using the browser, and it was ftp:// but you typed http:// what would you expect to happen?
Jeff Yan
Ranch Hand

Joined: Nov 05, 2009
Posts: 42
and how do you do that exactly, ive got this so far:

but it doesnt seem to work! compiler error - incomparable types char and java.lang.String
Jeff Yan
Ranch Hand

Joined: Nov 05, 2009
Posts: 42
yea i get it now, i just dont know how to implement it properly!
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10248
    
    8

Why are you converting it to a char array? You do not really require it.
Check out the String API for methods which will let you change case and methods which will tell you if a given string starts with a specific prefix.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: web browser JTextField problem