Solved

LayoutManager Blues...

Posted on 1998-08-24
40
257 Views
Last Modified: 2010-03-30
I am trying to set up a catalog and want images of the five items on the left, a description of the items in the center and then TextFields for QTY of items ordered.  I can not seem to get it to work properly (I am not even trying to get the TextFields working at this point - just the images and labels) I either get the images and no labels or labels and no images - below is my code what am I doing wrong??

import java.awt.*;
import java.lang.*;
import java.awt.event.*;
import java.applet.Applet;


public class Catalog extends Applet {
// Load the image off the document base...
            Image img, img1, img2, img3, img4;
            Button view, add, order, print;
            Panel cart, itemOne, itemTwo, itemThree, itemFour, itemFive;
            Label itemOneLabel, itemTwoLabel, itemThreeLabel;
            Label itemFourLabel, itemFiveLabel;
            Label itemOneLabel1, itemTwoLabel1, itemThreeLabel1;
            Label itemFourLabel1, itemFiveLabel1;
            //TextField itemOneTextField, itemTwoTextField, itemThreeTextField;
            //TextField itemFourTextField, itemFiveTextField;

public void init() {
          img = getImage(getDocumentBase(),"spiral.gif");
          img1 = getImage(getDocumentBase(),"ledger.gif");
          img2 = getImage(getDocumentBase(),"pen.gif");
          img3 = getImage(getDocumentBase(),"pencil.gif");
          img4 = getImage(getDocumentBase(),"paperclip.gif");

      itemOneLabel = new Label( "Writing Pads - 8 1/2 x 11, 50 sheets/pad, college ruled, ");
      itemOneLabel1 = new Label( "bound at the top, Product stock number: 11, Cost: $1.00 ");
      itemTwoLabel = new Label( "Accounting Ledger - 8 1/2 x 11, 50 sheets/ledger, 7 column, ");
      itemTwoLabel1 = new Label( "bound, Product stock number: 12, Cost: $3.00");
      itemThreeLabel = new Label( "Ball Point Pens - Blue ink, Retractable point, 5 pens per ");
      itemThreeLabel1 = new Label( "package, Product stock number: 21, Cost: $2.50 ");
      itemFourLabel = new Label( "Pencils - No 2 lead, 12 pencils/package, Product ");
      itemFourLabel1 = new Label( "stock number: 22, Cost: $1.25 ");
      itemFiveLabel = new Label( "Paper Clips - Metal, 100 per box, 5 boxes per package, ");
      itemFiveLabel1 = new Label( "Product stock number: 31, Cost: $2.50 ");            
      

      // easy to make lower button panel
      this.setLayout( new BorderLayout() );  
      Panel p = new Panel();
      this.add( "Center", p );

      // one item across, four different products
      p.setLayout( new GridLayout( 1, 10 ) );

      Panel itemOne = new Panel();
      itemOne.setLayout( new FlowLayout( FlowLayout.RIGHT ) );
      itemOne.add( itemOneLabel );
      itemOne.add( itemOneLabel1 );
      //itemOne.add( itemOneTextField );
      p.add( itemOne );

      Panel itemTwo = new Panel();
      itemTwo.setLayout( new FlowLayout( FlowLayout.RIGHT ) );
      add( itemTwoLabel );
      add( itemTwoLabel1 );
      //itemOne.add( itemTwoTextField );
      p.add( itemTwo );

      Panel itemThree = new Panel();
      itemThree.setLayout( new FlowLayout( FlowLayout.RIGHT ) );
      add( itemThreeLabel );
      add( itemThreeLabel1 );
      //itemOne.add( itemThreeTextField );
      p.add( itemThree );

      Panel itemFour = new Panel();
      itemFour.setLayout( new FlowLayout( FlowLayout.RIGHT ) );
      add( itemFourLabel );
      add( itemFourLabel1 );
      //itemOne.add( itemFourTextField );
      p.add( itemFour );

      Panel itemFive = new Panel();
      itemFive.setLayout( new FlowLayout( FlowLayout.RIGHT ) );
      add( itemFiveLabel );
      add( itemFiveLabel1 );
      //itemOne.add( itemFiveTextField );
      p.add( itemFive );


                  //Add the buttons for shopping cart control

                  cart = new Panel( );
                  cart.setLayout( new GridLayout( 1, 4 ) );
                  add( add = new Button( "Add to Shopping Cart" ) );
                  add( view = new Button( "View Shopping Cart" ) );
                  add( order = new Button( "Place an Order" ) );
                  add( print = new Button( "View your Order" ) );
                  //add.addActionListener( this );
                  //view.addActionListener( this );
                  //order.addActionListener( this );
                  //print.addActionListener( this );

                  add( "South", cart );

  }

// Paint the image
public void paint(Graphics g) {
        g.drawImage( img, 5, 5, 100, 75, this );
        g.drawImage( img1, 5, 95, 100, 75, this );
        g.drawImage( img2, 5, 185, 100, 75, this );
        g.drawImage( img3, 5, 275, 100, 75, this );
        g.drawImage( img4, 5, 365, 100, 75, this );
   }

}

Any ideas or pointers??
0
Comment
Question by:mapper
  • 22
  • 10
  • 6
  • +2
40 Comments
 
LVL 8

Expert Comment

by:diakov
ID: 1222477
I will answer tomorrow. I go to sleep. From first glance you do not load the images correctly. This method always returns immediately, whether or not the image exists. When this applet attempts to draw the image on the screen, the data will be loaded. The graphics primitives that draw the image will incrementally paint on the screen. Also, you try to paint at absolute coordinates. The layout managers are the ones that decide the onscreen appearance. Better derive a ImagePannel, which loads an image or with already loaded image, sets it's preferred size, and then you add it to the layouts.
this is for now, I go to sleep. Success.



0
 

Author Comment

by:mapper
ID: 1222478
diakov,

I will try and implent the image panel - but I am new and don't know how to use images with out the graphics way...

thanks though,

mapper
0
 
LVL 2

Expert Comment

by:aziz061097
ID: 1222479
I would suggest you to use some GUI development tool like Visual Cafe. Why would you want to spend time in laying out things when you have enough work on implementing the logic ? Even if you do not want to use Visual Cafe as your IDE you can atleast create your panels and take that code in your program. Another suggestion is that keep the code for each panel in a different program file (class extending panel) that makes your UI objects independent for manipulation.
0
 
LVL 5

Expert Comment

