| ||||||||||
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 |
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 |
1 public class GUItreeInteractive extends JFrame { 2 3 public GUItreeInteractive(){ 4 super("GUI Tree Interactive Example");
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. You might also ask me in class – I do provide time for questions. Mark Guzdial |
Check out the left side of the equals sign in an assignment. Mark Guzdial |
Remember that you have to hit RETURN in the text box for the actionListener to be triggered! Mark Guzdial |
I'm glad! Did you build a cool tool (one that you might find useful one day)? Mark Guzdial |
Which error message? Mark Guzdial |
Did you hit Return first? Remember that we talked about that in class. Mark Guzdial |
Check out the code for flip() in Picture.java. Mark Guzdial |
YES! We did talk about that in class. Mark Guzdial |
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 |
button5.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
p.write(filename);
}
}
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 |
WEIRD! What's your path? Maybe you're saving someplace unusual/unexpected by accident? Mark Guzdial |
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 |
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 |
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 |