OOPS JAVA M5 Solved Ktunotes - in

Download as pdf or txt
Download as pdf or txt
You are on page 1of 26

St.

Thomas
Institute For Science and Technology
Trivandrum

Department of Computer Science and Engineering

Object Oriented Design and Programming


S3 CSE
Module 5
(Important Topics)

Kerala Technological University

St.Thomas Institute For Science and Technology - S3 CSE OOD 1


Downloaded from Ktunotes.in
Q. Write an example for application of Event Handling
• Handling MouseEvents ( Explained in next slide)
• Handling KeyEvents ( Explained in later slides )

Downloaded from Ktunotes.in


Q. Explain with a program for MouseEvents
• To handle mouse events, you must implement the MouseListener and the MouseMotionListener interfaces
• The following applet demonstrates the process. It displays the current coordinates of the mouse in the applet’s
status window. Each time a button is pressed, the word “Down” is displayed at the location of the mouse
pointer.
• Each time the button is released, the word “Up” is shown. If a button is clicked, the message “Mouse clicked”
is displayed in the upperleft corner of the applet display area
• As the mouse enters or exits the applet window, a message is displayed in the upper-left corner of the applet
display area.
• When dragging the mouse, a * is shown, which tracks with the mouse pointer as it is dragged. Notice that the
two variables, mouseX and mouseY, store the location of the mouse when a mouse pressed, released, or
dragged event occurs.
• These coordinates are then used by paint( ) to display output at the point of these occurrences.
• Inside init( ), the applet registers itself as a listener for mouse events. This is done by using
addMouseListener( ) an addMouseMotionListener( ), which, as mentioned, are members of Component. They
are shown here:
• void addMouseListener(MouseListener ml)
• void addMouseMotionListener(MouseMotionListener mml)

Downloaded from Ktunotes.in


Downloaded from Ktunotes.in
Downloaded from Ktunotes.in
Q. Explain with a program for KeyEvents
• To handle keyboard events, implement the
KeyListener interface.
• When a key is pressed, a KEY_PRESSED event is
generated. This results in a call to the keyPressed( )
event handler.
• When the key is released, a KEY_RELEASED
event is generated and the keyReleased( ) handler is
executed.
• If a character is generated by the keystroke, then a
KEY_TYPED event is sent and the keyTyped( )
handler is invoked. Thus, each time the user presses
a key, at least two and often three events are
generated.
• The following program demonstrates keyboard
input. It echoes keystrokes to the applet window
and shows the pressed/released status of each key in
the status window.

Downloaded from Ktunotes.in


Q. Explain components and containers used in AWT or Draw the Component Class Hierarchy in Java

Downloaded from Ktunotes.in


Downloaded from Ktunotes.in
Downloaded from Ktunotes.in
Downloaded from Ktunotes.in
Q. Explain how Frames are created in awt with example

We can create a GUI using Frame in two ways:


1) By extending Frame class
2) By creating the instance of Frame class

Downloaded from Ktunotes.in


Extending the Frame Class

Downloaded from Ktunotes.in


Creating Frame by creating instance of Frame class

Downloaded from Ktunotes.in


Q. Write a AWT Program to use TextField and
Button

Output:

Name:

Add Edit Delete Search

Downloaded from Ktunotes.in


Q. List some of the containers and components used in Swing

Downloaded from Ktunotes.in


Q. Difference between Swing and AWT

Downloaded from Ktunotes.in


Q. Explain JDBC ( Java Database Connectivity) or Explain how ( steps) a java application is connected to a
database using JDBC with a sample program. ( Very Important )

Downloaded from Ktunotes.in


Downloaded from Ktunotes.in
Steps for Connecting a Java Application and database

Downloaded from Ktunotes.in


Downloaded from Ktunotes.in
Downloaded from Ktunotes.in
Downloaded from Ktunotes.in
Downloaded from Ktunotes.in
Downloaded from Ktunotes.in
Eg: Sample Program for JDBC Connection

Downloaded from Ktunotes.in

You might also like