by:msmolyak
ID: 1222480
You have two panels in your applet: one in the center and on at the bottom The bottom panel is give its preferred height (and it stretches accross the entire bottom part of the applet). The rest of the space is taken by the center panel. Thus, I am not sure where the images are supposed to be drawn. What I would do is to create a separate Panel (imagePanel) and place it at "West" position.

Panel imagePanel = new Panel()
{
  public void paint(Graphics g)
  {
     // Draw the images
  }
}
add(imagePanel, West");

Also, if you want your buttons to have preferred sizes, create another panel with FlowLayout (flowPanel) and add the cart to it.

    Panel flowPanel = new Panel();
    cart = new Panel( );
    cart.setLayout( new GridLayout( 1, 4 ) );
    add( add = new Button( "Add to Shopping Cart" ) );
    add( view = new Button( "View Shopping Cart" ) );
    add( order = new Button( "Place an Order" ) );
    add( print = new Button( "View your Order" ) );
    flowPanel.add(cart)
    add( "South", flowPanel );
0
 

Author Comment

by:mapper
ID: 1222481
aziz,

Thanks, but I am taking a class where the Prof. insists that you do things (from what other Java types think is not too correct!) his way - he likes you to setLayout (null); and setbounds to arrange things in the applet - the problem is that the browser doesn't support setbounds - you have to use reshape and that is deprecated so - it is crap code (in my mind) - the problem that I am experiencing is that I am taking this class out side of the classroom (distance learning) and it is hard to get the Prof. to help you.  So I have to stumble along a lot slower than normal and I am running out of time - the visual tool would be cool but I have very limited funds - so unless it is free or 30 day trial - I am hosed on that one too!!

mapper
0
 
LVL 3

Expert Comment

by:mjenkins
ID: 1222482
Here is what you were trying to do:

   import java.awt.image.ImageObserver;
   import java.awt.*;
   import java.lang.*;
   import java.awt.event.*;
   import java.applet.Applet;
 
 
   public class Catalog extends Applet {
   // Load the image off the document base...
   Image img, img1, img2, img3, img4;
   Button view, add, order, print;
   Panel cart, itemOne, itemTwo, itemThree, itemFour, itemFive;
   Label itemOneLabel, itemTwoLabel, itemThreeLabel;
   Label itemFourLabel, itemFiveLabel;
   Label itemOneLabel1, itemTwoLabel1, itemThreeLabel1;
   Label itemFourLabel1, itemFiveLabel1;
   //TextField itemOneTextField, itemTwoTextField, itemThreeTextField;
   //TextField itemFourTextField, itemFiveTextField;
 
public void init()
{
   img = getImage(getDocumentBase(),"spiral.gif");
   img1 = getImage(getDocumentBase(),"ledger.gif");
   img2 = getImage(getDocumentBase(),"pen.gif");
   img3 = getImage(getDocumentBase(),"pencil.gif");
   img4 = getImage(getDocumentBase(),"paperclip.gif");
 
   itemOneLabel = new Label( "Writing Pads - 8 1/2 x 11, 50 sheets/pad, college ruled, ");
   itemOneLabel1 = new Label( "bound at the top, Product stock number: 11, Cost: $1.00 ");
   itemTwoLabel = new Label( "Accounting Ledger - 8 1/2 x 11, 50 sheets/ledger, 7 column, ");
   itemTwoLabel1 = new Label( "bound, Product stock number: 12, Cost: $3.00");
   itemThreeLabel = new Label( "Ball Point Pens - Blue ink, Retractable point, 5 pens per ");
   itemThreeLabel1 = new Label( "package, Product stock number: 21, Cost: $2.50 ");
   itemFourLabel = new Label( "Pencils - No 2 lead, 12 pencils/package, Product ");
   itemFourLabel1 = new Label( "stock number: 22, Cost: $1.25 ");
   itemFiveLabel = new Label( "Paper Clips - Metal, 100 per box, 5 boxes per package, ");
   itemFiveLabel1 = new Label( "Product stock number: 31, Cost: $2.50 ");
 
   // easy to make lower button panel
   this.setLayout( new BorderLayout() );
   Panel p = new Panel();
   this.add( "Center", p );
 
   // one item across, four different products
   p.setLayout( new GridLayout( 5, 3 ) );
 
   p.add( new ImageCanvas( img, this ) );
   Panel itemOne = new Panel();
   itemOne.setLayout( new FlowLayout( FlowLayout.RIGHT ) );
   itemOne.add( itemOneLabel );
   itemOne.add( itemOneLabel1 );
   p.add( itemOne );
   p.add( new TextField("0") );
 
   p.add( new ImageCanvas( img1, this ) );
   Panel itemTwo = new Panel();
   itemTwo.setLayout( new FlowLayout( FlowLayout.RIGHT ) );
   itemTwo.add( itemTwoLabel );
   itemTwo.add( itemTwoLabel1 );
   p.add( itemTwo );
   p.add( new TextField("0") );
   
   p.add( new ImageCanvas( img2, this ) );
   Panel itemThree = new Panel();
   itemThree.setLayout( new FlowLayout( FlowLayout.RIGHT ) );
   itemThree.add( itemThreeLabel );
   itemThree.add( itemThreeLabel1 );
   p.add( itemThree );
   p.add( new TextField("0") );
   
   p.add( new ImageCanvas( img3, this ) );
   Panel itemFour = new Panel();
   itemFour.setLayout( new FlowLayout( FlowLayout.RIGHT ) );
   itemFour.add( itemFourLabel );
   itemFour.add( itemFourLabel1 );
   p.add( itemFour );
   p.add( new TextField("0") );
   
   p.add( new ImageCanvas( img4, this ) );
   Panel itemFive = new Panel();
   itemFive.setLayout( new FlowLayout( FlowLayout.RIGHT ) );
   itemFive.add( itemFiveLabel );
   itemFive.add( itemFiveLabel1 );
   p.add( itemFive );
   p.add( new TextField("0") );
   
   
   //Add the buttons for shopping cart control
   cart = new Panel( );
   cart.setLayout( new GridLayout( 1, 4 ) );
   cart.add( add = new Button( "Add to Shopping Cart" ) );
   cart.add( view = new Button( "View Shopping Cart" ) );
   cart.add( order = new Button( "Place an Order" ) );
   cart.add( print = new Button( "View your Order" ) );
   
   add( "South", cart );
   }
   
 }
class ImageCanvas
    extends Canvas
{
    Image img;
    ImageObserver obs;
 
    public ImageCanvas( Image img, ImageObserver obs )
    {
    this.img= img;
    }
}

msmolyak locked it while I was posting the answer.
0
 
LVL 3

Expert Comment

by:mjenkins
ID: 1222483
Oops! I truncated ImageCanvas! It should be:

class ImageCanvas
   extends Canvas
{
    Image img;
    ImageObserver obs;
 
   public ImageCanvas( Image img, ImageObserver obs )
   {
      this.img= img;
   }
 
   public void paint(Graphics g)
   {
      g.drawImage( img, 0, 0, 75, 100, obs );
   }
}

If you like this answer better than msmolyak's reject the proposed answer and I will post as the new answer.

Additionally, there is a much better way to do this whole thing. You should really use a GridBagLayout to properly set up the sizes of the panels.
0
 

Author Comment

by:mapper
ID: 1222484
I would like to see the GridBagLayout offered by the other expert...

mapper
0
 
LVL 5

Expert Comment

by:msmolyak
ID: 1222485
Could you describe the desired layout using text like:

image1 label1 field1
image2 labe2 field2
.
button1 button2 button3

I would like to make sure I understand exactly what you need.
0
 

Author Comment

by:mapper
ID: 1222486
image of item in catalog on LEFT

Then a discription of item in CENTER

Then a TextField to order the item on RIGHT

With buttonPanel along bottom

The ImageObserver requires "reloads" of applet to paint the images...

However, it is looking better but the label method used as a product description is aligned to the right and truncates a portion of some of the longer entries...

0
 
LVL 5

Expert Comment

by:msmolyak
ID: 1222487
Let's try it.

GridBagConstraints for image canvases (see mjenkins'es proposal)
gridx = 0;
gridy = row number;
anchor = WEST;
insets = new Insets(10, 20, 0, 0);
weightx = 0;
weighty = 0;
fill = NONE;

For the Labels:
gridx = 1;
gridy = row number;
anchor = WEST;
insets = new Insets(10, 20, 0, 0);
weightx = 0;
weighty = 0;
fill = NONE;

For the  text fields:
gridx = 2;
gridy = row number;
anchor = WEST;
insets = new Insets(10, 20, 0, 20);
weightx = 0;
weighty = 1.0;
fill = HORIZONTAL;

To use that stuff do:

GridbagLayout gbl = new GridBagLayout()
p.setlayout(gbl);

// Do this for each component (use gdc.clone() to save some lines of code for similar constraints)
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
// Set the rest of constraints here
gbl.setConstraints(imageCanvas, gbc);
p.add(imageCanvas);


0
 
LVL 5

Expert Comment

by:msmolyak
ID: 1222488
Buttons will go into a separate panel. See my previous posting.
0
 

Author Comment

by:mapper
ID: 1222489
Wow!  A quantum leap (for me) !!  It will take me a few moments to cut & paste and then try to make sure all is in the right place...

Please bare with me... This is all TOTALLY new ...

Thanks,

mapper
0
 

Author Comment

by:mapper
ID: 1222490
msmolyak,

Heavy duty dude...  I am looking over what needs to be done...  Man, this is complicated to say the least...

I have to figure out the GBL Layout Manager is very complicated - this will probably keep me busy for a week!  I will give the old college try and then see what I think...

mapper
0
 
LVL 5

Expert Comment

by:msmolyak
ID: 1222491
Take your time. It is not as complicated as you think. You will probably need to understand what the contstraint values mean. Do not hesitate to ask.

Also although you can layout almost anything using GridBagLayout you should strive to use simpler means. Although in your case since you combine images and text it may be required. ((It may be had to align a label verticaly to image center for example).

Good luck!
0
 

Author Comment

by:mapper
ID: 1222492
Dude,

I am not really concerned if the images do not line up exactly, I just want to do this with out using the easy reshape method - I want to learn the right way - the big problem is that I am running out of time (I do have a completed first phase GUI using reshape done - in case this bite is bigger than I can chew) - I have two phases left - the next one is to make the catalog work and the last one is to print out a completed order... So, I need to finish, but I would like to learn the proper or at least technically proficient way of doing this - with out crap code to get it to work...

Thanks for you offer - I am looking at the text books input on the GBL and trying to use:

Image1 + TextArea + TextField
Image2 + TextArea + TextField
Image3 + TextArea + TextField
Image4 + TextArea + TextField
Image5 + TextArea + TextField
Button , Button, Button, Button

As the layout blueprint - I am hoping that the TA will help somewhat with the over all symmetry of the alignment problems you mentioned...

Thanks!

mapper
For the layout
0
 

Author Comment

by:mapper
ID: 1222493
BTW:

How do I contact you - via this email message to this input form?

mapper
0
 
LVL 5

Expert Comment

by:msmolyak
ID: 1222494
Just post a comment, I will respond as soon as I can.

Michael
0
 

Author Comment

by:mapper
ID: 1222495
Michael,

Cool - I have class in school tonight a final - but I don't have class again until Thursday - that will give me two good days to try it - if I don't get it I will use the crappy method because of the time constraints I mentioned previously...

mapper
0
 

Author Comment

by:mapper
ID: 1222496
Michael,

I have tinkered with the code and tried to compile it - I got 12 errors mainly with the images and the way I am trying to do it - is there anything in the code below that jumps out at you?

   import java.awt.image.ImageObserver;
   import java.awt.*;
   import java.lang.*;
   import java.awt.event.*;
   import java.applet.Applet;
       
       
     public class Cat extends Applet {

         // Load the image off the document base...

          GridBagLayout gbl;
          GridBagConstraints gbc;
            Canvas c;
            TextArea  ta, ta1, ta2, ta3, ta4;
            TextField tf, tf1, tf2, tf3, tf4;
        Image img, img1, img2, img3, img4;
        Button b1, b2, b3, b4;
            Label qty;
       
      public void init()
      {

      gbl = new GridBagLayout();
    setLayout(gbl);            // applet

      // instantiate the gridbag constraints
      gbc = new GridBagConstraints();

         img = getImage(getDocumentBase(),"spiral.gif");
         img1 = getImage(getDocumentBase(),"ledger.gif");
         img2 = getImage(getDocumentBase(),"pen.gif");
         img3 = getImage(getDocumentBase(),"pencil.gif");
         img4 = getImage(getDocumentBase(),"paperclip.gif");

            ta = new TextArea( "Writing Pads - 8 1/2 x 11, 50 sheets/pad, college ruled," +
                                       "bound at the top, Product stock number: 11, Cost: $1.00 ", 10, 5 );
      
            ta1 = new TextArea( "Accounting Ledger - 8 1/2 x 11, 50 sheets/ledger, 7 column, " +
                            "bound, Product stock number: 12, Cost: $3.00", 10, 5 );

            ta2 = new TextArea( "Ball Point Pens - Blue ink, Retractable point, 5 pens per " +
                                           "package, Product stock number: 21, Cost: $2.50 ", 10, 5 );
       
            ta3 = new TextArea( "Pencils - No 2 lead, 12 pencils/package, Product " +
                                          "stock number: 22, Cost: $1.25", 10, 5 );

            ta4 = new TextArea( "Paper Clips - Metal, 100 per box, 5 boxes per package, " +
                                          "Product stock number: 31, Cost: $2.50", 10, 5 );

            tf = new TextField( "20" );
            tf1 = new TextField( "20" );
            tf2 = new TextField( "20" );
            tf3 = new TextField( "20" );
            tf4 = new TextField( "20" );

            view = new Button( "View Items in Shopping Cart" );
            add = new Button( "Add Items to Shopping Cart" );
            order = new Button( "View Order" );
            print = new Button( "Submit Order" );

            qty = new Label( "QUANTITY:" );

            c = new Canvas( );
            c.setBackground( Color.white );                    
 
 
 
    //gbc.gridx = 0;

    // Set the rest of constraints here
    gbl.setConstraints(imageCanvas, gbc);
    p.add(imageCanvas);  


      //GridBagConstraints for image canvases
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( img, 0, 1, 1, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( img1, 0, 2, 1, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( img2, 0, 3, 1, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( img3, 0, 4, 1, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( img4, 0, 5, 1, 1 );

    //For the  Quantity Label:
      gbc.fill = GridBagConstraints.HORIZONTAL;
      addComponent( qty, 0, 3, 1, 1 );

      //For the TextAreas:
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( ta, 1, 1, 2, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( ta1, 1, 2, 2, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( ta2, 1, 3, 2, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( ta3, 1, 4, 2, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( ta4, 1, 5, 2, 1 );

    //For the  text fields:
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( tf, 1, 3, 1, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( tf1, 2, 3, 1, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( tf2, 3, 3, 1, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( tf3, 4, 3, 1, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( tf4, 5, 3, 1, 1 );
     
      //For the buttons
      gbc.fill = GridBagConstraints.HORIZONTAL;
      addComponent( b1, 0, 6, 1, 1 );
      gbc.fill = GridBagConstraints.HORIZONTAL;
      addComponent( b2, 1, 6, 1, 1 );
      gbc.fill = GridBagConstraints.HORIZONTAL;
      addComponent( b3, 2, 6, 1, 1 );
      gbc.fill = GridBagConstraints.HORIZONTAL;
      addComponent( b4, 3, 6, 1, 1 );

         }

      //addComponent is defined
      public void addComponent( Component c, int row, int column, int width, int height)
      {

            gbConstraints.gridx = column;
            cbContarints.dridy = row;

            gbConstraints.gridwidth = width;
            gbConstraints.gridheight = height;

            gbLayout.setConstraints( c, gbConstraints );
            add( c );
      }
         
       }

      class ImageCanvas extends Canvas
      {
          Image img;
          ImageObserver obs;
       
         public ImageCanvas( Image img, ImageObserver obs )
         {
            this.img= img;
         }
       
         public void paint(Graphics g)
         {
            g.drawImage( img, 5, 0, 75, 100, obs );
         }
      }

thanks,

mapper
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:mapper
ID: 1222497
Michael,

I have narrowed down the errors to just the five image references, I was confusing the name given to the books version of GBL and GBC with what you started with (DUH!) - so now I jsut have to figure out how to get the images to work and then I can take a look at it...

   import java.awt.image.ImageObserver;
   import java.awt.*;
   import java.lang.*;
   import java.awt.event.*;
   import java.applet.Applet;
       
       
     public class Cat extends Applet {

         // Load the image off the document base...

          GridBagLayout gbl;
          GridBagConstraints gbc;
            TextArea  ta, ta1, ta2, ta3, ta4;
            TextField tf, tf1, tf2, tf3, tf4;
        Image img, img1, img2, img3, img4;
        Button b1, b2, b3, b4;
            Label qty;
       
      public void init()
      {

      gbl = new GridBagLayout();
    setLayout(gbl);            // applet

      // instantiate the gridbag constraints
      gbc = new GridBagConstraints();

         img = getImage(getDocumentBase(),"spiral.gif");
         img1 = getImage(getDocumentBase(),"ledger.gif");
         img2 = getImage(getDocumentBase(),"pen.gif");
         img3 = getImage(getDocumentBase(),"pencil.gif");
         img4 = getImage(getDocumentBase(),"paperclip.gif");

            ta = new TextArea( "Writing Pads - 8 1/2 x 11, 50 sheets/pad, college ruled," +
                                       "bound at the top, Product stock number: 11, Cost: $1.00 ", 10, 5 );
      
            ta1 = new TextArea( "Accounting Ledger - 8 1/2 x 11, 50 sheets/ledger, 7 column, " +
                            "bound, Product stock number: 12, Cost: $3.00", 10, 5 );

            ta2 = new TextArea( "Ball Point Pens - Blue ink, Retractable point, 5 pens per " +
                                           "package, Product stock number: 21, Cost: $2.50 ", 10, 5 );
       
            ta3 = new TextArea( "Pencils - No 2 lead, 12 pencils/package, Product " +
                                          "stock number: 22, Cost: $1.25", 10, 5 );

            ta4 = new TextArea( "Paper Clips - Metal, 100 per box, 5 boxes per package, " +
                                          "Product stock number: 31, Cost: $2.50", 10, 5 );

            tf = new TextField( "20" );
            tf1 = new TextField( "20" );
            tf2 = new TextField( "20" );
            tf3 = new TextField( "20" );
            tf4 = new TextField( "20" );

            b1 = new Button( "View Items in Shopping Cart" );
            b2 = new Button( "Add Items to Shopping Cart" );
            b3 = new Button( "View Order" );
            b4 = new Button( "Submit Order" );

            qty = new Label( "QUANTITY:" );

 
    //gbc.gridx = 0;

    // Set the rest of constraints here
    //gbl.setConstraints(imageCanvas, gbc);
    //add(imageCanvas);  


      //GridBagConstraints for image canvases
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( img, 0, 1, 1, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( img1, 0, 2, 1, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( img2, 0, 3, 1, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( img3, 0, 4, 1, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( img4, 0, 5, 1, 1 );

    //For the  Quantity Label:
      gbc.fill = GridBagConstraints.HORIZONTAL;
      addComponent( qty, 0, 3, 1, 1 );

      //For the TextAreas:
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( ta, 1, 1, 2, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( ta1, 1, 2, 2, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( ta2, 1, 3, 2, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( ta3, 1, 4, 2, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( ta4, 1, 5, 2, 1 );

    //For the  text fields:
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( tf, 1, 3, 1, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( tf1, 2, 3, 1, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( tf2, 3, 3, 1, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( tf3, 4, 3, 1, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( tf4, 5, 3, 1, 1 );
     
      //For the buttons
      gbc.fill = GridBagConstraints.HORIZONTAL;
      addComponent( b1, 0, 6, 1, 1 );
      gbc.fill = GridBagConstraints.HORIZONTAL;
      addComponent( b2, 1, 6, 1, 1 );
      gbc.fill = GridBagConstraints.HORIZONTAL;
      addComponent( b3, 2, 6, 1, 1 );
      gbc.fill = GridBagConstraints.HORIZONTAL;
      addComponent( b4, 3, 6, 1, 1 );

         }

      //addComponent is defined
      public void addComponent( Component c, int row, int column, int width, int height)
      {
            //set gridx and gridy
            gbc.gridx = column;
            gbc.gridy = row;

            //set gridwidth and gridheight
            gbc.gridwidth = width;
            gbc.gridheight = height;

            //set constraints
            gbl.setConstraints( c, gbc );
            add( c );
      }
         
       }

      class ImageCanvas extends Canvas
      {
          Image img;
          ImageObserver obs;
       
         public ImageCanvas( Image img, ImageObserver obs )
         {
            this.img= img;
         }
       
         public void paint(Graphics g)
         {
            g.drawImage( img, 5, 0, 75, 100, obs );
         }
      }

L8R Dude,

mapper
0
 
LVL 3

Expert Comment

by:mjenkins
ID: 1222498
To msmolyak:

I'm glad you were able to take advantage of MY answer for YOUR  benefit... there's nothing so satisfying as taking credit for someone else's effort...
0
 

Author Comment

by:mapper
ID: 1222499
Either way - I will award points to you both - I am under the gun and this is just the first phase of the three phase project - I have (with the image references rem'ed out) the gridbaglayout working - though w/o the images it is skewed -

Please believe me I will adequately reward both of your efforts - once they are working properly...

Thanks,

mapper
0
 

Author Comment

by:mapper
ID: 1222500
Doesn't give enough information to implement image portion of GridBagLayout...

I can figure it all out but that ...


0
 

Author Comment

by:mapper
ID: 1222501
I have made the GBL functional except for the images (5 of them) - Here is the code that has all references to the images rem'ed out:

   import java.awt.image.ImageObserver;
   import java.awt.*;
   import java.lang.*;
   import java.awt.event.*;
   import java.applet.Applet;
       
       
     public class Cat extends Applet {

         // Load the image off the document base...

          GridBagLayout gbl;
          GridBagConstraints gbc;
            TextArea  ta, ta1, ta2, ta3, ta4;
            TextField tf, tf1, tf2, tf3, tf4;
        Image img, img1, img2, img3, img4;
        Button b1, b2, b3, b4;
            Label qty;
       
      public void init()
      {

      gbl = new GridBagLayout();
    setLayout(gbl);            // applet

      // instantiate the gridbag constraints
      gbc = new GridBagConstraints();

         img = getImage(getDocumentBase(),"spiral.gif");
         img1 = getImage(getDocumentBase(),"ledger.gif");
         img2 = getImage(getDocumentBase(),"pen.gif");
         img3 = getImage(getDocumentBase(),"pencil.gif");
         img4 = getImage(getDocumentBase(),"paperclip.gif");

            ta = new TextArea( "Writing Pads - 8 1/2 x 11, 50 sheets/pad, college ruled," + "\n"
                            + "bound at the top, Product stock number: 11, Cost: $1.00 ", 2, 7 );
      
            ta1 = new TextArea( "Accounting Ledger - 8 1/2 x 11, 50 sheets/ledger, 7 column, "
                        + "\n" + "bound, Product stock number: 12, Cost: $3.00", 2, 7 );

            ta2 = new TextArea( "Ball Point Pens - Blue ink, Retractable point, 5 pens per " +                                     "\n" + "package, Product stock number: 21, Cost: $2.50 ", 2, 7 );
       
            ta3 = new TextArea( "Pencils - No 2 lead, 12 pencils/package, Product " + "\n" +
                                          "stock number: 22, Cost: $1.25", 2, 7 );

            ta4 = new TextArea( "Paper Clips - Metal, 100 per box, 5 boxes per package, " +
                              "\n" + "Product stock number: 31, Cost: $2.50", 2, 7 );

            tf = new TextField( " " );
            tf1 = new TextField( " " );
            tf2 = new TextField( " " );
            tf3 = new TextField( " " );
            tf4 = new TextField( " " );

            b1 = new Button( "View Items in Shopping Cart" );
            b2 = new Button( "Add Items to Shopping Cart" );
            b3 = new Button( "View Order" );
            b4 = new Button( "Submit Order" );

            qty = new Label( "QUANTITY:" );

 
      //GridBagConstraints for image canvases
      //gbc.fill = GridBagConstraints.BOTH;
      //addComponent( img, 1, 0, 1, 1 );
      //gbc.fill = GridBagConstraints.BOTH;
      //addComponent( img1, 2, 0, 1, 1 );
      //gbc.fill = GridBagConstraints.BOTH;
      //addComponent( img2, 3, 0, 1, 1 );
      //gbc.fill = GridBagConstraints.BOTH;
      //addComponent( img3, 4, 0, 1, 1 );
      //gbc.fill = GridBagConstraints.BOTH;
      //addComponent( img4, 5, 0, 1, 1 );

    //For the  Quantity Label:
      gbc.fill = GridBagConstraints.HORIZONTAL;
      addComponent( qty, 0, 3, 1, 1 );

      //For the TextAreas:
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( ta, 1, 1, 2, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( ta1, 2, 1, 2, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( ta2, 3, 1, 2, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( ta3, 4, 1, 2, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( ta4, 5, 1, 2, 1 );

    //For the  text fields:
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( tf, 1, 3, 1, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( tf1, 2, 3, 1, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( tf2, 3, 3, 1, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( tf3, 4, 3, 1, 1 );
      gbc.fill = GridBagConstraints.BOTH;
      addComponent( tf4, 5, 3, 1, 1 );
     
      //For the buttons
      gbc.fill = GridBagConstraints.HORIZONTAL;
      addComponent( b1, 6, 0, 1, 1 );
      gbc.fill = GridBagConstraints.HORIZONTAL;
      addComponent( b2, 6, 1, 1, 1 );
      gbc.fill = GridBagConstraints.HORIZONTAL;
      addComponent( b3, 6, 2, 1, 1 );
      gbc.fill = GridBagConstraints.HORIZONTAL;
      addComponent( b4, 6, 3, 1, 1 );

         }

      //addComponent is defined
public void addComponent( Component c, int row, int column, int width, int height)
      {
            //set gridx and gridy
            gbc.gridx = column;
            gbc.gridy = row;

            //set gridwidth and gridheight
            gbc.gridwidth = width;
            gbc.gridheight = height;

            //set constraints
            gbl.setConstraints( c, gbc );
            add( c );

      }

    // Set the rest of constraints here
    //      gbl.setConstraints(imageCanvas, gbc);
    //      add(imageCanvas);
 
         
       }

      class ImageCanvas extends Canvas
      {
          Image img;
          ImageObserver obs;
       
         public ImageCanvas( Image img, ImageObserver obs )
         {
            this.img= img;
         }
       
         public void paint(Graphics g)
         {
            g.drawImage( img, 5, 0, 75, 100, obs );
         }
      }

What can I do to implement the images in the left column of the GBL???

mapper
0
 
LVL 3

Accepted Solution

by:
mjenkins earned 300 total points
ID: 1222502
Here is the new source. Your button panel was causing the sizes of the columns t o be scewed. Hope this helps...

import java.awt.image.ImageObserver;
import java.awt.*;
import java.lang.*;
import java.awt.event.*;
import java.applet.Applet;


public class Cat extends Applet {

              // Load the image off the document base...

     GridBagLayout gbl;
     GridBagConstraints gbc;
     TextArea  ta, ta1, ta2, ta3, ta4;
     TextField tf, tf1, tf2, tf3, tf4;
     Image img, img1, img2, img3, img4;
     Button b1, b2, b3, b4;
     Label item;
     Label desc;
     Label qty;

     public void init()
     {

     gbl = new GridBagLayout();
         setLayout(gbl); // applet

     // instantiate the gridbag constraints
     gbc = new GridBagConstraints();

     Panel bPanel = new Panel();

     img = getImage(getDocumentBase(),"img.gif");
     img1 = getImage(getDocumentBase(),"img.gif");
     img2 = getImage(getDocumentBase(),"img.gif");
     img3 = getImage(getDocumentBase(),"img.gif");
     img4 = getImage(getDocumentBase(),"img.gif");

     ta = new TextArea( "Writing Pads - 8 1/2 x 11, 50 sheets/pad, college ruled," + "\n"
         + "bound at the top, Product stock number: 11, Cost: $1.00 ", 2, 7 );

     ta1 = new TextArea( "Accounting Ledger - 8 1/2 x 11, 50 sheets/ledger, 7 column, "
     + "\n" + "bound, Product stock number: 12, Cost: $3.00", 2, 7 );

     ta2 = new TextArea( "Ball Point Pens - Blue ink, Retractable point, 5 pens per "
     + "\n" + "package, Product stock number: 21, Cost: $2.50 ", 2, 7 );

     ta3 = new TextArea( "Pencils - No 2 lead, 12 pencils/package, Product " + "\n" +
     "stock number: 22, Cost: $1.25", 2, 7 );

     ta4 = new TextArea( "Paper Clips - Metal, 100 per box, 5 boxes per package, " +
     "\n" + "Product stock number: 31, Cost: $2.50", 2, 7 );

     tf = new TextField( " " );
     tf1 = new TextField( " " );
     tf2 = new TextField( " " );
     tf3 = new TextField( " " );
     tf4 = new TextField( " " );

     b1 = new Button( "View Items in Shopping Cart" );
     b2 = new Button( "Add Items to Shopping Cart" );
     b3 = new Button( "View Order" );
     b4 = new Button( "Submit Order" );

     ImageCanvas im1 = new ImageCanvas( img, this );
     ImageCanvas im2 = new ImageCanvas( img1, this );
     ImageCanvas im3 = new ImageCanvas( img2, this );
     ImageCanvas im4 = new ImageCanvas( img3, this );
     ImageCanvas im5 = new ImageCanvas( img4, this );

     item = new Label( "Item:" );
     desc = new Label( "Description:" );
     qty = new Label( "Quantity:" );

     //GridBagConstraints for image canvases
     gbc.weightx = 0;
     gbc.weighty = 0;
     gbc.fill = GridBagConstraints.BOTH;
     addComponent( im1, 1, 0, 1, 1 );
     gbc.fill = GridBagConstraints.BOTH;
     addComponent( im2, 2, 0, 1, 1 );
     gbc.fill = GridBagConstraints.BOTH;
     addComponent( im3, 3, 0, 1, 1 );
     gbc.fill = GridBagConstraints.BOTH;
     addComponent( im4, 4, 0, 1, 1 );
     gbc.fill = GridBagConstraints.BOTH;
     addComponent( im5, 5, 0, 1, 1 );

         //For the  Quantity Label:
     gbc.fill = GridBagConstraints.HORIZONTAL;
     addComponent( item, 0, 0, 1, 1 );
     addComponent( desc, 0, 1, 2, 1 );
     addComponent( qty, 0, 3, 1, 1 );

     //For the TextAreas:
     gbc.weightx = 1;
     gbc.weighty = 1;
     gbc.fill = GridBagConstraints.BOTH;
     addComponent( ta, 1, 1, 2, 1 );
     gbc.fill = GridBagConstraints.BOTH;
     addComponent( ta1, 2, 1, 2, 1 );
     gbc.fill = GridBagConstraints.BOTH;
     addComponent( ta2, 3, 1, 2, 1 );
     gbc.fill = GridBagConstraints.BOTH;
     addComponent( ta3, 4, 1, 2, 1 );
     gbc.fill = GridBagConstraints.BOTH;
     addComponent( ta4, 5, 1, 2, 1 );

         //For the  text fields:
     gbc.weightx = 0;
     gbc.weighty = 0;
     gbc.fill = GridBagConstraints.BOTH;
     addComponent( tf, 1, 3, 1, 1 );
     gbc.fill = GridBagConstraints.BOTH;
     addComponent( tf1, 2, 3, 1, 1 );
     gbc.fill = GridBagConstraints.BOTH;
     addComponent( tf2, 3, 3, 1, 1 );
     gbc.fill = GridBagConstraints.BOTH;
     addComponent( tf3, 4, 3, 1, 1 );
     gbc.fill = GridBagConstraints.BOTH;
     addComponent( tf4, 5, 3, 1, 1 );

     // Buttons
     bPanel.setLayout( new GridLayout( 1, 4 ) );
     bPanel.add( b1 );
     bPanel.add( b2 );
     bPanel.add( b3 );
     bPanel.add( b4 );
     gbc.fill = GridBagConstraints.HORIZONTAL;
     addComponent( bPanel, 6, 0, 4, 1 );

     }

     //addComponent is defined
     public void addComponent( Component c, int row, int column, int width, int height)
     {
     //set gridx and gridy
     gbc.gridx = column;
     gbc.gridy = row;

     //set gridwidth and gridheight
     gbc.gridwidth = width;
     gbc.gridheight = height;

     //set constraints
     gbl.setConstraints( c, gbc );
     add( c );

     }
}

class ImageCanvas
    extends Canvas
{
    Image img;
    ImageObserver obs;

    public ImageCanvas( Image img, ImageObserver obs )
    {
        this.img= img;
    }

    public Dimension preferredSize()
    {
        return new Dimension( 76,101 );
    }

    public Dimension minimumSize()
    {
        return preferredSize();
    }

    public void paint(Graphics g)
    {
        g.drawImage( img, 0, 0, 75, 100, obs );
    }
}
~


0
 

Author Comment

by:mapper
ID: 1222503
mjenkins,

I get three deprecation errors:

preferredSize & minimumSize

and the images are not loading - I had a final tonight and I will look at it in the morning when I am not so burned out...

One thing though, I appreciate your sticking with me on this - I didn't want to be the cause for problems between you and msmolyak -  I got confused with all of the postings and I stand by my comment in regards to rewarding both of your efforts...  I have a Prof. that insists on bending the way Java should be  - with get it done no matter what the code looks like and then he will not get back to you in a timely manner and that puts the squeeze on you and the frustration level amps up and it is not very nice.  I just want to get this catalog done with as much code that is normal from a technical standpoint and not get into the habit of what ever works no matter what...

Thanks again, I will play around with the images and see if I can get them working in the morning...

mapper
0
 
LVL 3

Expert Comment

by:mjenkins
ID: 1222504
Here, I've fixed your image problem and cleaned up the code a little bit. You don't need to constantly keep setting gbc.fill, it stays until you change it. The reason the images weren't loading was because they need to be repaint'ed after loading. The '500' just keeps the repainting down to twice a second while loading the images. I removed the two size methods that were deprecated -- they aren't REALLY necessary.

BTW - You can stop the error messages by simply adding a javadoc:

/**
 * @deprecated
 */

comment above the method in question. I used the deprecated methods to maintain 1.02 compatibility.

Well, here is the final code:

import java.awt.image.ImageObserver;
import java.awt.*;
import java.lang.*;
import java.awt.event.*;
import java.applet.Applet;
 
 
public class Cat extends Applet
{
    private GridBagLayout gbl;
    private GridBagConstraints gbc;
    private TextArea  ta, ta1, ta2, ta3, ta4;
    private TextField tf, tf1, tf2, tf3, tf4;
    private Button b1, b2, b3, b4;
    private Label item, desc, qty;
 
    public void init()
    {
        gbl = new GridBagLayout();
        setLayout(gbl); // applet
 
        // instantiate the gridbag constraints
        gbc = new GridBagConstraints();
        Panel bPanel = new Panel();
 
        // Load Descriptions
        ta = new TextArea( "Writing Pads - 8 1/2 x 11, 50 sheets/pad, college ruled," + "\n"
            + "bound at the top, Product stock number: 11, Cost: $1.00 ", 2, 7 );
        ta1 = new TextArea( "Accounting Ledger - 8 1/2 x 11, 50 sheets/ledger, 7 column, "
            + "\n" + "bound, Product stock number: 12, Cost: $3.00", 2, 7 );
        ta2 = new TextArea( "Ball Point Pens - Blue ink, Retractable point, 5 pens per "
            + "\n" + "package, Product stock number: 21, Cost: $2.50 ", 2, 7 );
        ta3 = new TextArea( "Pencils - No 2 lead, 12 pencils/package, Product " + "\n" +
            "stock number: 22, Cost: $1.25", 2, 7 );
        ta4 = new TextArea( "Paper Clips - Metal, 100 per box, 5 boxes per package, " +
            "\n" + "Product stock number: 31, Cost: $2.50", 2, 7 );
 
        // Initialize Qty fields
        tf = new TextField( " " );
        tf1 = new TextField( " " );
        tf2 = new TextField( " " );
        tf3 = new TextField( " " );
        tf4 = new TextField( " " );
 
        // Button Controls
        b1 = new Button( "View Items in Shopping Cart" );
        b2 = new Button( "Add Items to Shopping Cart" );
        b3 = new Button( "View Order" );
        b4 = new Button( "Submit Order" );
 
        // Load images
        ImageCanvas im1 = new ImageCanvas( getImage(getDocumentBase(),"spiral.gif") );
        ImageCanvas im2 = new ImageCanvas( getImage(getDocumentBase(),"ledger.gif") );
        ImageCanvas im3 = new ImageCanvas( getImage(getDocumentBase(),"pen.gif") );
        ImageCanvas im4 = new ImageCanvas( getImage(getDocumentBase(),"pencil.gif") );
        ImageCanvas im5 = new ImageCanvas( getImage(getDocumentBase(),"paperclip.gif") );
 
        // Labels
        item = new Label( "Item:" );
        desc = new Label( "Description:" );
        qty = new Label( "Quantity:" );
 
        //GridBagConstraints for image canvases
        gbc.weightx = 0;
        gbc.weighty = 0;
        gbc.fill = GridBagConstraints.BOTH;
        addComponent( im1, 1, 0, 1, 1 );
        addComponent( im2, 2, 0, 1, 1 );
        addComponent( im3, 3, 0, 1, 1 );
        addComponent( im4, 4, 0, 1, 1 );
        addComponent( im5, 5, 0, 1, 1 );
   
        //For the  Quantity Label:
        gbc.fill = GridBagConstraints.HORIZONTAL;
        addComponent( item, 0, 0, 1, 1 );
        addComponent( desc, 0, 1, 2, 1 );
        addComponent( qty, 0, 3, 1, 1 );
   
        //For the TextAreas:
        gbc.weightx = 1;
        gbc.weighty = 1;
        gbc.fill = GridBagConstraints.BOTH;
        addComponent( ta, 1, 1, 2, 1 );
        addComponent( ta1, 2, 1, 2, 1 );
        addComponent( ta2, 3, 1, 2, 1 );
        addComponent( ta3, 4, 1, 2, 1 );
        addComponent( ta4, 5, 1, 2, 1 );
   
        //For the  text fields:
        gbc.weightx = 0;
        gbc.weighty = 0;
        gbc.fill = GridBagConstraints.BOTH;
        addComponent( tf, 1, 3, 1, 1 );
        addComponent( tf1, 2, 3, 1, 1 );
        addComponent( tf2, 3, 3, 1, 1 );
        addComponent( tf3, 4, 3, 1, 1 );
        addComponent( tf4, 5, 3, 1, 1 );
   
        // Buttons
        bPanel.setLayout( new GridLayout( 1, 4 ) );
        bPanel.add( b1 );
        bPanel.add( b2 );
        bPanel.add( b3 );
        bPanel.add( b4 );
        gbc.fill = GridBagConstraints.HORIZONTAL;
        addComponent( bPanel, 6, 0, 4, 1 );
    }
    //addComponent is defined
    public void addComponent( Component c, int row, int column, int width, int height)
    {
        //set gridx and gridy
        gbc.gridx = column;
        gbc.gridy = row;
   
        //set gridwidth and gridheight
        gbc.gridwidth = width;
        gbc.gridheight = height;
   
        //set constraints
        gbl.setConstraints( c, gbc );
        add( c );
    }
}  
 
class ImageCanvas
    extends Canvas
    implements ImageObserver
{  
    Image img;
   
    public ImageCanvas( Image img )
    {
        this.img= img;
    }
   
    public boolean imageUpdate( Image im, int info, int x, int y, int width, int height )
    {
        repaint(500);
        return true;
    }
 
    public void paint(Graphics g)
    {
        g.drawImage( img, 0, 0, 75, 100, this );
    }
}

0
 

Author Comment

by:mapper
ID: 1222505
mjenkins,

How bizarre - I was just looking at what you sent last night and I noticed the images were not named (Man, I must have been tired!) - I will crank through it once and then to the feedback...

Thanks...

mapper
0
 

Author Comment

by:mapper
ID: 1222506
mjenkins,

All looks good except the images are being truncated (only showing half of the image) I played with the

gbc.weightx = 1;   originally 0 for both - now the pictures show but it screws up the TAs
gbc.weighty = 1;

There is a big gap between the pictures and the TextAreas - is it a conflict between the GBL settings for the the two or what??

mapper
0
 
LVL 3

Expert Comment

by:mjenkins
ID: 1222507
What size are you using for the applet width and height in the html file?
How big are the pictures?
I had assumed from your original post that the pictures were all of uniform size (75x100), is this not the case?

Don't play with the weights, that's not the problem. The problem is with the ImageCanvas. I need more specifics about the gif files...

0
 

Author Comment

by:mapper
ID: 1222508
M,

All images are of WIDTH = 100 and HEIGHT = 75 pixels.

I have put the code back the way it was - I was playing in order to learn about GBL and GBC - man, that is funky...

mapper
0
 

Author Comment

by:mapper
ID: 1222509
M,

I omitted the applet info:

<APPLET code="Cat" width="650" height="525">
</APPLET>

I changed the width and it just resized and the problem was the same...

thanks,

mapper
0
 
LVL 3

Expert Comment

by:mjenkins
ID: 1222510
What size are you using for the applet width and height in the html file?
How big are the pictures?
I had assumed from your original post that the pictures were all of uniform size (75x100), is this not the case?

Don't play with the weights, that's not the problem. The problem is with the ImageCanvas. I need more specifics about the gif files...

0
 
LVL 3

Expert Comment

by:mjenkins
ID: 1222511
Here is a replacement for ImageCanvas that deal with arbitrary sized Images. The picture column in the applet should size to the largest image. Try this out. I used a couple of different sized images to test with, so it should be okay.

class ImageCanvas
    extends Panel
    implements ImageObserver  
{  
    Image img;
    int width, height;
   
    public ImageCanvas( Image img )
    {
        this.img= img;
        height = img.getHeight(this);
        width = img.getWidth(this);
    }  
 
    /**
     * @deprecated
     */
    public Dimension minimumSize( )
    {  
        return preferredSize( );
    }      
 
    /**    
     * @deprecated
     */    
    public Dimension preferredSize( )
    {      
        return new Dimension( width, height );
    }      
 
    public boolean imageUpdate( Image im, int info, int x, int y, int width, int height )
    {  
        if( (info & WIDTH) != 0 )  
        {
            this.width = width;
        }
        if( (info & HEIGHT) != 0 )
        {
            this.height = height;
        }
        if( (info & ALLBITS) != 0 )
        {
            setSize( this.width, this.height );
            repaint();
            return false;
        }
 
        repaint(500);
        return true;
    }
       
    public void update(Graphics g)  
    {  
        paint(g);
    }
       
    public void paint(Graphics g)
    {  
        g.drawImage( img, 0, 0, width, height, null );
    }  
}

0
 

Author Comment

by:mapper
ID: 1222512
M,

Everything works but I have to hit reload to get the images to paint - the viewable scree does not paint the images but if you scroll down the lower two images are there and then when you scroll back up that image paints - but not the middle two - unless, I hit reload...

Any thoughts?

mapper
0
 
LVL 3

Expert Comment

by:mjenkins
ID: 1222513
Try this:

Change the

repaint();

in updateImage() to

invalidate();
repaint(1);

also change

g.drawImage( img, 0, 0, width, height, null );  

to

g.drawImage( img, 0, 0, width, height, this );

There is no reason why it shouldn't work as-is. Its a browser quirk. The repaint call is not being honored. Browser supprt for Java really sucks.
0
 

Author Comment

by:mapper
ID: 1222514
M,

You Da MAN!!

That did it - why is the browser support so lousy for Java when M$ and Netscape both tout Java as the saviour for the web??

Doesn't add up -

Now on to part two making the buttons work and making the catalog function - the GUI was hard enough why do I feel like this is going to be even harder??

would you recommend a cardpanel or something that brings up a new window when one of the buttons is clicked at the bottom of the catalog GUI??

mapper
0
 
LVL 3

Expert Comment

by:mjenkins
ID: 1222515
I would most likely create a frame or dialog that would become visible as necessary. Using the Applet panel itself is unpredictable (as we've seen).
0
 

Author Comment

by:mapper
ID: 1222516
M,

That will give me something to think about - I have a feeling I'll be posting again though!

mapper
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now