aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes simple web browser in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "simple web browser in java" Watch "simple web browser in java" New topic
Author

simple web browser in java

harshada patil
Ranch Hand

Joined: Mar 12, 2011
Posts: 96
ya Image is located exactly as URI specifies...


at run time- it goes into the if loop..but the image on jButton3 disappears..now it is not getting image or i need to write something more??
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3649
    
  17

Yes. You need to post an SSCCE. Read the link to see what that means.

I can already tell you are writing spaghetti code that's going to have numerous bugs, but it will be helpful if you post a *small* program I can compile and run, that demonstrates the problem you have.
harshada patil
Ranch Hand

Joined: Mar 12, 2011
Posts: 96
@ulf

thanks for "pausing thread solution" it worked
harshada patil
Ranch Hand

Joined: Mar 12, 2011
Posts: 96
sample code for changing or setting image icon

Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3649
    
  17

Okay, I guess you'll have to use an actual URL instance, or a regular file string instead.

Either: "C:/.../splash.png"
or: new URL("file:///C:/.../splash.png");
harshada patil
Ranch Hand

Joined: Mar 12, 2011
Posts: 96
@Stephan
it is working with sample program posted above
but still not working in my project
harshada patil
Ranch Hand

Joined: Mar 12, 2011
Posts: 96
icon is getting changed but set page method is executed so fast..i'm not able to allow user for stopping thread (to stop loading web page) please see the following code on load page button(/ stop loading as in Google Chrome)


boolean parameter passed in set page method is used as follows: if set to true then thread is paused
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42945
    
  68
I don't want to sound too negative, but seriously : how often do you use the Stop button? Aren't there more useful features you could implement?
harshada patil
Ranch Hand

Joined: Mar 12, 2011
Posts: 96
i know yar.. i'm trying for other features too.. but what is wrong in trying things.. i know i can use separate control to stop loading web page or not providing control at all.. but this is the way I go..
harshada patil
Ranch Hand

Joined: Mar 12, 2011
Posts: 96
is it feasible to add cookies control in my browser?? what will be the actual functionality of cookies in browser..?
harshada patil
Ranch Hand

Joined: Mar 12, 2011
Posts: 96
is it possible to add menu bar from right end??
harshada patil
Ranch Hand

Joined: Mar 12, 2011
Posts: 96
??
harshada patil
Ranch Hand

Joined: Mar 12, 2011
Posts: 96
which control should i use to show web browser history?
i tried to use history as a menu and pages in history as menuItem in it but i am not getting how to dynamically insert or delete pages as a menuItem..
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19790
    
  20

JMenu has methods to add or insert JMenuItems.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
harshada patil
Ranch Hand

Joined: Mar 12, 2011
Posts: 96
okay.. and what security feature i can add in my browser?
harshada patil
Ranch Hand

Joined: Mar 12, 2011
Posts: 96
In my project i want to create menuItem at run time..
and for this i tried for following code


but now i want to add event handler to that menu item... how can i do that??
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19790
    
  20

When you create the JMenuItem add an appropriate event listener, or use a javax.swing.Action to create it.
harshada patil
Ranch Hand

Joined: Mar 12, 2011
Posts: 96
i'm not creating variable of jMenuItem so how can i add event handler to it?? please explain me
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

harshada patil wrote:i'm not creating variable of jMenuItem so how can i add event handler to it?? please explain me


You aren't assigning the instance of JMenuItem to a variable, so that means you have a problem adding an event handler to it. You can see that's a problem. What I don't understand is why you don't see the obvious solution to the problem.

Think about it. "If I don't do X then I can't do Y. But I have to do Y. So therefore I will..."
harshada patil
Ranch Hand

Joined: Mar 12, 2011
Posts: 96
Thanks for your reply Paul, at run time i want to add and remove menu item from menu, and i don't know the exact number of menu items i need to add or delete.. so how can i create variable (of menu item) at run time.. this is a problem for me.. Hope you are getting my point..
without creating variable i can create menu item as in my previous reply, but as i am not creating variable of menu item... i'm unable to write action listener for it
Petar Thomas
Ranch Hand

