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

Questions on HW7-Sp2005

Questions on GUI and PictureTool?

ASK IT HERE!



Dr. Java doesn't recognize PictureTool as a constructor, but this error only happens when I try to put a picture in as input. I've tried declaring the picture in different places and making it null... what can I do to fix it?

I don't get your question. You have to define the class PictureTool and give it a construct that takes String filename as input. Does that help? Mark Guzdial


Quick question– i think i am missing something. When i try to apply clearBlue() using my button it keeps giving me this error, do i need to define the picture somewhere else?( the variable z is the picture that i set when i run the class).....
public PictureTool(String filenameP ){
super("Picture Tool");
//This is where we show the original picture
Picture z = new Picture(filenameP);
z.show();
"File: C:\j2sdk1.4.2_06\java-source\PictureTool.java [line: 80]
Error: local variable z is accessed from within inner class; needs to be declared final"
I made the same mistake! That's why I emphasized it in lecture. Your ActionListener's CANNOT access any method variables. They can only access instance (class-level) variables. You can only access method variables if they're "final" (unchanging)–which isn't of much use to anyone! Move z into an instance variable, do NOT declare it in your method, then everything should work. Mark Guzdial

should PictureTool extend JFRame? and also what does line 4 of this do?
1 public class GUItreeInteractive extends JFrame {
2  
3   public GUItreeInteractive(){
4     super("GUI Tree Interactive Example");

is it telling JFrame to make what's in quotes the title of the GUI box thing. you know you like the vocabulary.
Yes, PictureTool should probably extend JFrame. (You can do it other ways, but I've mostly shown you extending JFrame, so I recommend it – it's the easiest way to do it. Yes, REMOVEDe 4 is telling JFrame to go ahead and do its constructor – create a window, whose name is "GUI Tree Interactive Example." BTW, I do plan to be at my office hours 1-2 pm in Student Center today (Tuesday 29 March). Mark Guzdial



Maybe there is a slide set that better explains how to use instance variables

Maybe. You might also ask me in class – I do provide time for questions. Mark Guzdial


I get this error when I try to run Rhythm Tool...
"Error: Malformed left expression in assignment"
Know what it's about?

^ Never mind, it's gone now. But sometimes it comes up. I don't know why. And later on it works again.
Check out the left side of the equals sign in an assignment. Mark Guzdial

When im trying to scale, it doesnt seem to be reading the number that's in the text box, but instead is just using whatever i define "num" as in the action listener for the text box.
Remember that you have to hit RETURN in the text box for the actionListener to be triggered! Mark Guzdial



This is a great homework! I learned a lot.
I'm glad! Did you build a cool tool (one that you might find useful one day)? Mark Guzdial

How do you save the picture to the original place? I can make it save with a different name to a different place, but when I try to use the same variable the inner class error message comes up again.
Which error message? Mark Guzdial

Problem... when scaling the picture, I did "System.out.println(num);" and it shows up as 0.0 every time even though num should be whatever input the person put in.

Did you hit Return first? Remember that we talked about that in class. Mark Guzdial

I'm having trouble using flip(). At first I thought that it was broken, but I realized that it wasn't when I typed p.flip().show(); Then it worked. The same with p.flip().repaint(); It also works then, but the problem there is that the picture that PictureTool() opens, the title of the box it is displayed in is the path of the file, but when you use flip().show()/flip().repaint(), the title is changed from the path to literally "New Picture". Can anyone comment on why that happens and maybe a way to have it not do that.
as soon as i posted that, i think i thought of the answer. is it because flip() generates a new picture that isn't saved anywhere as a file. so by default it just names is "New Picture"?
and again, i really think that p.flip(); should work. why doesn't it?
Student50
Check out the code for flip() in Picture.java. Mark Guzdial

I just tried the rhythm tool and when I typed in repeat 2 times it didn't work. It would repeat 10 times. So then I figured out you have to press enter before it registers. =( It took me many hours to figure out such a simple thing. Oh well. Thanks.
YES! We did talk about that in class. Mark Guzdial

When saving the file, should you save it in the same place with the same filename or let the user decide where to save it?
The former is easier, the latter is nice for the user. The former is all that you have to do for this assignment, but the latter makes it a darn useful tool! Mark Guzdial

I can't get the file to save in the same place. filename is the variable name holding the filename, but when I try to access it, the error comes up...


button5.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
p.write(filename);
}
}



Error: local variable filename is accessed from within inner class; needs to be declared final
Is filename an instance variable, or a variable local to a method? Remember that ActionListeners can only access instance variables, not method variables. Mark Guzdial


^ Never mind, I got it. Whew, that was the hardest part of this homework. Getting saving right.

Everything works now, but whenever I save a scaled picture, my computer freaks out and closes Finder and restarts it. But it works. How strange.
WEIRD! What's your path? Maybe you're saving someplace unusual/unexpected by accident? Mark Guzdial

not an important question, just for aesthetics: is there a way to arrange the buttons more exactly within panels and sections? like if i want my 4 editing buttons in the center of a bordered panel but want 2 below the other 2...how would i go about doing that?
That's a rendering issue, right? There are lots of other kinds of layout managers in Java, including ones that let you specify exactly x,y where you want things to go. So, yes, you can do that. Find a good book on Swing. Mark Guzdial

is it okay if my scale creates a new picture? is it supposed to?
Yes, but close the old picture and open the new picture – see the new SimplePicture and PictureFrame java files that Sebastian posted on the Homework page. Mark Guzdial


for input, do you want the user to enter the entire location of the file? (C:/.../file.jpg) or just the filename and it's from a preset MediaPath?

when saving the picture, how can you change the path to be a new path so it doesn't save over the original image?
Student50

Here is my code for the color mantipulation...
//Button no. one for negation
JButton button1 = new JButton("Negate");
button1.addActionListener(
new ActionListener()
public void actionPerformed(ActionEvent e) {
Picture temp = p.negate();
p.close();
p = temp;
p.show();
}
}
);
panel2.add(button1);

I keep getting the following error:
Error: incompatible types
found : void
required: Picture

Which makes sense because "negate" doesn't return anything. But nearly none of our color mantipulation methods in Picture return anything. I'm really lost!

If it doesn't return anything, it changes "this" – the picture the method is called on. In that case, you don't assign anything. Mark Guzdial




Link to this Page