Monday, August 30, 2010

My head is about to explode.

OK, so its day two of my actual give a damn experience w/ learning anything since I've been out of high school. As such, i'm seriously putting an effort into learning Java, however this book is a pretty big bite to eat here and i'll show you why.


This snippet of code was taken from one example in the second chapter of the book, and its not a "copy/paste" bit of code, it won't compile for you with just this.


String theMessage;
 int messageX = 125, messageY = 95; // Coordinates of the message

 public HelloComponent2( String message ) {
  theMessage = message;
  addMouseMotionListener(this);
 }

 public void paintComponent( Graphics g ) {
  g.drawString( theMessage, messageX, messageY );
 }

 public void mouseDragged(MouseEvent e) {
  // Save the mouse coordinates and paint the message.
  messageX = e.getX( );
  
  messageY = e.getY( );
  repaint( );
 }
 
 public void mouseMoved(MouseEvent e) {}


All this code was done on a version of the always welcome "Hello World!" application that every book and tutorial takes the student through. Technically this isn't the first "Hello World!" application in the book, but it is in fact in the same chapter as the first example. I'm only on chapter two in the book and this is a snippet of what I've learned so far. The first example was fairly surprising, the author took an approach i hadn't yet seen before where you were taught how to make a window with the text in it rather than just a command line "Hello World!" program. I can honestly say i was surprised in a very pleasant way, I've always wanted to learn to do that and this book took me right there.

Only two sections later and I now have code that not only displays the words in a window, it also allows for interaction with the mouse, which the code shows if you know Java. There are still three sections left to go through for the second chapter and i'm still pleasantly surprised by it, however I had to take a break because my head was full of Java code so early in the evening.

For those that are counting, I'm not only two and a half chapters into this book with 24 chapters (not including the Appendix sections), I've got a program that says "Hello, World!" and another program that says the same but I can drag across the window area with my mouse. As far as the value of the book to me, it just raised up a notch. I'm very happy with it.

No comments:

Post a Comment