Answer To: AUR30405 Certificate III in Automotive Mechanical Technology ICTPRG525 – Student Assessment 1...
Shweta answered on Aug 23 2021
Order 63801/Assessment Task 1.docx
Assessment Task 1
1.
a) Steps to create Keyboard3 java file using JCreator are:
i) Open JCreator from Start Menu
ii) Select File -> New -> Project
iii) Click Next button to select a Basic Java Application
iv) Click Next button and type name of file as “Keyboard3”
v) Click Finish button
vi) In project creation window click on Finish button
vii) Will see window with class Keyboard3 with main function.
Another way is to create directly a java file instead of project in such a way
· Open Jcreator form Start Menu
· Select File-> New-> File
· In window open, select java class
· Click Next and Finish
b) A class java.applet.Applet which is inherited by general java class, here in our case Keyboard3 is designed in such way that it is embedded in the webpage to generate the dynamic content. It runs inside the browser and works at client side. An applet differs from a Java application in that it has no main method, instead, it starts form method called init.
c) Applet subclass init() method is an entry point for applet class. It is used to initialized the Applet. It is invoked only once on other hand paint() is method of component class (java.awt), it is used to paint the Applet. It provides Graphics class which is used for drawing different object like line, oval, arc, rectangle etc.
d) Instance variables are variable which are defined within the class but outside the class methods. Instance variables hold the value for more than one method, constructor or block, Here in Keyboard.java class instance variables are: width, height, x, y, s, backbuffer, backg.
Local variables are variables which are defined within a method, constructor or block. It is created when enter a particular method. Here is class Keyboard3 there is only one local variable within a method “keyTyped” of char datatype “c”.
There are different methods in class Keyboard3:
1) Init() is used to initialize the Applet, within this there are different methods
· getSize().width method is inherited from the superclass JApplet. It is used to get width of an applet
· getSize().height is a method to get height of an applet.
· serBackground() is a method to set the background color of Applet. It is defined in init() method to change color as soon as the applet is initialized.
· createImage() is a method to create an image of particular width and height which is passed as parameter.
· Image.getGraphics() is a method to create a graphics context for drawing to an off-screen image.
· backg.SetColor() sets color of graphics image.
· Graphics.fillRect() is a method to fill the specific rectangle and is filled with a current color.
· Graphics.setColor() is again called to change the color of rectangle to green.
· addKeyListener(this) is a key listener interface which is used to notify whenever the state of key is changed.
· addMouseListener(this) is a mouse listener interface which is used with any GUI component to handle state change of mouse.
2) keyPressed(KeyEvent e), keyRealeased(KeyEvent e), keyTyped(KeyEvent e) are methods found in key listener interface.
3) KeyTyped is used to handle event when something is typed using keys. Here within this method some methods are used such as
· getKeyChar() to get characters and put them in string.
· drawstring(s,x,y) is method to text output in a swing window. Here, s is a string that can be displayed on the screen. x and y are the variables that hold the x and y position on the graphical window.
· repaint() is used whenever update method is called along with call to the paint method, repaint() method clears the current window calls the update method and afterwards call paint().
4) mouseEntered(MouseEvent e), mouseExited(MouseEvent e), mousePressed(MouseEvent e), mouseRealeased(MouseEvent e), mouseEntered(MouseEvent e) and mouseClicked(MouseEvent e) are methods of the mouse listener interface.
5) mouseClicked(MouseEvent e) is used to handle event when mouse is clicked. Within this used getX() and getY() method to get value of x and y and then used repaint().
6) Update() is used to update the current graphics, followed by usage of paint() method. Here used:
· Graphics.drawImage() is a method to draw specific image at specific location. Here, it is drawing rectangle image.
· Graphics.setColor()sets the color of image.
· Graphics.drawLine(x1,y1, x2, y2) is used to draw a line from coordinates (x1,y1) to coordinates (x2,y2)
7) Paint() at the end paint method is called to paint and in this update is called.
e) Event handling methods used in class Keyboard3 are:
1) 1) MouseEvent: use the listener interface MouseListener. It is initialized using addMouseListener(this) method. mouseEntered(MouseEvent e), mouseExited(MouseEvent e), mousePressed(MouseEvent e), mouseRealeased(MouseEvent e), mouseEntered(MouseEvent e) and mouseClicked(MouseEvent e) are methods of the mouse listener interface.
2) 2) KeyEvent: use the listener interface KeyListener. It is initialized using addKeyListener(this) method. keyPressed(KeyEvent e), keyRealeased(KeyEvent e), keyTyped(KeyEvent e) are methods found in key listener interface.
f) Steps to run java program:
1) Jcreator: From the menu select Run -> Run File and...