Joined: Oct 11, 2009
Posts: 234


..and then later...

Petar Thomas
Ranch Hand

Joined: Oct 11, 2009
Posts: 234
swoop : )))
harshada patil
Ranch Hand

Joined: Mar 12, 2011
Posts: 96
I'm creating history control.. In which I'm creating MenuItem at run time.. the following logic i have used to implement it, but action listener is not getting added
please help me with this


Petar Thomas
Ranch Hand

Joined: Oct 11, 2009
Posts: 234
Please , Click on this Link: http://sscce.org/
harshada patil
Ranch Hand

Joined: Mar 12, 2011
Posts: 96
Thanks for your help Peter.. From next time when i will post any question.. defiantly it will be a SSCCE code
harshada patil
Ranch Hand

Joined: Mar 12, 2011
Posts: 96
when i'm creating new menu item with every web page visited.. the menu items are getting inserted into menu history with recently visited page as a last element (at bottom) now i want to reverse the list, so that history can viewed as it can be seen in other Browsers
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4664
    
    5

I see. And have you read the API for JMenu to see whether it provides a method that allows you to do that?

luck, db
There are no new questions, but there may be new answers.
harshada patil
Ranch Hand

Joined: Mar 12, 2011
Posts: 96
I can't see anything like this in it..
Please point out if i'm wrong...
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4664
    
    5

Do you see a method that does this?
Adds the specified component to this container at the given position.
harshada patil
Ranch Hand

Joined: Mar 12, 2011
Posts: 96
I know this method but i'm not getting how should i use it so that items are inserted in bottom to top order??
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42945
    
  68
harshada patil wrote:I know this method but i'm not getting how should i use it so that items are inserted in bottom to top order??

If you could try something to figure this out, what would you try?
Petar Thomas
Ranch Hand

Joined: Oct 11, 2009
Posts: 234
Notice the difference between next two codes... When You understand what is going on, think about the next thing , for which I didn't gave code here, : History, it self, holds more than twenty entries. It is only twenty entries which are visible (in the menu). When You click on some ontry -viewport- changes , like the open window through which You see five floors of the next building across, allways, and if You look through the window from down - up - You see higher floors, and if You look down - from up - through the window - You see lower floors... This menu is similar, it is allways visible twenty entries (I haven't gave a code for that), but history can have much more entries... In the version of the second code shown here, JMenu is used as a container for holding history entries, but if the real history must hold much more entries, then ArrayList can hold all the history entries, while the JMenu shows only the twenty (and when You click, it's allways ten down and ten up from clicked, so You can "move" the view port)
One more time. First code sample shows not reversed menu order, it is also here to make it easier to understand how and what I have written in the second sample code. Second sample code shows reversed menu order. After You understand what did I wanted to say with this two code samples, think about how the real history really works, You can't hold the whole history in the JMenu, only the part of it, the visible part, the whole history has to be saved somewhere else, perhaps in the ArrayList, so then, You would have two history lists - one visible with twenty entries max - and one real which hold how ever much entries , from the second one are twenty taken. Then, notice this: You will have two current indexes of current page..... Look. If You have an ArrayList which has at the momen around hundart entries in it self, and a current page is, let's say, 57th page from the history, then - in the JMenu You would show entries from 47 till 67 , twenty of them... and from the list of twenty JMenuItems in history JMenu... tenth JMenuItem (that's one index) whould be the actuall 57th history item (2nd index).
One more practical thing... So, for example, when You click on the 'history' menu, then the menu pops down. It shows twenty history item, and current page is made in bold font, from the list. Then - when You click on the other page - menu closes - other page loads ........ when again the history JMenu is opened, again menu pops down, but now showing twenty history elements around the last page which was chosen (it was like moving the view port ). So... that's the 'current page' ... Now, what You can make is calculate and populate JMenu with JMenuItems - at the moment when the JMenu was clicked at with a mouse... So, it could be like that... You click. Instead of opening, first the listener is called, and in the listener there is a code for populating JMenu with fresh twenty JMenuItems those "around" the current page, ten up , and ten down..(for example)
JMenu has a method +addMenuListener(MenuListener ) ... You can make a class implement MenuListener interface. MenuListener interface has three methods, menuCanceled(...) , menuDeselected(...) and menuSelected(...). So, if You write Your own class which would implement those three methods, and.. You add that class as a MenuListener to a JMenu ('history) menu object ... every time someone clicks 'history' menu, before displaying the menu, the method menuSelected(...) from Your class would be called...and from withinside that method You can populate history JMenu with 20 entries a moment before the menu gets displayed on the screen... (for exapmle, You could copy twenty entries from an ArrayList where is "the whole" history list.... into the 20 JMenuItems which then You could attach to a JMenu 'history' menu.... just before the menu get's displayed... (and don't forget to add listeners to 20 JMenuItems )....
And when You finish with thinking about all that, think about one more thing... So, imagine, You have a history list that works just fine. When You type the address, page loads, and history list gets filled with typed address.... Duplicates are allowable in my browser. So - I - can have, in my browser, case in my history: yahoo, msn, yahoo, msn, yahoo, msn... etc.
The other thing is this: So, then You open 'history' menu, the thing pops down. You choose a page down from the list, a page somewhere from the past. So, current page becomes some page from the past. What is happening with pages betwen the past and the newest page? While You are just clicking around, the (real) 'history' list doesn't change, but, while You are browsing some old, past, page.... if -then- You enter a page address.... all pages from the old, past page, till the newest page, are losted and deleted, in other words, if You "go in the past", select some page, all pages from that page till the new page - the whole range - get's erased .. if You choose to enter page address, if You type in.... becaouse , when You type in, that page becomes the newest page, and what was the last page, page before the newest page? ( ...


1)




2)





]And extra.......
3)



4) You will have to think a little bit caouse 3) and 4) are just a small part of the working code which is not here, it shows some ideas.. "You just have to connect the dot's"



