7 Replies Latest reply on Nov 19, 2002 4:13 AM by 807549

    jpanel help

    807549
      here is the code below it works perfectly, only problem which i am having is when I use jpanel or Jframe then it gives me an errors.
      import java.awt.*;
      import java.awt.event.*;
      import java.awt.image.*;
      
      public class RecBt extends Frame
      {
      DPanel pan = new DPanel();
      int bars = 3;
      
      public RecBt(int w, int h)
      {
      super();
      addWindowListener(new WindowAdapter()
      { public void windowClosing(WindowEvent ev)
      { dispose();
      System.exit(0);
      }
      public void windowDeiconified(WindowEvent ev)
      {
      bars = 4;
      }
      });
      setBounds(6,6,w,h);
      add(pan);
      setVisible(true);
      }
      public class DPanel extends Panel
      {
      Image image;
      Color color[] = new Color[4];
      
      public DPanel()
      {
      image = getToolkit().createImage("flower.jpg");
      MediaTracker tracker = new MediaTracker(this);
      tracker.addImage(image,0);
      try
      {
      tracker.waitForID(0);
      }
      catch (InterruptedException e){}
      color[0] = Color.red;
      color[1] = Color.blue;
      color[2] = Color.gray;
      color[3] = Color.orange;
      }
      public void paint(Graphics g)
      {
      super.paint(g);
      int h2 = getHeight()/2;
      for (int j=0; j < bars; j++)
      {
      Bar bar = new Bar(j,0,j*h2/bars,getWidth(),h2/bars);
      g.setColor(color[j]);
      bar.draw(g);
      }
      g.drawImage(image,0,h2,getWidth(),h2,null);
      }
      }
      public class Bar
      {
      int x,y,width,height,num;
      String text;
      
      public Bar(int num, int x, int y, int w, int h)
      {
      this.num = num;
      this.x = x;
      this.y = y;
      width = w;
      height = h;
      if (num == 3) text = num+" This Is The Extra Line "+num;
      else text = num+"Agkgkgkgkgkgkgkgkgkgkgkgk"+num;
      }
      public void draw(Graphics g)
      {
      g.fillRect(x,y,width,height);
      g.setColor(Color.white);
      g.setFont(new Font("",0,height/2));
      FontMetrics fm = getFontMetrics(g.getFont());
      int tw = fm.stringWidth(text);
      g.drawString(text,(width-tw)/2,y+height/2);
      }
      }
      public static void main (String[] args)
      {
      new RecBt(500,350);
      }
      }
      
      [\code]
      
      here are the errors:
      
      C:\Documents and Settings\Jasmin  Shah\My Documents\CIS168\RecBt.java:5: cannot resolve symbol
      symbol  : class JFrame  
      location: class RecBt
      public class RecBt extends JFrame
                                 ^
      C:\Documents and Settings\Jasmin  Shah\My Documents\CIS168\RecBt.java:27: cannot resolve symbol
      symbol  : class JPanel  
      location: class RecBt.DPanel
      public class DPanel extends JPanel
                                  ^
      C:\Documents and Settings\Jasmin  Shah\My Documents\CIS168\RecBt.java:15: cannot resolve symbol
      symbol: method dispose  ()
      { dispose();
        ^
      C:\Documents and Settings\Jasmin  Shah\My Documents\CIS168\RecBt.java:13: cannot resolve symbol
      symbol  : method addWindowListener  (<anonymous java.awt.event.WindowAdapter>)
      location: class RecBt
      addWindowListener(new WindowAdapter()
      ^
      C:\Documents and Settings\Jasmin  Shah\My Documents\CIS168\RecBt.java:23: cannot resolve symbol
      symbol  : method setBounds  (int,int,int,int)
      location: class RecBt
      setBounds(6,6,w,h);
      ^
      C:\Documents and Settings\Jasmin  Shah\My Documents\CIS168\RecBt.java:24: cannot resolve symbol
      symbol  : method add  (RecBt.DPanel)
      location: class RecBt
      add(pan);
      ^
      C:\Documents and Settings\Jasmin  Shah\My Documents\CIS168\RecBt.java:25: cannot resolve symbol
      symbol  : method setVisible  (boolean)
      location: class RecBt
      setVisible(true);
      ^
      C:\Documents and Settings\Jasmin  Shah\My Documents\CIS168\RecBt.java:34: cannot resolve symbol
      symbol  : method getToolkit  ()
      location: class RecBt.DPanel
      image = getToolkit().createImage("flower.jpg");
              ^
      C:\Documents and Settings\Jasmin  Shah\My Documents\CIS168\RecBt.java:49: cannot resolve symbol
      symbol  : variable super  
      location: class RecBt.DPanel
      super.paint(g);
      ^
      C:\Documents and Settings\Jasmin  Shah\My Documents\CIS168\RecBt.java:50: cannot resolve symbol
      symbol  : method getHeight  ()
      location: class RecBt.DPanel
      int h2 = getHeight()/2;
               ^
      C:\Documents and Settings\Jasmin  Shah\My Documents\CIS168\RecBt.java:53: cannot resolve symbol
      symbol  : method getWidth  ()
      location: class RecBt.DPanel
      Bar bar = new Bar(j,0,j*h2/bars,getWidth(),h2/bars);
                                      ^
      C:\Documents and Settings\Jasmin  Shah\My Documents\CIS168\RecBt.java:57: cannot resolve symbol
      symbol  : method getWidth  ()
      location: class RecBt.DPanel
      g.drawImage(image,0,h2,getWidth(),h2,null);
                             ^
      C:\Documents and Settings\Jasmin  Shah\My Documents\CIS168\RecBt.java:80: cannot resolve symbol
      symbol  : method getFontMetrics  (java.awt.Font)
      location: class RecBt.Bar
      FontMetrics fm = getFontMetrics(g.getFont());
                       ^
      13 errors