Solved

Data file to specify instances of Drawable objects.

Posted on 2003-12-11
16
287 Views
Last Modified: 2010-03-31
These following questions contain code to the first and second parts of my code. This final questions asks how to combine the 2 separate programs together

1      This stage is essentially a repeat of the first prototype, except that the data file needs to specify instances of Drawable objects. The GUI should also be modified appropriately to hold a list of Drawables in place of Shapes with corresponding changes to the paintComponent() method.
2      The list of Drawables in the GUI Component of part 1 could be a Picture!
Rename the ShapeListComponent as DrawableComponent. Replace the ArrayList attribute with a Drawable attribute, and the setList() method with a setDrawable(). In a separate class create a Picture object and pass this to the Component to display.  Test your program with several picture data files.



The following links contain code i posted before to do the first and second parts of my program.


//program which uses the drawable interface.
http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_20822187.html


//program which reads in file data and creates shapes on screen.
http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_20815673.html

//interface thar tags drawable objects.
http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_20812032.html

Other posts have been made by me based on this program. Please check my question history to rebeal them all.

Hopefully the final question for me on this program.




0
Comment
Question by:k1ngp1n99
  • 10
  • 6
16 Comments
 
LVL 92

Expert Comment

by:objects
ID: 9924443
We can't write it for you, but we can certainly help you if you have problems with your code or need specific suggestions on how to proceed.
0
 

Author Comment

by:k1ngp1n99
ID: 9924475
objects the same level of help you gave in the other questions i asked is fine. This stuff is for next year when i study graphical user interfaces. These type of questions are the ones i will have to answer based on information i have.
0
 
LVL 92

Expert Comment

by:objects
ID: 9925661
if you can try yourself , I can help you fix any problems you have in your code.
0
 

Author Comment

by:k1ngp1n99
ID: 9926812
i get the following error in two of my programs if i get this fixed im sure i can do the above question. Also objects how would you implement this into my gui. Is it like this or something

Picture.addDrawable(Line,10,10);


';' expected  while (i.hasNext())
import java.util.*;
import java.awt.geom.*;
import java.awt.Graphics2D.*;
class Picture implements Drawable
{
   private ArrayList Drawables = new ArrayList();

   public void addDrawable(Drawable d, int x, int y)
   {
      Drawables.add(new PictureComponent(d, x, y));
   }

   public void draw(Graphics2D g, int ax, int ay)
   {
      Iterator i = Drawables.iterator()
      while (i.hasNext())
      {
          PictureComponent d = (Drawable) i.next();
          g.draw(g, ax, ay);
     }
      }
}


cannot resolve symbol

symbol  : class Graphics2D
location: class PictureComponent
   public void draw(Graphics2D g, int ax, int ay)


class PictureComponent implements Drawable
{
   private Drawable D = null;
   private int X = 0;
   private int Y = 0;

   public PictureComponent(Drawable d, int x, int y)
   {
      D = d;
      X = x;
      Y = y;
   }

   public void draw(Graphics2D g, int ax, int ay)
   {
      D.draw(g, X+ax, Y+ay);
   }
}

0
 
LVL 92

Expert Comment

by:objects
ID: 9927084
> ';' expected  while (i.hasNext())
>       Iterator i = Drawables.iterator()

need a semicolon on the end of this line

      Iterator i = Drawables.iterator();

> cannot resolve symbol

add the following import:

import javax.swing.*;
0
 
LVL 92

Expert Comment

by:objects
ID: 9927093
sorry ignore that last one the import should be:

import java.awt.*;

And remove the following statement:

import java.awt.Graphics2D.*;
0
 

Author Comment

by:k1ngp1n99
ID: 9927138
Picture component is free of error but class picture comes up with 2 more errors. And also when implementing into my GUI do i use something like Picture.addDrawable(Line,10,10);

C:\Documents and Settings\kingpin\My Documents\Work\Software construction\Project Draw\completed\prototype2\Picture.java:13: cannot resolve symbol
symbol  : class Graphics2D
location: class Picture
   public void draw(Graphics2D g, int ax, int ay)
                    ^
C:\Documents and Settings\kingpin\My Documents\Work\Software construction\Project Draw\completed\prototype2\Picture.java:18: incompatible types
found   : Drawable
required: PictureComponent
          PictureComponent d = (Drawable) i.next();
0
 
LVL 92

Expert Comment

by:objects
ID: 9927247
Add the import:

import java.awt.*;


> PictureComponent d = (Drawable) i.next();

should be:

Drawable d = (Drawable) i.next();

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 92

Expert Comment

by:objects
ID: 9927256
>  do i use something like Picture.addDrawable(Line,10,10);

yes
0
 

Author Comment

by:k1ngp1n99
ID: 9927284
Get a totally new error now.

C:\Documents and Settings\kingpin\My Documents\Work\Software construction\Project Draw\completed\prototype2\Picture.java:19: draw(java.awt.Shape) in java.awt.Graphics2D cannot be applied to (java.awt.Graphics2D,int,int)
          g.draw(g, ax, ay);
           ^
1 error
0
 
LVL 92

Expert Comment

by:objects
ID: 9927329
that line should be:

d.draw(g, ax, ay);
0
 

Author Comment

by:k1ngp1n99
ID: 9927372
Picture.addDrawable(Line,10,10); doesnt seem to work even though it looks correct
0
 
LVL 92

Expert Comment

by:objects
ID: 9927446
how exactly isn't it working?
0
 

Author Comment

by:k1ngp1n99
ID: 9927466
C:\Documents and Settings\kingpin\My Documents\Work\Software construction\Project Draw\completed\prototype2\Proto1.java:20: cannot resolve symbol
symbol  : variable Line
location: class Proto1
            Picture.addDrawable(Line,10,10);
                                    ^
C:\Documents and Settings\kingpin\My Documents\Work\Software construction\Project Draw\completed\prototype2\Proto1.java:20: non-static method addDrawable(Drawable,int,int) cannot be referenced from a static context
            Picture.addDrawable(Line,10,10);
                       ^
2 errors
Finished
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 9927574
Sorry I thought Picture and Line were variables.
You need to create a Picture, and a Line, and add the line to the Picture:

eg.

Line line = new Line(20, 20);
Picture picture = new Picture();
picture.addDrawable(line, 10, 10);
0
 
LVL 92

Expert Comment

by:objects
ID: 9930907
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What is the latest versions eclipse neon 2 140
jar file executable 12 42
eclipse shortcuts 9 45
couple of eclipse 5 25
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
The viewer will learn how to implement Singleton Design Pattern in Java.

920 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

15 Experts available now in Live!

Get 1:1 Help Now