Change Contents of the Bubble
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Questions on HW5-Sp2005

Questions on weaving and replacing in a picture list?

Ask 'em here!



I've added a requirement to HW5 to provide a test class with a main() method to demonstrate your work. Mark Guzdial


No customers at my last office hours this week–hope that means that all is well. I'll try to be on-line when I can while at SIGCSE. If you're curious about what a professor does at one of these conference (I mean, besides the all-night parties! :-), check out my SIGCSE2005 Schedule. See you next week! Mark Guzdial

Are we supposed to add the methods weave and replace in PictNode.java?
It's your choice which of the various picture nodes to modify, but YES, the weave and replace methods go in the class of the linked list element. Mark Guzdial

I realize now that I will need some guidance on hw5. I thought I knew what to do on Monday, but that has proved fruitless. I have been trying to write a weave for picture nodes modeled after song nodes but haven’t had much success. Instead of beating a dead horse all night, I would like to ask for general guidance on how I should go about mainly writing the weave method. Will Wednesday’s lecture help here?
If you look at the lecture, yes, you will see how weave and replace are implemented for the sound nodes. That'll give you another example to work from. Mark Guzdial

since we don't have a "count" in the weave function for the HW... but our example in sound does... do we need the method to read the lenght of the linked list?
The count parameter in the SongNode.weave function doesn't contain the number of nodes in the list, it indicates how many times the new node should be woven into the list. The version we are implementing for picture is a more general form that weaves in the new picture until it reaches the end of the list. Hint think while instead of for loop. Student24

great advice jonny!

what is the goal of this hw in terms of what we show. should our main method actually show the pictures in our linked list? copy to a canvas?

The learning goal of this homework is for you to write methods that manipulate a linked list, not just use one. Go look at the Homework assignment, again. Your main() method should show THREE pictures, at different stages of testing your methods. Mark Guzdial


Does someone have office hours tomorrow (Friday) between 12-1 or after 3?

Office hours have been posted for a while now. Check out http://coweb.cc.gatech.edu/cs1316/5

Why am i getting this error "Error: cannot resolve symbol
symbol : variable current" when i try to compile the file LayeredSceneElement. I also get a similar error when i try to compile PictNode, but the error class for it is "drawable node" I am using the 3 java files that are currently on the homework5 page. I've tried recompiling just about everything. Any ideas?

The error cannot resolve symbol: variable current means that you are using a variable current that can't be accessed. Is it declared? If it's in LayeredSceneElement, could you send me the line number so that I can check it? Thanks! Mark Guzdial

I have modified the HW5 due date to be next WEDNESDAY, not next MONDAY. I've also moved Quiz 2 to Friday. See the Syllabus Mark Guzdial


HEY!! How's it going on HW5? Are people getting close? Is it working well? I'm very curious, wondering way out here in Missouri! Mark Guzdial


The error is on line 137 in LayerSceneElement line 5 in PictNode. Right now im just trying to go through the lecture slides and doing all the examples so i understand the homework, so there is no modified code- I'm lost right now though as to what the cause of the problem is. Thank you
LayeredSceneElement.java has a comment in my line 137. That link (to LayeredSceneElement.java) is a copy of the file that I'm using. Try downloading it and compiling that. REMOVEDe 5 of PictNode is the declaration, so I'm guessing that DrawableNode needs to be recompiled. Just open it, and hit Compile All. Do let me know how it goes, please! Mark Guzdial



