CS1103 Learning Guide Unit 7 - Actions and Buttons, Complex Components and MVC
This week’s primary learning content includes Swing components, Model-View-Controller (MVC) design pattern, and web server programming. First, for Swing components, I learned about actions and buttons. Specifically, buttons include: (a) commonly used buttons and some components related to buttons, including push buttons, checkboxes, radio buttons, menu items, toolbars, icons on buttons, HTML on buttons, and keyboard accelerators; (b) some complex components, including lists, tables, documents and editors; (c) custom components. Second, for the MVC design pattern, I realize that when one designs an application, he/she can divide it into three components: Model, View and Controller, and different parts correspond to different responsibilities, which is beneficial to the code maintainability, reusability, and testing (). Regarding web server programming, I learned how the client sends a request to the server and how the server responds, and I implemented this process with code. Furthermore, I mastered using telnet or browser to test my web server program in the implementation process. Finally, it is worth mentioning that I was not sure which class to choose to handle the different I/O streams when I was writing the web server program, so I summarized these classes as follows:
In the discussion forum, I explained in detail how Model-View-Controller (MVC) “decouples data access, business logic, data presentation, and user interaction” (UoPeople, n.d.), and referenced the codes written by Banas to explain MVC further. I didn’t create my own program because Banas wrote his example so well that I don’t feel like I could write a better code to explain MVC than this one. Specifically, Banas uses a calculator example to explain MVC. He creates three classes, namely CalculatorModel, CalculatorView and CalculatorController. As the class names suggest, these three classes correspond to Model, View and Controller, respectively. In the class CalculatorModel, Banas used the method addTwoNumbers() to calculate the sum of two numbers, which corresponds to data acquisition and business logic processing of the Model; in the class CalculatorView, Banas used the Swing component to visualize the calculation results, which corresponds to the data presentation of the View; in the class CalculatorController, Banas called the method addTwoNumbers() in the CalculatorModel to get the sum of the two numbers, and then called the setCalcSolution() function of the class CalculatorView to transmit the sum to the View for display, which corresponds to the user interaction and internal-organizational logic of the Controller. Through studying the above code, I have a deeper understanding of the MVC design pattern.
Before doing my programming assignment, I did not have the confidence to write a robust web server program. But when I finished the code, and all the functions passed the tests, I felt proud of it. Specifically, after completing my web server program and testing it with telnet and browser, I was surprised to find that the program could successfully receive the request header information from telnet. According to the request header information, the server program could return different error codes (400, 403, 404, 500, 501) and corresponding HTML pages. On the telnet or browser side, they can also receive response information from the server. After seeing these results, I felt encouraged and realized that sometimes we could accomplish things that seem impossible and then be amazed by the results.
Word count: 671
References
1.Pastor, P. (2010, March 24). MVC for Noobs. Envatotuts+.
https://code.tutsplus.com/tutorials/mvc-for-noobs--net-10488
2.Banas, D. (2013). MVC JAVA TUTORIAL.
http://goo.gl/deVk5
3.UoPeople. (n.d.) Discussion Forum Unit 7.
https://my.uopeople.edu/mod/forum/discuss.php?d=734554