Lecture 11 | Programming Methodology (Stanford)
ฝัง
- เผยแพร่เมื่อ 11 มิ.ย. 2024
- Lecture by Professor Mehran Sahami for the Stanford Computer Science Department (CS106A). Professor Sahami lectures on GObjects, GImage, Gcompound, and Gpolygons. He then shows how to incorporate the mouse and keyboard into the graphics.
CS106A is an Introduction to the engineering of computer applications emphasizing modern software engineering principles: object-oriented design, decomposition, encapsulation, abstraction, and testing. Uses the Java programming language. Emphasis is on good programming style and the built-in facilities of the Java language.
Complete Playlist for the Course:
th-cam.com/users/view_play_list...
CS106A at Stanford Unversity:
www.stanford.edu/class/cs106a/
Stanford Center for Professional Development:
scpd.stanford.edu/
Stanford University:
www.stanford.edu
Stanford University Channel on TH-cam:
/ stanford
This is where the fun begins. Interesting how these concepts remain relevant almost 9 years on.
Quick tip for those having difficulties - go slow and work out the examples. Let me explain. As you progress with the lectures, you'll find yourself getting lost. This is fine. Its just your brain adjusting to new information. To truly understand new information, pause and repeat over and over till you get the concept cold. For example, i was having difficulties understanding the concept of coding the animation. So i took out the code and wrote it out with a pen. I went through it piece by piece trying to understand the reason behind each line of code. I did this repeatedly until i understood animation cold.
In summary, rewind, rewrite and repeat until you understand.
heyy, I have a doubt. I just started watching this playlist and I'm confused about how do I practice this stuff and how do I get started?. I'm using IntelliJ as my IDE and I don't know how to use acm libraries within it, because it gives me an error saying that It "Cannot resolve symbol acm". How do I actually implement this stuff? Is the code that I write based off on these lectures still valid in java 17? If not, how do I go about it?
He uses every second of lecture. Awesome.
2020 and still relevant. This guy is a legend. Love all the little jokes in between
heyy, I have a doubt. I just started watching this playlist and I'm confused about how do I practice this stuff and how do I get started?. I'm using IntelliJ as my IDE and I don't know how to use acm libraries within it, because it gives me an error saying that It "Cannot resolve symbol acm". How do I actually implement this stuff? Is the code that I write based off on these lectures still valid in java 17? If not, how do I go about it? How did you learn it? Do you gave any suggestions?
@@samagrabarnwal acm libraries as per my notice are not relevant now they are replaced with libraries like
import java.util.*;
and for gui there are swing libraries.
To stay updated about how to make input output GUI's in todays time do check out GFG and java docs. Lectures are great but in some places you need to crosscheck.
mehran we all are doing good.. we all love you
Topics: The GImage Class, The GPolygon Class, The GCompound Class, Event Driven Programs, The ClickForFace Program Example, Responding to Mouse Events, Responding to Keyboard Events, The UFO program Example
is about to be 2024 and we still rocking as Mehran would say
Prof Mehran is a great teacher. Whenever I think i'm lost in the book assignments I check the lectures and everything make sense again.
I learned more in a single lecture of this guy than my first semester at the school I graduated from. I don't know if it is Stanford or Mehran or both, but it is so great to have this videos out.
I'm in awe about the syntax!
Mehran is AMAZING
Mehran, Thank you so much. this is great
Hang in there guys
24:50 oh i LOVE this course. Good times!
Grate lecture Stanford. You really are a good teacher Mehran.
Mehran is the man, he is soooooooo gooooooooood!!!!
Anybody else having difficulty wrapping their head around parameters? Can anyone recommend a good resource for learning more about them and how they work? On a separate, unrelated note, this has 98,727 views. Lecture 1 has 1.5 million. Pat yourself on the back if you're still here.
My explanation is parameters are just the info an object uses. Oracle's Java docs are a great source in fact the source, docs.oracle.com/javase/tutorial/index.html
I know this is old, but think of parameters as things you are passing into the function container. The function container acts as an environment or a namespace for that particular function, and nothing exists in that container unless you either create it yourself explicitly by declaring and initializing a variable, or by passing in something from the outside when you call the function.
I know this is old but..
Imagine you are making a form for someone to enter their email address. You want to save that email address as a String. In order to save it, you need to receive it, and to receive it you take it in as a parameter. Using pseudo-code, you would do something like this:
public class User
private String emailAddress;
public void storeEmail(String newEmailAddress)
emailAddress = newEmailAddress;
The simplest example I can think of would be if someone needed you to write a method that adds two numbers together and returns the sum:
public int add(int num1, int num2)
int sum = num1 + num2
return sum
as he said in cdPlayer example , parameters are the disk itself , the device is the method("function"). . so parameter is the data u need the function to process but not all functions have parameters
STILL A LEGEND
what method should we use for our Breakout assignment, mouseMoved() or mouseDragged() ? . I mean our paddle moves when we move our mouse or when we click and drag the paddle?
@Preevailer The acm package is included in your Eclipse.
is it required to list out all the lengths and widths of the face (the eyes and stuff) as constants (private static final double) or is it just good style? couldnt you save time and just list them as normal variables (int ______ = 0.10)?
If anyone is having trouble with GImage, in the latest java version, I have found it best to put the image in the bin folder in the project in your workspace.
Another great lecture. Modified the bouncing ball code as Mehran suggested to get the bouncing face by using the GFace class and first, much to my disappointment it didn't work. Ecilpse gave back a message "GFace cannot be resolved to a type". Of course I hadn't a clue what that meant. Googling the error, though, I found our that this is known Eclipse bug and you can select Project, clean and it will get rid of it and now I have my bouncing face :-) Good times!!! Moving onwards and upwards!!
Does anyone have the complete code please?
It is very difficult for me to see it clearly on the screen, it looks very blurry.
Thank you.
i think most code is in the book
35:47: Mouse moved, mouse moved, mouse moved!!! :) Genius!
I searched for another source to learn more about Gcompound
but I didn't find anything . just this lecture. .
anybody know another source . tell us
@DillonSundance Well, I have a different java book and it uses exactly the same library's for the most part, so they aren't that random.
How is he creating a RandomGenerator object without extending the RandomGenerator class ?
Prof Mehran already gave you the hint: use getElementAt method. This method checks the front most object at that point.
i bought a book called java for dummies. but these lectures are way more usefull..
You can download a preliminary draft version of the book for free. It doesn't have some of the later chapters of the final version but chapter 8 of the draft is the one you'll want to use for the breakout assignment. It discusses the acm graphics library and event handling.
Where can I see the book and the assignment? Thanks
How i the standford system set up ? For example is 106A a freshmen level class still? Yes I am such randomly asking
Amazing teacher, I wish Mehran did TH-cam videos as well ❤️🩹
Just bought the original star wars DVD. "Its so good," Mehran Sahami.
Im having trouble with the GImage.
It just says it doesn't find my file, although it IS in the right folder...
The Eclipse IDE is being used through the entire course. Just start a new project and copy/paste the bouncing ball code from the handout. Also don't forget to add/link the acm library package to your project.
where can i get the slides used in the lecture?
Can someone please help me? Every time I try to run a program that uses GCompound it says that my acm.jar file is missing the source for GCompound. I have tried redownloading it and installing it various times but it still doenst work! Please any help will be greatly appreciated.
What you get choclates for asking questions?
I must extends Gcompound? ??
I'm having another problem with Breakout. I can get the ball by starting the game in the mouseevent but it loses focus on the screen so it appears as though the ball is sitting still and then all of a sudden it is at the bottom of the screen. I guess there needs to be a away to put focus on the canvas after the mouse listener event, or on the ball. I can run the start game in the run method but it just starts as soon as the game loads, so I suppose another option would be to have a loop in the run method that is waiting for the mouse click and then proceed within the run method, but I suspect the code should execute inside the mouseclick method.
+m3tafunj Just found the answer: there is a waitForClick() method. You can find out about it if you read the YEAH notes at: web.stanford.edu/class/archive/cs/cs106a/cs106a.1134/handouts/yeahBreakout.pdf
WHICH software , he uses for bouncing ball ed?
I wish that this video could be of better quality because sometimes it can he hard to see the text in eclipse. I really like the videos though.
when making the Breakout program i got to the problem that when i try to make the collisions with the bricks it only collided with one of those bricks, I guess that this is cous i add the bricks with a for loop and i assume that after it is placed only the canvas remembers its there but my program overwrites it with the next brick of the for loop? is there a way around it??
obviously if won't collide with multiple bricks at once. It can go to another brick after colliding with another brick though, but the ball will collide with one brick at once.
I'm trying the code for the mouseTracker, but I'm getting this error:
The source attachment does not contain the source for the file JTFTools.class.
Heres my code:
import acm.graphics.*;
import acm.program.*;
import java.awt.event.*;
public class MouseTracker extends GraphicsProgram{
private GLabel Label;
public void run(){
Label = new GLabel("");
Label.setFont("Times new Roman - 36");
add(Label,50,50);
addMouseListeners();
}
public void mouseMoved(java.awt.event.MouseEvent e){
Label.setLabel("Mouse: ('" + e.getX() + ", " + e.getY() + ')');
}
}
If someone could help I would apreciate it.
Try getting the book. The Art of Science of Java by Eric S. Roberts. Of course without looking at your code, no one can tell where you may have gone wrong. Good luck.
@xVerbati nvm he asked if you can rotate polygons, anyone know how?
at 37:19 in the screen on mousetracker program ......why is it label = new GLabel(""); and not ....GLabel label = new GLabel(""); the first one in running well but second one is showing error
because he has already declared the label variable or in this case object.
How do you get the ACM library working in eclipse? I downloaded the stanford eclipse version and I downloaded a file called acm.jar, what do I do with acm.jar?
Open it?
I have GFace Class in my workspace ,I run "click for face" program ,but it doesnt work ...
somebody help me please !!!
I'm trying to write the breakout program without having to create 5 different functions for creating each color row. I'm not sure how to set the color element anyway other than hard coding it though. SetColor(Color.red) works but SetColor.(Color.strColor) where strColor = "red" doesn't work.
Any ideas?
setColor is method, SetColor is a class.
if you use method , it's need parameters. I think Color.red is call the method red of class Color, and it return specific value has type method setColor require.
The easy way to know is read javadoc of that Class you used.
if there is only an imaginary reference point how did the compputer know where to draw that first point?
is add a function and not a method?
Ye, I found it already, thanks anyways :) Adding libraries in pretty darn easy, I think I'll find it hard to go back to C++.
Agreed
:]
Mehran is hilarious!
The Art and Science of Java by Eric S. Roberts
why is the quality not as good?
entropy
what did the guy ask at 11:25???
I'm watching the lectures but for some reason this one Lecture 11 the video quality is quite bad. I'm watching it on a 55 inch TV and still can barely make out some of the characters. A current (2017) version of this Java tutorial would be great maybe in 2018 since it would be ten years anniversary of the original. Lots of changes to Java and video technology. Actually I just thought this is more than likely filmed on MiniDV tape there wouldn't have been any good consumer digital sources in 2008.
Yeah but the problem is getting another professor like Mehran to teach it...
Mehran can make even some of baddest of students to pay attention on his teaching ..
Lot of examples in youtube ... LOL me tooo
@S2h6699
if you look at it that way, he also forgot the class, braces, etc
He sure likes to say funky a lot.
The S in String and System should be lower cased.
26:40 SEND OUT MY MINIONS!!!!
@ddubs123 You probably already know the answer by now seeing as your comment is 9 months ago, but i'll tell you anyway, they're the same thing, function is basically just the term in the c++ language as in java they are called methods, and since he probably teaches both, he prob gets em mixed up but it doesn't matter.
BouncingFace.EXEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE!!!
Create a project. Right click 'src'. Chose 'Build path' --> Configure build path. Select the 'Libraries' tab. Click Add external .jars button. Pick the file. When you do it right, acm.jar is listed under Reference Libraries and you can import in your classes.
"...an hour and a half later I was like, 'whoo, there it is!' and then I wept."
@chen viewed
i took this course and all I got was diabetes
If you need methodologies more than java doc start from 14:00 minutes
28:52 I have not even graduated from highschool and why am i getting called out like that(;-;)
Has anyone completed the breakout assignment just by watching these videos? I'm been trying to get through the assignments just with the videos, but without a book or a teacher to ask questions it is very difficult and I can't make my paddle move in one direction only :/
I completed it just now. I know, I'm a bit late.
follow "caiyuhui" in twitter to discuss...
Y is this program not working??
import java.awt.event.*;
import acm.graphics.*;
import acm.program.*;
public class MouseEvent extends GraphicsProgram {
public void run() {
addMouseListeners();
}
public void mouseClicked(MouseEvent e) {
GRect rect = new GRect(30,30);
add(rect, e.getX(), e.getY());
}
}
Try using public void init() { instead of run method.
M0stBlunt3d Thanks for your suggestion, but it worked later. My java was broken, so I downloaded A different version of eclipse.
Curran C Doddabele how did you get it to work? What version of Eclipse are you using. I've been struggling with the import Java awt. I've got the latest JDK but it won't allow me to import.
change the method mouseMoved(MouseEvent e){} to moveMoved(java.awt.event.MoseEvent e){} then it will work...you don't need to import java.awt.event.*; for this.
then i wept...
Shhh...
No talking in class.
He did a bouncing face out of his roomate's face when he was our age!
Sounds like you have a corrupted workspace.
So here's the fix:
First remove the folder containing your "face" program from the Eclipse workspace panel. (Right click on folder, click delete).
Next, locate "root" folder containing your "face" program on your PC.
Double click ".metadata"
Double click ".plugins"
Right click on "org.eclipse.core.resources", then click delete.
Now re-import folder with your "face" program to the Eclipse workspace.
.
Should now work like a dream...
Incorrect.
why is the quality of the video becoming shittier with every lecture, i can barely read the code when mehran is presenting it now...
17:38 He totally lost it.
I think he's done this a few times! Ya think? LoL!
The translation form english to chinese is bad,like a japanese class.
i was just kidding
1 person got rejected from Stanford
Click for Face? Hmmm.
use the god dam microphones
cheese anyone?