There seems to be a problem with the version of Picture.java you link to in the homework assignment...The file just ends in the middle of the Chromakey method.
  public void chromakey(Picture target, Color bgcolor, int threshold,
                        int targetx, int targety)
  {
    Pixel currPixel = null;
    Pixel newPixel = null;

    // loop through the columns
    for (int srcx=0, trgx=targetx; srcx<getWidth() && trgx<target.getWidth(); srcx++, trgx++) 
    {
     
      // loop through the rows
      for (int srcy=0, trgy=targety; srcy<getHeight() && t


That's the end of the file. 64kb in size. Student36

Is anybody else having this problem? Using Mozilla Firefox, I just clicked on the file, and chose "save to disk" when it prompted me. The entire file downloaded for me. #4


In response to "Just open it, and hit Compile All. Do let me know how it goes, please", i ended up just having to download the most recent zip of the java source folder. Works fine now though
EXCELLENT! Thanks! Mark Guzdial

I'm having trouble getting 3 different pictures to come up when i run my main method... any suggestions?
What happens? Mark Guzdial

I think my methods are working... I'm having trouble getting my results to show, though, cause the methods are void... big long scary errors like NullPointerException. Thanks!
NullPointerException means that you're using a variable name that has no value in it. Can you tell me what line it looks like, and maybe I can help with that? Mark Guzdial

somehow I don't have DrawableNode.java? so my PictNode won't compile since it;s supposed to extend.
Grab it out of the .zip file I uploaded to the Syllabus page. Mark Guzdial


Please don't delete the questions box



I also had trouble with not having DrawableNode or whatever the classname was. When is this assignment actually due? I had looked at the schedule on the Coweb which said Wednesday, but now I'm noticing dirty little rumors about the deadline having come and gone on WebCT.
It's due Wed. WebCT and I are fighting, but I'll get it changed there, too. Mark Guzdial

I'm not sure i actually understand what makeClone() is supposed to do, and how to implement it... I think it would be node1.makeClone() but that doesnt seem to do much.
node1.makeClone() should make a copy of node1–it'll return a new one. You need that if you're going to create a whole bunch node1's repeated. Mark Guzdial


Can this be done using "PositionedSceneElement"? I'm thinking not since I can't use the "replace" method on a "PositionedScenceElement" in that I have to use it on a "Root Element" of some sort. But since I have no idea how any of the "tree" picture elements work, I'm forced to look at the "PositionedSceneElement" class. Is there any chance of me being able to make a replace method for "PositionSceneElement" class?
Yes, absolutely! You can use ANY of the picture linked lists for this assignment! Mark Guzdial

Questions about it all?




Okay, I got it now. WebCT now knows that HW5 is due at 10 pm Wed. night. Mark Guzdial


i think i'm really lost.
so are we supposed to create our own methods of weave and replace? and then make a class named PictureTest, testing them?

Yes. Exactly. Mark Guzdial


what about just adding a main method to the bottom of the class?
Yeah, you could, but we haven't really talked much about doing that. And since main() methods are pretty non-object-oriented, I actually prefer that they be used only in a class of their own. But it's not wrong if you decide to do it that way. Mark Guzdial

My problems come when I call my methods in the command area on a linked list, like this:
PictureElement yeahbuddy = new PictureElement(new Picture(FileChooser.pickAFile()));

> PictureElement its = new PictureElement(new Picture(FileChooser.pickAFile()));

> PictureElement gonna = new PictureElement(new Picture(FileChooser.pickAFile()));

> PictureElement work = new PictureElement(new Picture(FileChooser.pickAFile()));

> yeahbuddy.setNext(its); its.setNext(gonna); gonna.setNext(work);

> PictureElement now = new PictureElement(new Picture(FileChooser.pickAFile()));

> yeahbuddy.weave(now, 2);

> now.show();

java.lang.NullPointerException:
at javax.swing.ImageIcon.loadImage(Unknown Source)
at javax.swing.ImageIcon.setImage(Unknown Source)
at PictureFrame.updateImage(PictureFrame.java:84)
at PictureFrame.initFrame(PictureFrame.java:145)
at PictureFrame.(PictureFrame.java:57)
at SimplePicture.show(SimplePicture.java:334)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)

Do I need a drawFromMeOn method? I haven't found one that I can write myself separate from turtles or DrawableNode... Can you extend a class from more than one superclass? This one already extends Picture... can it extend Turtle or DrawableNode, too?
Why are you telling now to show? Isn't the first node in your list yeahbuddy? It looks to me like now doesn't have a picture – that's where it seems to be dying in your code. You can certainly USE turtles in your methods without extending another class. (No, in Java, any subclass only has one superclass – you can only extend from one class.) You can also use the drawFromMeOn in DrawableNode and modify it to create one in PictureFrame. Mark Guzdial



Why am i getting this error..."Error: cannot resolve symbol
symbol : method weave (SceneElement,int)
location: class SceneElement"
I realize that it is because weave is expecting a PictNode Type and im sending it a sceneElement.... my question is how do i change the variable type or maybe im messing up on the weave function. Any suggestions would be helpful. Thank you.
At first, I was going to suggest making your call to weave like this: root.weave((SceneElement) myPictNode,5);. That's a cast. But here's another issue: PictNode isn't a subclass of SceneElement. A variable of type SceneElement can automatically take a PictNode – if PictNode was a subclass of SceneElement. But that's probably not your issue either – if you're getting "cannot resolve symbol" then DrJava can't even find your weave. Is it spelled right? (Remember that case counts!) Is it in the right file/class? Mark Guzdial

I wrote my weave method in SceneElement, and most of it works (like i can actually execute it...), but I'm having trouble visualizing the for loop involved.
for (int i=1; i <= EndOfREMOVEDkedList ; i++)
like...the EndOfREMOVEDkedList part obviously is not what should be there, but how do I notate it so that i = the max in the linked list since there's no automatic getwidth or anything?
You don't use a for loop. You should be using a while. You use a for loop when you can count how many times you want to do something. You want this to execute for as long as necessary to get through the loop – use a while. Look at the examples from class. Mark Guzdial


weave is spelled correctly and all that mess, i think my problem falls in the last question you asked... "Is it in the right file/class", im pretty sure thats my problem so im going to play with that for awhile- Thank you.

I am having difficulty in locating how getFileName(); is defined. I was hoping that I could redefine it for the class I am making, but I have yet to see where you have typed the code to read it. I haven't seen it anywhere in the files in the java-sources folder. So can you tell me where the method getFileName() is defined?
getFileName() is actually defined in SimplePicture. Mark Guzdial
 /**
  * Method to get the file name associated with the picture
  * @return  the file name associated with the picture
  */
 public String getFileName() { return fileName; }


I'm still confused where to place our weave and replace methods. You keep mentioning that we have other options than PictNode. Like what? Please help!
Weave and Replace should be within the class of your linked list elements. It could go in PositionedSceneElement or LayeredSceneElement, if you want to use those lists. It could go in SceneElement if you want to use SceneElementLayered or SceneElementPositioned. I've given you several choices for picture linked lists – you can use any of those. Mark Guzdial

When I replace, its like the kitty, flower, swan, horse, grave example from class. So, my picture is replaced, but the other pictures aren't in the same place, only the replaced pic. Is that okay?
The pictures aren't in the same place? That sounds like you accidentally changed the linked list structure. That wouldn't be the right thing to do. Mark Guzdial

In my replace method, the replacement only works when there is just one node to replace; if there are more - it replaces the first one, and after i run my main() it only shows the list up until that one +the very next one, but that's it. i'm out of ideas, please help
You actually COMPLETELY answered your own question. If it stops at that node, then the next link must be null, right? How about if you make it point to the rest of the list instead – then it would keep going, right? Consider using insertAfter for inserting your new node? Mark Guzdial

public void replace(Picture oldpic, Picture newpic)
  {
    PositionedSceneElement current=this;
    PositionedSceneElement next=this;
    PositionedSceneElement newone=new PositionedSceneElement(newpic);
    int x=1;
    
    while(x!=0)
    {
      next=current.getNext();
      if (next.getPicture()==oldpic)
      {
        current.remove(next);
        current.insertAfter(newone);
      }
      current=current.getNext(); //if i move this line under the if statement, it gives an error too
      if (current.getNext()==null)
        x=0;
      
    }

What is x doing here? Why do you need X if you're doing a replace? Recall that I did give you a replace for sounds last week – you might start from that. For example, I don't recommend removing and re-inserting nodes to do the replace – just swap out the Picture. Mark Guzdial

Yikes! This drawFromMeOn thing has me a little confused... this is what happens:
FileChooser.setMediaPath("C:\\Documents and Settings\\localadmin\\My Documents\\My Pictures\\Car Hotties\\");

> PictureElement good = new PictureElement(new Picture(FileChooser.getMediaPath("MyBaby.jpg")));

> PictureElement thing = new PictureElement(new Picture(FileChooser.getMediaPath("MyBaby2.jpg")));

> PictureElement Im = new PictureElement(new Picture(FileChooser.getMediaPath("MyBaby3.jpg")));

> PictureElement stubborn = new PictureElement(new Picture(FileChooser.getMediaPath("VetteZ06.jpg")));

> Picture bg = new Picture(FileChooser.getMediaPath("BMW_z4.jpg"));

> good.setNext(thing); thing.setNext(Im); Im.setNext(stubborn);

> good.drawFromMeOn(bg);

Error: No 'drawFromMeOn' method in 'PictureElement'
> bg.drawFromMeOn(good);

Error: No 'drawFromMeOn' method in 'Picture'
> good.drawFromMeOn();

Error: No 'drawFromMeOn' method in 'PictureElement'
> good.drawFromMeOn(thing);

java.lang.NullPointerException:
at SimplePicture.getBasicPixel(SimplePicture.java:259)
at Pixel.getColor(Pixel.java:183)
at Picture.chromakey(Picture.java:1838)
at PictureElement.drawMeOn(PictureElement.java:129)
at PictureElement.drawFromMeOn(PictureElement.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)

What could I do to improve? Thanks! ;)
We gave you a few different drawFromMeOn implementations. There should be one in one of the linked list classes that you're using. It should be in the same class your replace() and weave() methods – PositionedSceneElement, LayeredSceneElement, or SceneElement. Mark Guzdial

Code from class

public class PSETest {
  public static void main(String [] args) {
    FileChooser.setMediaPath("D:/cs1316/mediasources/");
    
    Picture dog = new Picture(FileChooser.getMediaPath("dog-blue.jpg"));
    PositionedSceneElement dognode = new PositionedSceneElement(dog);
    PositionedSceneElement dognode2 = new PositionedSceneElement(dog);
  
    Picture tree = new Picture(FileChooser.getMediaPath("tree-blue.jpg"));
    PositionedSceneElement treenode = new PositionedSceneElement(tree);
    PositionedSceneElement treenode2 = new PositionedSceneElement(tree);
    
    treenode.setNext(dognode); dognode.setNext(treenode2);
    treenode2.setNext(dognode2);
    
    Picture bg = new Picture(400,400);
    treenode.drawFromMeOn(bg);
    bg.show();
    
    Picture house = new Picture(FileChooser.getMediaPath("house-blue.jpg"));
    treenode.replace(dog,house.scale(0.25));
    
    Picture bg2 = new Picture(400,400);
    treenode.drawFromMeOn(bg2);
    bg2.show();

  }
}


I've got a block in my mind. I have some code for weave, and it weaves my robot into my image one time (so it's not actually continuing to weave). Could you please point me to where in this code it should continue the weaving?
public void weave(PositionedSceneElement newelement, int nn) 
  {
    PositionedSceneElement current = this; // Start from here
    PositionedSceneElement copy; // Where we keep the one to be weaved in
    PositionedSceneElement oldNext; // Need this to insert properly
    int skipped; // Number skipped currently
    
      copy = newelement.makeClone(); // Make a copy
      
      //Skip nn nodes
      skipped = 1;
      while ((current.getNext() != null) && (skipped < nn))
      {
        current = current.getNext();
        skipped++;
      };
      
      if (current.getNext() == null) // when we get to the end...
      {
        System.out.println("Duh, the next of current is equal to null.");
        return; // just return this
      };
      
      oldNext = current.getNext(); // Save its next
      current.insertAfter(copy); // Insert the copy after this one
      current = oldNext; // Continue on with the rest
    }

Student48



nevermind, weave is now working. Student48

You've got the problem that we talked about in class today. You're creating your copy BEFORE the loop. You need to make a new copy each time you insert one. Mark Guzdial


My weave is similar to the one posted above, but i am getting the problem "cannot resolve symbol method makeClone() location positionedSceneElement" I know this means that makeClone() is not in PositionedSceneELement My question is how do i use makeClone().... or maybe im putting my weave in the wrong file


public void weave(PositionedSceneElement nextOne, int skipAmount)
{
PositionedSceneElement current = this; // Start from here
PositionedSceneElement copy; // Where we keep the one to be weaved in
PositionedSceneElement oldNext; // Need this to insert properly
int skipped; // Number skipped currently
//copy = nextOne.makeClone(); // Make a copy
while ((current.getNext()== null))
{
copy = nextOne.makeClone(); // Make a copy
That use of makeClone() looks good to me. Let me see where we defined makeClone()...Mark Guzdial


makeClone() is in PictNode which is why its probably not working... so are you saying i need to modify makeClone() and put it in PositionedSceneElement?

Yup! You'll have to make your own. Pictures understand "copy," so just make a copy of the picture. It's really not a hard method to write. Mark Guzdial


alright– got that done with

Well, atleast it runs now.. although the weaving doesnt actually do anything.. im just going mess around with it for a while

Thanks for the help, much apperciated.

My weave is only putting one pic in, instead of continually until the linked list is over. Here's what the while loop looks like:
while ((current.getNext() != null) & (skipped n))
{
current = current.getNext();
skipped++;
};
and the oldnext, copy, insertafter commands are outside of the loop...what's going on?

my weave is compiling and running, along with my other code, but i am getting the same pic for canvas one and two...any advice?

As we talked about in class this morning – if you're making the copy BEFORE the loop, then you won't get multiple copies. If there is only one copy of the picture you're weaving in, then only one picture can show up. Mark Guzdial




Link to this Page