Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

AWT CardLayout Confusion

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made a class as shown to play around with CardLayout

This compiles fine but results in a runtime error:

My problem is, i don't know which add(String, Component) method compiler is referring to. It's not part of the container (I tried Frame vs Panel) nor is it part of the layoutmanager...
 
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when u add components to a container with a cardLayout u need to add them like this:
the name of the component, string to describe it.
exactly like the add u have in comments.
the exception is for the add(b) with no string describing it.
add(Component,String) is the right way for cardLayout.
the reason u need the string is that u can later switch to that card using the name u gave it.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic