aspose file tools*
The moose likes Applets and the fly likes Clickable picture to another URL for an applet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Clickable picture to another URL for an applet?" Watch "Clickable picture to another URL for an applet?" New topic
Author

Clickable picture to another URL for an applet?

Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

Okay so I have a few questions about an applet I'm making.

First is is there a way to click on a picture in the applet which would bring us to another URL on the site? Basically this applet is going to give recommendations on the product, and I Think it would be a cool idea to click on the picture of another link that will be able to send me to the URL? Also I remember when I took a basic HTML class that when we made the applet it was using the class file? Can Jar's be used as well?


Thanks,

~JO
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41885
    
  63
Yes, you can use jar files in applet to bundle all the class files. That's what the archive attribute in the applet tag is for: http://docs.oracle.com/javase/tutorial/deployment/applet/html.html

You can certainly interpret any UI action (such as a click on an image) as a trigger to take the user to some other web site. That's what the java.applet.AppletContext#showDocument(java.net.URL) method is for.


Ping & DNS - my free Android networking tools app
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

Thanks! I notice they say with or without JNLP. How would I make a JNLP file? What are the advantages? I notice there is a log console that pops up whenever I run a .JNLP but is that all?

Thanks!



Now I could just create a new panel within the frame that could contain this URL according to this?

showDocument
void showDocument(URL url,
String target)
Requests that the browser or applet viewer show the Web page indicated by the url argument. The target argument indicates in which HTML frame the document is to be displayed. The target argument is interpreted as follows:
Target Argument Description
"_self" Show in the window and frame that contain the applet.
"_parent" Show in the applet's parent frame. If the applet's frame has no parent frame, acts the same as "_self".
"_top" Show in the top-level frame of the applet's window. If the applet's frame is the top-level frame, acts the same as "_self".
"_blank" Show in a new, unnamed top-level window.
name Show in the frame or window named name. If a target named name does not already exist, a new top-level window with the specified name is created, and the document is shown there.
An applet viewer or browser is free to ignore showDocument.

I think the best would be to bring us to the item while keeping us on the recommending page, I guess I could extend the applet size after clicking? Is that possible?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41885
    
  63
Now I could just create a new panel within the frame that could contain this URL according to this?

The web page would be displayed in the instead of the one containing the applet, or in a new browser window (depending on the value of the "target" parameter"). It's not displayed as part of the applet.

I think the best would be to bring us to the item while keeping us on the recommending page, I guess I could extend the applet size after clicking? Is that possible?

It's not possible to enlarge the applet, but you can open a new browser window via a "_blank" target parameter.
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

Ulf Dittmer wrote:
Now I could just create a new panel within the frame that could contain this URL according to this?

The web page would be displayed in the instead of the one containing the applet, or in a new browser window (depending on the value of the "target" parameter"). It's not displayed as part of the applet.

I think the best would be to bring us to the item while keeping us on the recommending page, I guess I could extend the applet size after clicking? Is that possible?

It's not possible to enlarge the applet, but you can open a new browser window via a "_blank" target parameter.



So basically when I activate it there is no way to have the web page open with the App?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41885
    
  63
I don't understand what you mean by "have the web page open with the App".
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61230
    
  66

Applets have many restrictions. At this point I'd question the need for an applet in the first place. Are there other things you need to do that only an applet can provide? Or are you just trying to avoid HTML and JavaScript?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

Bear Bibeault wrote:Applets have many restrictions. At this point I'd question the need for an applet in the first place. Are there other things you need to do that only an applet can provide? Or are you just trying to avoid HTML and JavaScript?


I'm doing a job for someone and this is what they wanted, HTML/Javascript would probably be better in this case since it's an easy task; however I think this is also a perfect opportunity to learn more about applets and such since I will need to make one for a future project once it's completed.


What I meant is, is there a way to open the link while still having the App open in the same window? A new window is probably going to be the easiest if not though.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41885
    
  63
The web page either opens in the same window -in which case the page containing the applet is displaced- or in a new window. There are no other alternatives.
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

Ulf Dittmer wrote:The web page either opens in the same window -in which case the page containing the applet is displaced- or in a new window. There are no other alternatives.


Gotcha thanks .

I did however see in JavaFX's Ensemble that it had a section that it would open up a page within the frame designated for each project, but I'm assuming that is different?


http://www.oracle.com/technetwork/java/javafx/samples/index.html
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41885
    
  63
You can embed a Swing web viewing component in your applet and load the web page into that. But the most common one (Swing's own JEditorPane) is horribly limited in the HTML it can display -HTML 3.2, no CSS, no JavaScript- which usually means that any recent web page will not display correctly.

But why would you use such an approach if you have a proper browser available that can display anything you throw at it? You shouldn't use applets for things they aren't meant for. (And, in fact, these days you should hardly use applets at all.)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61230
    
  66

Ulf is correct; displaying HTML in a frame in an applet in an HTML page is madness.

I ask again: why is an applet needed? Using applets in the modern Web at this point is sort of like trying to use a vacuum tube in a flat-screen TV.
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

HAah okay, was just curious how that was done, thanks. I will just open another window open. Also Bear like I said that's what he wants, I could do it in JS if needed. Like I said before I have another application that is going to be very complex that cannot be done in JS, so an applet will be needed for that. I rather learn what's needed now for that, even if Applets are a relatively dead path. Unless of course there is a better way to display my JAVA code in a webpage?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41885
    
  63
No
 
Consider Paul's rocket mass heater.
 
subject: Clickable picture to another URL for an applet?