Just finished downloading the EE SDK (which contains the GlassFish Server) and Eclipse IDE for EE. Cam showed me how to create an HTML and Java logic page, host it to a local server, create some tables in HTML and use Java to create buttons and a dialogue box.
Awesome stuff, I feel I am one step further to grasping classes, methods, constructors, creating instances of such and passing data. I believe something has clicked in my linear programmed head regarding objects NOT being variables or confusing objects with being a part of Java syntax. An object is an object! A tangible, manipulative thing which has methods that are used to describe that object, using variables and parameters. Classes are ways to organize and sort these objects.
It took my awhile to get this, Cam had stated that I was doing well with the "hard" concepts, but missing out on this easy, essential and important concept of Java.
2 comments:
Heh...I'm not sure if The Eclipse IDE contains Glassfish. I think it's NetBeans that contains glassfish. Although, we weren't using Glassfish at all - we were sticking with the Google Web Toolkit (GWT) and the Google App Engine (GAE). Netbeans and Glassfish will wait for another day. Given though, everything we did COULD be deployed to Glassfish if we so choose.
Let's get cracking on the exam. You saw how to display a textfield and a button. You even saw some code to maniuplate various wicket/GUI objects when a button was clicked. How can we go one step further and actually have an online question working.
We want to set it up like this. Just one question, and when a user clicks "SUBMIT" or something we can tell they if they are right or wrong.
Q. What do you call a fish without an eye?
a) Blinky
b) One eyed fish
c) fsh
d) Sue
Maybe we then have a TextBox where the user types in a, b, c or d and a submit button. When someone clicks the submit button, we pop up a window that tells them if they are right or wrong.
Of course, that means we need a clickhandler.
class QuestionHandler implements ClickHandler{
}
And if the ClickHandler is to be used to figure out what someone typed into a TextBox, well, it must be 'using' or 'working with' or 'composed of' a textbox. So, we can say the ClickHandler 'uses' a TextBox in code by adding one in as a property.
class QuestionHandler implements ClickHandler{
TextBox answerBox;
}
And of course, when someone creates a QuestionHandler, how do they do it? I keep saying to you "How do you create Xyz?" The answer is always:
XYX xyz = new Xyz():
You get it right until you code a class, then you start saying:
int xyz = new ClickHandler - or something like that.
To create a new Something, it's always:
Something something = new Something();
(REPEAT THAT ALL DAY LONG)
HOWEVER, every QuestionHandler needs a TextBox, so if you create one using the default constructor that takes no arguments, it becomes possible to create a QuestionHandler with a null TextBox. So, we create a custom Constructor:
And if the ClickHandler is to be used to figure out what someone typed into a TextBox, well, it must be 'using' or 'working with' or 'composed of' a textbox. So, we can say the ClickHandler 'uses' a TextBox in code by adding one in as a property.
class QuestionHandler implements ClickHandler{
TextBox answerBox;
public QuestionHandler(TextBox tb) {
answerBox = tb;
}
}
Now, when someone creates a QuestionHandler, they must provide a TextBox:
TextBox box = new TextBox();
QuestionHandler qh = new QuestionHandler(box);
Notice that when the QuestionHandler gets created, it is passed in a real TextBox? A real instance?
A questionhandler is associated with a TextBox, so when you create a QuestionHandler, you need to provide one to the constructor.
Neat stuff!
Post a Comment