• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

How to link a button a card layout to another card (JPanel)

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I want  to link button on a card(JPanel) in a cardLayout to another card(JPanel) in the same Layout.
components
i Have 2 Panel class  = 1. welcome.class , snacks.class
and 1 jframe class =  kiosk.class

Already i can switch through view using the flowLayout but i want to link a button from one card to the other
Purpose
What i want to achieve is how to use a button on welcome panel and navigate to the snack panel within a cardLayout



This is what i tried
KIOSK CLASS(JFRAME CONTAINING VIEWS)



WELCOME.CLASS(JPANEL FORM)





The main connection is highlighted in dark red

What i was trying to do is to define a new kiosk in my welcome class and reference the switchPanel method which takes a parameter of (Container container, String plName)

but anytime i try to run i get this error

 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That code above doesn't seem to be the same as the code in the stack trace.
Line 27 in kiosk.java is a comment line, so can't have thrown the null pointer exception.
 
bernard kissi
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


the code stack error is on line 22



 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
container is null, then, which means that panelCard is null in Welcome.
Where do you think panelCard is initialised (it's hard to follow that generated code)?
 
bernard kissi
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


this is my panelCard in welcome.class (line 19)



line 39 in my kiosk. class (line 39)
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
panelCard in kiosk is not the same as panelCard in Welcome.

So initilaising a variable in kiosk is not going to have any effect on the one in Welcome.

So what exactly are you trying to do with this variable?
That might give us a pointer as to where it should live.
 
bernard kissi
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
panelCard is the parent holding my card views, so therefore before i can create a button link on a card to link to the other i have to access a parent through which i can access the child card. so i want access the panelCard object in Kiosk in my welcome.class
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK.
So Welcome is one panel of a CardLayout and kiosk (should be Kiosk) is another?

I would suggest a controller that sits above these two.
Neither of these classes should know that it is part of a CardLayout.  They should just have a reference to something that will handle an event that means the screen needs to change.

So, when the relevant button is pressed, this will inform the controller which will then handle the CardLayout changes.


Something like the above is the concept.
That way you detach the two screens.
 
bernard kissi
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kiosk is the main Jframe holding the JPanel Forms: welcome, drinks, snacks class respectively
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, that's the problem with using a GUI builder.
It makes the code almost impossible (for me at least) to follow.

So treat the Kiosk as the controller.
The rest still stands.
 
Once upon a time there were three bears. And they were visted by a golden haired tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic