(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