File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

web browser JTextField problem

 
Jeff Yan
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What error do you get if you make it final? What does "i cannot do it" mean? Who cannot do what?
 
Jeff Yan
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the same URL work from your browser?
If yes, please post the stack trace
 
Jeff Yan
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you were using the browser, and it was ftp:// but you typed http:// what would you expect to happen?
 
Jeff Yan
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yea i get it now, i just dont know how to implement it properly!
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic