Solved

Data file to specify instances of Drawable objects.

Posted on 2003-12-11
16
286 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
countHi challenge 25 85
create a gui in perl 3 46
GUI builder for Eclipse? 8 11
VB Script to add site to Java Exception List 4 18
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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

760 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

22 Experts available now in Live!

Get 1:1 Help Now