Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Data file to specify instances of Drawable objects.

Posted on 2003-12-11
16
289 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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
 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

839 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