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

Questions on HW6-Spring08

Questions on HW6PART1-Spring08

Question: I get the following error when I try to compile the TurtleDrawingFileIO file: invalid method declaration; return type required. This is referring to my TurtleDrawing constructor. I changed everything it said to change, but are we supposed to add a constructor or remove one?

Question: I keep getting this error: non-static variable commands cannot be referenced from a static context. All I did was take the provided and everywhere it said TurtleDrawing, I put TurtleDrawingFileIO. Then I changed the method headers by copy and pasting out of the directions and put "return commands;" before the last bracket in the first two methods. What am I missing?

Question: In TurtleDrawingFileIO, when outputToFile() calls toString(), I get the following error message: "Error: non-static method toString() cannot be referenced from a static context." Are we really supposed to be renaming toString() to convertCommandsToString() as listed in the instructions?

Question: Are we supposed to be changing toString()'s name in the outputToFile() method too then? It doesn't say anything about that in the instructions. How does one reference static methods in main()? If there's no constructor, what do the methods work on?

Question: Using either extractCommands("commands2.txt"); or TurtleDrawingFileIO.extractCommands("commands2.txt"); in main() gives me a FileNotFoundException, even though commands2.txt is in the same folder as TurtleDrawingFileIO. What's causing this?

Question: Is JPanel supposed to be in java-source? TurtlePanel can't find it for some reason.

I've looked through everything I can find on Turtles, but can't find a "speed" variable or setter anywhere. How are we supposed to set the speed of a Turtle?
Nevermind, found it further down in the instructions...

Question: When I run the given for hw6 pt1, all it does is create a blank output .txt file. I have the command files open... ?

Question: What does this line mean, from the instructions about drawCommands(): "You should also add the incoming the LinkedList of new commands to the list of old commands."

Question: When I'm testing the TurtleDrawingFileIO methods in my main method, I'm having trouble figuring out how to use addMoreCommandsFromFile. It calls extractCommands, but never uses the result anywhere, and just returns the commands that you input to it without adding anything. Do we need to change the method in order to make it do something relevant, or am I missing something?

Question: In order to make all the variables global, do we need a Global class? Is there another way to go about making them global?

Question: I keep getting a NullPointerException on line 6. I have printed the commands LL and it is fine. For some reason it cant get the parameters out of the command. Do you know why?
    1public void drawCommands(LinkedList<TurtleCommand> commands){
    2  this.commands.addAll(commands);
    3  for(int i = 0; i < commands.size();i++){
    4   TurtleCommand command = commands.get(i);
    5   if(command.getType().equals("forward"))
    6    turtle.forward(command.getParameter(0));
          turtle.moveTo(command.getParameter(0), command.getParameter(1));

Question: When it says "add the incoming LinkedList of new commands to the list of old commands," how and where should we create the new LinkedList?

I'm unclear about which commands are "old" and which are "new". Are we pulling the "old" linked list (which I'm assuming will be called commands?) from TurtleDrawingFileIO?

Question: Why when I am trying to create a new TurtlePanel, in the TurtlePanel class, do I get the error (and I have imported all the necessary stuff at the top): Error: C:\cs1316\java-source-Fall06\ unreported exception; must be caught or declared to be thrown

Question: How can I call the outputToFile method we have on TurtleDrawingFileIO from the TurtlePanel class?

Question: I am confused on how you would make a turtle command out of setHeading?

I'm having trouble getting my window to show. I think my problem is one of two things: either my main method is wrong or I have not made the proper adjustments to my TurtleEtchASketch method (such as flow layout, i.e. layout manager).
Here is my main method:
public static void main(String[] args) {      
    JFrame frame = new JFrame();
    frame.setSize(400, 400);
    frame.setLocation(30, 60);
    TurtleSketchPanel sketch = new TurtleSketchPanel();

Everything works except for when we press the save, load, and shake buttons, it does what it is supposed to do, but when we press the up, down, etc. buttons afterwards, it won't draw. Why is this?

How are we supposed to use two layout managers? It's confusing because are we supposed to include them both somehow into the SketchPanel? Or are we supposed to use one in the SketchPanel and one in the EtchASketch?

I am getting an FileIO exception error in my TurtleSketchPanel. Its occuring within my ButtonListener class so its not allowing me to throw an exceptioin or do a try catch. I don't know where the problem is.

Does BorderLayout.NORTH and BorderLayout.SOUTH count as two different Layout Managers? We used it in the same "My Turtle Panel."

My ButtonListener works fine, but my TextListener keeps giving me the following error:
Error: TurtleSketchPanel.TextListener is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener. What's wrong?
Thanks for the above. All is working now. I was trying to use: textValueREMOVEDged(TextEvent te) instead of the actionPerformed method (I had found it in the java api). I still don't understand why it wouldn't work and why you need to have the actionPerformed method there in order to not get that error. Maybe it is something that would be easier for you to explain in person... if so, i'll ask you sometime.
i am confused about my load method, when i put the text in it will save, but it wont load up in java, if i look at the physical file, it exists

public void load() throws{
commands = new LinkedList();
String chosenFile2 = FileChooser.pickAFile();

and i added this to my main method panel.load();

OK, our save and load methods work when tested, but the save in certain cases just writes a blank file. For example if we press up, down, left, right and then press save, the file created by save is blank. However if we load an already filled file like commands2.txt and then save it, the save works.

heres our save button;

else if(source.equals(saveButton)){
newCommand = "save";
catch(Exception e){

Links to this Page