Introduction To Java Programming Language
105606Module 5: Introduction to AWT and Applets
1(g). Event handling in Java commonly follows the: (i) Delegation event model (ii) Sequential event model (iii) Inheritance event model (iv) Compilation event model20262m
Module 5: Introduction to AWT and Applets
View this question on its own page →Event handling in Java commonly follows the:
(i) Delegation event model
(ii) Sequential event model
(iii) Inheritance event model
(iv) Compilation event modelWorked SolutionAnswer: (i) Delegation event model
In Java GUI programming, an event source (such as a button) generates an event and delegates handling to registered listener objects. The listener implements an interface such as
ActionListener.MermaidDiagramRendering diagram…1(i). AWT stands for: (i) Advanced Window Technology (ii) Application Window Tool (iii) Abstract Window Toolkit (iv) Abstract Web Toolkit20262m
Module 5: Introduction to AWT and Applets
View this question on its own page →AWT stands for:
(i) Advanced Window Technology
(ii) Application Window Tool
(iii) Abstract Window Toolkit
(iv) Abstract Web ToolkitWorked SolutionAnswer: (iii) Abstract Window Toolkit
AWT is Java's Abstract Window Toolkit, a GUI library providing components such as
Frame,Button,Label, andTextField. Many AWT components use native operating-system peers.8(b). Construct an AWT application containing a frame, label, text field and button. Develop an event-handling mechanism that displays a message when the button is pressed.20267m
Module 5: Introduction to AWT and Applets
View this question on its own page →Construct an AWT application containing a frame, label, text field and button. Develop an event-handling mechanism that displays a message when the button is pressed.
Worked SolutionAWT event-handling example
import java.awt.*; import java.awt.event.*; public class GreetingApp { public static void main(String[] args) { Frame frame = new Frame("Greeting"); Label label = new Label("Enter your name:"); TextField input = new TextField(18); Button button = new Button("Greet"); Label output = new Label(" "); Panel panel = new Panel(); panel.add(label); panel.add(input); panel.add(button); panel.add(output); button.addActionListener(e -> output.setText("Hello, " + input.getText())); frame.add(panel); frame.setSize(420, 120); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { frame.dispose(); } }); frame.setVisible(true); } }The button is the event source.
addActionListenerregisters a listener; a click generates anActionEventand invokes the handler. The window listener closes the frame cleanly.9(d). Write a short note on Applets and Applet Parameters.20267m
Module 5: Introduction to AWT and Applets
View this question on its own page →Write a short note on Applets and Applet Parameters.
Worked SolutionApplets and applet parameters
A Java applet was a small Java program designed to run inside an applet viewer or browser plugin. Applets historically used lifecycle methods such as
init(),start(),stop()anddestroy(). Modern browsers no longer support Java applets, so they are a legacy topic rather than a current deployment choice.Parameters could be passed in HTML using
<param name="color" value="blue">and read withgetParameter("color").public void init() { String color = getParameter("color"); if (color == null) color = "blue"; // use the parameter in applet initialization }MermaidDiagramRendering diagram…For modern applications, use standard desktop, web or mobile technologies instead.