p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_java thread: "SketchModel not found in class" error message in Sketcher program


Message #1 by dominskis@a... on Wed, 10 Apr 2002 22:05:31
Dear People,
 In doing Ivor Horton's "Beginning Java 2" Chapter 14 page 664Sketcher 
program I ahve error message that says:


"SketcherCalculator.java": class SketchModel not found in class 
sketchercalculator.SketcherCalculator at line 20, and line 69 and line 49


"SketchView.java": Error #: 300 : class Sketcher not found in class 
sketchercalculator.SketchView at line 69, column 23


below is the coding 
Thank you in advance
Stan

package sketchercalculator;

import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.event.*;
import java.util.*;

//Sketcher Program version  #11 Drawing in a View

public class SketcherCalculator
{
  //declare the application window reference variable as private
  private static SketchFrame myJFrame;

  //declare the application window object
  private static SketcherCalculator theApp;

  //the data model for the sketch
  private SketchModel sketch;

 //the view of the sketch
 private SketchView view;


  public void init()
   {

     myJFrame =  new SketchFrame("Enjoying the design process", this);

     myJFrame.setSize(400,400);

     Dimension myFrameSize = myJFrame.getSize();
     Toolkit myToolkit = myJFrame.getToolkit();
     Dimension myScreenSize = myToolkit.getDefaultToolkit().getScreenSize
();

     //center the frame on the screen
     myJFrame.setLocation((myScreenSize.width -  myFrameSize.width)/2,
                         (myScreenSize.height - myFrameSize.height)/2);

    //charnge the backgroud color of the content pane
    myJFrame.getContentPane().setBackground(Color.yellow);

    //create the WindowAdapter object that is the listener for the 
myJFrame object
    myJFrame.addWindowListener(new WindowHandler() );

    //#11
    //create the model object
    sketch = new SketchModel();

    //create the view object
    view = new SketchView(this);

    //register the view with the model
    sketch.addObserver((Observer)view);

    myJFrame.getContentPane().add(view, BorderLayout.CENTER);

    myJFrame.setVisible(true);
   }

   //Return a reference to the aplication window
   public SketchFrame getWindow()
    {
     return myJFrame;
    }

    //return a referrrence to the model
    public SketchModel getModel()
     {
       return sketch;
     }

     //Return a reference to the view
     public SketchView getView()
      {
       return view;
      }




   //Handler class for window events
   class WindowHandler extends WindowAdapter
    {
      //Handler method for window closing event
        public void windowClosing(WindowEvent e)
           {
             //release window resources
             myJFrame.dispose();

             //end the application
             System.exit(0);
           }
    }

   public static void main(String[] args)
    {
         //create the application object
     theApp =  new SketcherCalculator();

     //initialize the application object
     theApp.init();

            new Calculator6();
    }
}

package sketchercalculator;

//Sketcher Program #11 Drawing in a View

import java.awt.*;          //for graphics
import javax.swing.*;
import java.util.*;        //for Observer
import java.awt.geom.*;

   class SketchView extends JComponent implements Observer
     {
        //temporary code
        //user coordiante system for drawing on a component is incapsulated
        // in the  object g. It provides tools needed to draw.
       public void paint(Graphics g)
        {

        //get a Java 2D device context in order to use the Graphics2D 
methods
          Graphics2D g2D = (Graphics2D)g;

          //draw in red
          g2D.setPaint(Color.red);

          //Position width and height of first rectangle
          Point2D.Float p1 = new Point2D.Float(50.0f, 10.0f);
          float width1 = 60;
          float height1 = 80;

          //Create and draw the first rectangle
          Rectangle2D.Float rect =   new Rectangle2D.Float(p1.x, p1.y, 
width1, height1);
          g2D.draw(rect);

          //  Position width and height of second rectangle
           Point2D.Float p2 = new Point2D.Float(150.0f, 100.0f);
          float width2 = width1 + 30;
          float height2 = height1 + 40;

          //create and draw the second rectangle
          g2D.draw(new Rectangle2D.Float((float)(p2.getX()), (float)
(p2.getY()), width2, height2));

          //draw in blue
           g2D.setPaint(Color.blue);

          //Draw lines to join to join corresponding corners of the 
rectangles
          Line2D.Float line = new Line2D.Float(p1,p2);
          g2D.draw(line);

          p1.setLocation(p1.x + width1, p1.y);
          p2.setLocation(p2.x + width2, p2.y);
          g2D.draw(new Line2D.Float(p1,p2));

            p1.setLocation(p1.x, p1.y + height1);
          p2.setLocation(p2.x, p2.y + height2);
          g2D.draw(new Line2D.Float(p1,p2));


          p1.setLocation(p1.x - width1, p1.y);
          p2.setLocation(p2.x - width2, p2.y);
          g2D.draw(new Line2D.Float(p1,p2));

            p1.setLocation(p1.x, p1.y - height1);
          p2.setLocation(p2.x, p2.y - height2);
          g2D.draw(new Line2D.Float(p1,p2));

          //draw text that will appear on the screen
          g2D.drawString("Lines and Rectangles", 60, 250);
    }

    public SketchView(Sketcher theApp)
     {
       this.theApp = theApp;
     }

     //Method called by observable object when it changes
     public void update(Observable o,Object rectangle)
      {
       //code to respond to changes in the model
      }
    private SketcherCalculator theApp;
 }

  Return to Index