Link to home
Start Free TrialLog in
Avatar of skel
skel

asked on

How can I test if an object is null? Painting an object? and background color of the applet.

I have the following while loop:

while( j < subopc[i].length ) {
        posy += size;
        subopc[i][j].pos( 20, posy );
        subopc[i][j++].paint( g );
}

The problem is that if subopc[i] = null, I have an exception error. I want to replace  the condition j < subopc[i].length by a way of testing if subopc[i] is null. In fact, some elements are null, so, in such cases, I don't want to enter that loop. How can I do that?

Another question.. I'm calling the paint method of subopc[][] object using subopc[i][j].paint( g ) called from the paint method of the main applet class. This works, but, is it correct? is this the only way to accomplish a painting of the object?

And the last question. I'm using setBackground method to paint the applet window background. Sometimes it works, and sometimes it doesn't. I'm using it in the paint method of the applet class. What's the problem?

Thanks in advance
Jaime
ASKER CERTIFIED SOLUTION
Avatar of jreagan
jreagan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of skel
skel

ASKER

Thanks a lot jreagan. I don't have your e-mail address.. so I place a follow-up here of the second question. How can I use the layout manager? I'm programming a menu. Walking step by step, I'm first using simply drawString to place the label of the option. I've created each option as an object that extends Panel. I'm using the following code in the init( ) method of the applet to initialize the objects:

numitems = Integer.parseInt( getParameter( "NumItems") );
// Create menu
opc = new Opcion[numitems];
subopc = new Opcion[numitems][ ];
// For each menu option, create the submenu
for( int i = 1; i <= numitems; i++ ) {
                  // Get the number of suboptions
                  n = Integer.parseInt( getParameter( "NumOpc " + i ) );
      // Create the suboptions
      if( n != 0 ) {
            subopc[i-1] = new Opcion[n];
      }
      // Get the URL which is to be called when the option is selected
      trg_url = getParameter( "URL" + i );
      // Get the label of the option
      label = getParameter( "Item " + i );
      // Call the constructor of the option
      opc[i-1] = new Opcion( font_name, font_color, over_color, target, size, trg_url, label );
      // Call constructors of suboptions
      for( int j = 1; j <= n; j++ ) {
            trg_url = getParameter( "URL" + i + " " + j );
            label = getParameter( "Sub" + i + " " + j );
            subopc[i-1][j-1] = new Opcion( font_name, font_color, over_color, target, size-2, trg_url, label );
      }
}

I want to control, therefore, when a user clicks on the option or moves the mouse over it. As I said, I'm actually putting only a text, but later, I want to place buttons or other way to show the options.

Can you help me in doing this? I think this is simple to do. I have the idea.. but I don't know how to implement it respecting JAVA sintax.

Thanks in advance,
Jaime