473,803 Members | 1,992 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CardLayout Manager is giving some trouble

26 New Member
Hi.

I have been trying to fiddle around with some layout managers, the CardLayout in particular. The idea I had was : I must be able to accept multiple panels on one frame, i.e, i must have the first panel with a navigation button labeled "Next", and on clicking it, i am expected to see another panel on the frame.

In my sample code, i have three classes: CardLayoutSelf, Page0, Page1.

The design is intended to work as follows :

1. The class CardLayoutSelf contains a variable cards of type JPanel. Also, I have a void createAndShowGU I( ) method. This method is responsible for adding the JPanels representing pages 0 and 1 onto the CardLayout, and in turn, adding it to the JFrame.

2. Pages 0 and 1, represented by the classes Page0 and Page1 each contain navigation buttons, "Next" and "Back" which when clicked shall lead to the corresponding page relative to the present page. Each of these two classes implement ActionListener.

3. I have a method JPanel addComponentToP ane() in each of the classes Page0 a Page1, which return the JPanel of that particular page. This method is invoked in createAndShowGU I( ),

The panels are being loaded onto the frame's ContenPane successfully. This is the code for it in class Page0 :

Expand|Select|Wrap|Line Numbers
  1.    public void actionPerformed(ActionEvent e)
  2.     {
  3.         String next = " Next ";
  4.         String back = " Back ";
  5.  
  6.         CardLayoutSelf c = new CardLayoutSelf();
  7.         CardLayout cl = (CardLayout)(c.cards.getLayout());
  8.  
  9.         if(next.equalsIgnoreCase(e.getActionCommand()) )
  10.         {
  11.          cl.show(c.cards, "1");
  12.         }
  13.    }
My createAndShowGU I() definition is as follows:

Expand|Select|Wrap|Line Numbers
  1. void createAndShowGUI()
  2.     {
  3.         cards = new JPanel(new CardLayout());
  4.  
  5.         JFrame frame = new JFrame(" CardLayouts");
  6.         frame.setLocation(400,300);
  7.         frame.setSize(600,450); 
  8.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  9.  
  10.         //Create and set up the content pane.
  11.         Page0 p0 = new Page0();
  12.         cards.add("0", p0.addComponentToPane());
  13.  
  14.         Page1 p1 = new Page1();
  15.         cards.add("1", p1.addComponentToPane());
  16.  
  17.         frame.getContentPane().add (cards,BorderLayout.CENTER);
  18.  
  19.         //frame.pack();
  20.         frame.setVisible(true);
  21.  
  22.     }
The error I get, on clicking the "Next" button on Page 0 is :

Exception in thread "AWT-EventQueue-0" java.lang.NullP ointerException
at Page0.actionPer formed(CardLayo utSelf.java:140 )

Can anyone help me out? It seems to be a problem involving actionPerformed ( ), but i simply am not able to pin it down.
Jun 26 '09 #1
5 2340
r035198x
13,262 MVP
With time you will be able to read exception traces and pick up important information from them. The message you got is telling you the exact line number in your code where a problem is happening. the problem that is happening is that you trying to access a variable whose value is null.
Jun 26 '09 #2
p vs np
26 New Member
Yes.
I do realise the significance of the line number, and in my code, it corresponds to the statement:

Expand|Select|Wrap|Line Numbers
  1. CardLayout cl = (CardLayout)(c.cards.getLayout());
in the actionPerformed () method.

But I simply do not get as to why/how cl could be receiving a NULL value!?
Jun 26 '09 #3
r035198x
13,262 MVP
If (CardLayout)(c. cards.getLayout ()) throws a null pointer, then one of the objects being dereferenced on that line is null.
Candidates are c, c.cards and c.cards.getLayo ut().
Jun 26 '09 #4
p vs np
26 New Member
Silly me.
I had not made cards , the variable in class CardLayoutSelf static.

Thanks for the help :)
Jun 26 '09 #5
r035198x
13,262 MVP
I hope you are using How to use CardLayout as a reference while you are doing this.
Jun 26 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
4683
by: Richard Holliingsworth | last post by:
Hello: Thanks for reading this. I'm running A2002 as a front end to SQL Server 7.0. I've finished building my tables, views, forms and reports. Now I want to build the Switcboard form. But when I go to "Tools" - "Database Utilities" ----- the "Switchboard Manager" is grayed out. Any ideas why??? And how to turn it back on????
2
4330
by: Wayne | last post by:
I've just performed a reformat and reinstalled Access 2000 and 2003 and as usual the linked table manager in Access 2003 is broken ie. it doesn't show any tables. I've gone through the process of re-registering Accwiz.dll as outlined in the MS Knowledge Base and although this process has worked for me before, it hasn't worked this time. There are still no tables showing. The article in the knowledge base includes this line: "If the...
0
2938
by: news.microsoft.com | last post by:
Greetings, I am building a ASPX UI that will allow a HR representative manage the AD Organization. I have a class that wraps a lot of AD work and I do things like change password and update the GAL with Business information. I have been able to write the code to get list of Direct Reports for a given user, no problem. However, I am having trouble with how to set the 'manager' of a AD user. Is it a property or a invoke function? My...
0
1170
by: sonali_reddy123 | last post by:
Hi all, I am using a crownwood components docking manager in my application.I want to assign a tip to the Auto Hide and close buttons present for the docking manager. But the properties associated with a manager are not giving me any idea about how to do this.
4
5643
by: Joergen Bech | last post by:
Where, o where is my little "Solution Configurations" drop-down box? I then noticed that the Configuration Manager is absent from the Build menu. Dragging the item to the menu using "Customize" just gives me a disabled item. It is there in VS2003 Enterprise and VS2005 B2 Team System (as far as I remember). Is this feature not available in VS2005Pro? If so, what other
0
1439
by: James Conrad StJohn Foreman | last post by:
Does IBM publish a schema for the database that the DB2 task manager uses? Although we've got the task manager client installed on some windows machines, (a) most of our desktop machines are Apple Macs and therefore gloriously incompatible, and (b) I'd like some of my managers to be able to see the status of tasks without giving them access and training with the task manager. Thus, does anyone know of anything IBM have published to allow...
1
1734
by: arunkumar_m2001 | last post by:
Hi, I need help. I transferred my database from one server to another by using attach detach process.I created all the jobs which existed in the old server in the new server. Everything looked fine but a couple of jobs is a giving me some problems. When I try to edit the job step I could see that the database dropdown list doesn't contain the database name(which I transferred from the old server)
5
2197
by: NEWSGROUPS | last post by:
I have some users that continuously end task on my database when a search takes to long. In turn corrupting the application. Is there any way to prevent this? The Microsoft KB for Methods That Can Be Used to Prevent Corruption suggests not allowing Task Manager to shut down the application but gives no way to prevent this. Any suggestions would help. Thanks in advance, Mark
0
5578
by: narayan2586 | last post by:
Hi all, When ever i am trying to connect my application it's giving below error message: RemoteException occurred in server thread; nested exception is: java.rmi.RemoteException: ; nested exception is: javax.ejb.EJBException: Connection to pool failed! - com.ibm.websphere.ce.cm.StaleConnectionException: SQL1224N The database manager is not able to accept new requests, has terminated all requests in progress, or has terminated your...
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10542
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10309
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10068
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7600
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6840
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5496
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2968
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.