This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Applets and the fly likes linking between applet pages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "linking between applet pages" Watch "linking between applet pages" New topic
Author

linking between applet pages

nasha shaharan
Greenhorn

Joined: Jun 01, 2011
Posts: 22
hi guys,
i have an applet with many buttons. i wanna be able to press a button and directs it to another page.
it is kinda like clicking a link in a webpage. i am not sure how to do this. can you please tell me how?

this is what i did in the button's actionPerformed:



thanks in advance!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41015
    
  43
Assuming that by "page" you mean another web page, that's what the Applet class's showDocument method does.


Ping & DNS - my free Android networking tools app
nasha shaharan
Greenhorn

Joined: Jun 01, 2011
Posts: 22
no..not a webpage. it's an applet also.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41015
    
  43
Is the applet on the same web page? Then it should be visible already. If It's on a different web page, then showDocument is the way to go.
nasha shaharan
Greenhorn

Joined: Jun 01, 2011
Posts: 22
same web page..how can it be visible? i need to click a button, say: View Profile. then it will take me to another applet called Profile.
just like a website. can you tell me more?
Andrew Thompson
Ranch Hand

Joined: Aug 05, 2010
Posts: 77
    
    5
I suspect the best approach to this is to convert Hello class to a JPanel and add it and the other GUI elements to a CardLayout. Here is a short example.



Andrew Thompson
http://pscode.org/
nasha shaharan
Greenhorn

Joined: Jun 01, 2011
Posts: 22
thanks for the example, Andrew! i will look into it and study more about cardlayout.
i'm wondering why i can't link to other applet in the same page, when my login page can do that whenever i hit the login button. when i log in successfully, the page changes to the content page.

this is my login page code:



and this is the code for the other applet when 'enter' button is pressed:


please help because i'm confused...



Andrew Thompson
Ranch Hand

Joined: Aug 05, 2010
Posts: 77
    
    5
nasha shaharan wrote:..i'm wondering why i can't link to other applet in the same page, ...


Probably because that makes about as much sense as "Why can't I banana card hat manifesto?".

Or to put that another way, I don't have the 1st idea about what your 'requirement' is supposed to mean. Links are either to other pages, other resources like images or ZIP archives, or anchors in the same page. There is no such thing as a 'link to an applet'.

Can you give us the URL of a web page that behaves as your applets are supposed to work?
nasha shaharan
Greenhorn

Joined: Jun 01, 2011
Posts: 22

It's like a website with a login page. after login, press the enter button and the applet called ButtonView takes the place of the login applet.
then in the ButtonView applet will have 3 buttons which do different things and they will open other applets as well.

the login to buttonView successfully linked, but the buttons in buttonView cannot open their respective applets.

just take a look at my code...

i don't want to use showDocuments because it will use different web pages. i only want one webpage, but the applets in one place, responding to whatever button being pressed.
or is this not possible? an applet contents cannot be changed? but in login page it was successful...maybe the panel from buttonView that was called?

sorry because i don't know a lot about applets..thanks for your help
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41015
    
  43
CardLayout is definitely the way to go.
nasha shaharan
Greenhorn

Joined: Jun 01, 2011
Posts: 22
oh CardLayout..can cardlayout contain applets in various sizes?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41015
    
  43
Being a layout, CardLayout does not contain applets but Panels or JPanels. You'll have to rewrite your code so that it is a single applet. And no, all panels in a CardLayout are of the same size. But that shouldn't be a problem.
nasha shaharan
Greenhorn

Joined: Jun 01, 2011
Posts: 22
thanks for explaining..so, the panels will be in the same size of the applet? the panels will be on top of each other then?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41015
    
  43
That would be a conceptualisation. The important point is that a single panel will be visible at any given time.
nasha shaharan
Greenhorn

Joined: Jun 01, 2011
Posts: 22
okay thanks! i'll go and learn more about cardlayout.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41015
    
  43
http://download.oracle.com/javase/tutorial/uiswing/layout/card.html
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: linking between applet pages
 
Similar Threads
Grid Layout
gridbaylayout constraints
Image is not getting displayed
Passing objects between a servlet and an applet
How do I add a ButtonGroup in an applet?