Java Day Four: Method Time

Today, I stepped back into code land. With my layout complete from my last session, I started on methods so the buttons would actually do something when clicked. Note: in the button’s description, you must add the “onClick” part, otherwise it is an inactive button. I needed to have the program to have the id of the button to perform the button-specific task. So, I call it.

method2

This is what I see when I look at the code now.

method3

Int means integer. This code wouldn’t actually fly. Computers like their naming done in a particular way.

method4

This is code to simply add digits to the output screen corresponding to the button pressed.

Try Block

The concept of the try block is fabulous. Say there’s an input that does not compute, like divide by zero or letters or whathaveyou. Without the try block, the program crashes. The try block “catches” exceptions like that and essentially says “chill, we just won’t do this one.” I like computers. They are really dogged. They will try to the point of crashing. But, that trait really isn’t desirable when life hands you so many exceptions. So, the try block will be that code that I imagine will come up a lot. Thanks, try block.

method5

This is for a particular application found on the internet. I did not use Protein as a variable for my calculator app.

Boolean Logic

Today, I used my first “or” statement in programming. It was:ย io_value == “0”||io_value == “-0.” I’ve never used pipes for anything and now I get to use the “double pipe.” More fun operators here. My favorite part about this is the symmetry of that equation. I’ve forgotten the elegance of mathematics. This time was hooking up the number pad and the tricky plus or minus button. Next session will be quite tricky, actual functions.

Advertisements

About KC

I am Katarina Countiss, a multimedia designer. I like blogs, games, art and technology. I am curious about how things are made.
This entry was posted in App. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s