You can also listen the song that I was accedentally listening while I was writing this..
http://www.youtube.com/watch?v=g3R3IqRZtHw
Goldfrapp-It's Not Over Yet(Grace & Klaxons Cover)
Petar Thomas
Ranch Hand

Joined: Oct 11, 2009
Posts: 234

...

This up is what gets called when JMenuItem is clicked. What I did here is the way how things shouldn't be done. When I have created JMenuItems in code sample 3), I've setted an ActionCommand (in a +menuSelected(...) )

, and here , in an +actionPerformed(...) I am parsing that string , hisotry menu + i .... to see what was that i that I added to the back of the actionCommand string... becaouse by this I can tell which JMenuItem was which. (in actionPerformed)...
Also, 'controller' was something that I was playing with.. but , in my code that I made, the line

serves to start loading a web page.. (in my code).. but, (in my code)... indexOfSelectedItem is actually the number from JMenuItem, for example 10, or 15, which menu item was clicked..
My History class has this method, which calculates from indexOfSelectedItem into a historyIndex..

Then I would call +get(index):String on the same History class, which would return me a address.. Then I would load that page... but I wouldn't forget then to call after that +setSelected(index) on History class object, for the purpouse of memorizing the current page...


+checkIn(String address): int , of History class, in my code:

Is called WHEN the new address is entered into a JTextField, (and when action is perforemed on that JTextField - then I send that String, address, into a checkIn )...after I load..

Method checkIn checks if the current loaded page is first on the top of the history (not JMenuItems, the real history)... if it is on top... it just inserts new address in the histry ArrayList

but, if the curently selected history entry is not the top one, but some in the middle, from the past, then piece of the history gets erased...



Anyway, this is playfield for making errors. If I accedentally wrongly reinterpreted my code to You, then I have introduced errors.. In another words... Maybe I missed a thing, or I changed the order of happenings...
harshada patil
Ranch Hand

Joined: Mar 12, 2011
Posts: 96
Please tell me how i can use the BlackListCookiePolicyExample as given in the link in my Browser..

http://download.oracle.com/javase/tutorial/networking/cookies/custom.html

I never used cookie before... So Please tell me
harshada patil
Ranch Hand

Joined: Mar 12, 2011
Posts: 96
Please help me with cookies...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: simple web browser in java