0% found this document useful (0 votes)
9 views6 pages

AWT (Abstract Window Toolkit) : Return Dopamine

Multiple Choice questions AJP

Uploaded by

Amar Gaikwad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views6 pages

AWT (Abstract Window Toolkit) : Return Dopamine

Multiple Choice questions AJP

Uploaded by

Amar Gaikwad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1.

AWT (Abstract Window Toolkit)

1.1 Components, Containers, Window, Frame, Panel

• Component: Base class for all GUI components (e.g., Button, TextField).
o Methods: setSize(), setVisible(), setBackground().
• Container: Holds components (e.g., Panel, Frame).
o Methods: add(Component comp), remove(Component comp).
• Window: Top-level container with no borders (e.g., Frame, Dialog).
o Constructor: Window(Frame owner).
• Frame: A resizable, top-level window with title and borders.
o Constructor: Frame(String title).
• Panel: A container to group components together.
o Constructor: Panel().

1.2 Creating Windowed Programs and Applets

• Applets: GUI-based programs embedded in web pages.


o Life Cycle Methods: init(), start(), stop(), destroy().
• Example for a Window:
• Frame frame = new Frame("My Frame");
• frame.setSize(400, 300);
• frame.setVisible(true);

1.3 AWT Controls and Layout Managers

• AWT Controls:
o Labels, Buttons, Checkbox, TextField, TextArea.
o Example: Button button = new Button("Click Me");
• Layout Managers:
o FlowLayout: Arranges components in a row.
o BorderLayout: Divides the container into regions (NORTH, SOUTH, etc.).
o GridLayout: Arranges components in a grid.

1.4 Use of Layout Managers

Layout Manager Description


FlowLayout Arranges components sequentially.
BorderLayout Divides into NORTH, SOUTH, etc. regions.
GridLayout Arranges in rows and columns.
CardLayout Allows flipping between panels.
GridBagLayout Advanced, flexible grid-based layout.

Return dopamine;
2. Swing

2.1 Introduction to Swing

• Features:
o Lightweight, platform-independent.
o Provides richer components than AWT.
• AWT vs Swing: |
• Aspect | AWT | Swing |
• |------------------|-----------------------------|-----------------------------------|
• | Components | Heavyweight (native) | Lightweight (Java-based) |
• | Look and Feel | OS-specific | Pluggable (customizable) |

2.2 Swing Components

• JApplet: Extended Applet class for Swing.


• JLabel: Display text or images.
o Constructor: JLabel(String text).
• JTextField: Editable text field.
o Constructor: JTextField(String text).
• JComboBox: Dropdown menu.
o Constructor: JComboBox(String[] items).

2.3 Buttons (JButton, Checkboxes, Radio Buttons)

• JButton:
o Constructor: JButton(String label).
o Methods: addActionListener(ActionListener l).
• Checkbox:
o Constructor: JCheckBox(String label).
• Radio Button:
o Constructor: JRadioButton(String label).

2.4 Advanced Swing Components

• Tabbed Pane: Allows tabbed navigation.


• Scroll Pane: Provides scrolling for components.
• Trees: Display hierarchical data.
• Tables: Represent data in rows and columns.
• Example for a Progress Bar:
• JProgressBar progressBar = new JProgressBar(0, 100);
• progressBar.setValue(50);

2.5 MVC Architecture

• Model: Manages data (e.g., database connections).


• View: Displays UI components.
• Controller: Handles user actions and updates Model and View.

Return dopamine;
3. Event Handling

3.1 The Delegation Event Model

• Event Sources: Objects that generate events (e.g., Button, TextField).


o Example: Button btn = new Button("Click");
• Event Listeners: Objects that handle events.
o Example: btn.addActionListener(new MyListener());

3.2 Event Classes

• ActionEvent: Triggered by buttons, menus, etc.


o Constructor: ActionEvent(Object source, int id, String command).
• ItemEvent: Triggered by item selection (e.g., Checkbox, Choice).
o Constructor: ItemEvent(ItemSelectable source, int id, Object item, int
stateChange).
• KeyEvent: Represents keyboard actions.
o Constants: KeyEvent.VK_A, KeyEvent.VK_ENTER.
• MouseEvent: Represents mouse actions (click, drag).
o Constants: MouseEvent.BUTTON1, MouseEvent.MOUSE_PRESSED.
• TextEvent: Triggered when text is modified.
o Constructor: TextEvent(Object source, int id).
• WindowEvent: Represents window actions (close, minimize).
o Example: WindowEvent.WINDOW_CLOSING.

3.3 Adapter Classes

• Simplify event handling by overriding only required methods.


o Examples: MouseAdapter, KeyAdapter, WindowAdapter.

3.4 Inner Classes

• Allow grouping listener code inside components.


o Example:
o button.addActionListener(new ActionListener() {
o public void actionPerformed(ActionEvent e) {
o System.out.println("Button clicked!");
o }
o });

3.5 Event Listener Interfaces

Interface Description
ActionListener Handles action events (buttons, menus).
ItemListener Handles item selection events.
KeyListener Handles keyboard events.
MouseListener Handles mouse click and release events.
MouseMotionListener Handles mouse drag and move events.
TextListener Handles text changes in TextComponent.
WindowListener Handles window state events.

Return dopamine;
4. Networking in Java

4.1 Socket Overview

• Client/Server Communication:
o Sockets facilitate communication between devices.
• Reserved Sockets: Ports reserved for specific services (e.g., port 80 for HTTP).
• Proxy Servers: Intermediary servers for requests.
• Internet Addressing: Identifies devices using IP addresses (e.g., IPv4, IPv6).

4.2 Java and the Net: Networking Classes and Interfaces

• Key Classes:
o Socket: For TCP connections.
o ServerSocket: To listen for incoming connections.
o DatagramSocket: For UDP connections.

4.3 InetAddress

• Factory Methods:
o getByName(String host): Returns InetAddress for a hostname.
o getLocalHost(): Returns the local host address.
• Instance Methods:
o getHostName(): Returns hostname.
o getHostAddress(): Returns IP address.

4.4 TCP/IP Client Sockets

• Whois: A protocol to query databases for domain info.


• Example:
• Socket socket = new Socket("hostname", 80);

4.5 URL

• Format: Specifies a web address (e.g., http://www.example.com).


• The URI Class:
o Used for parsing and manipulating URIs.
o Constructor: URI(String str).

4.6 URLConnection

• TCP/IP Server Sockets: Allows servers to accept incoming connections.


o Example:
o ServerSocket serverSocket = new ServerSocket(8080);

4.7 Datagrams

• DatagramPacket: Represents data for UDP communication.


o Constructor: DatagramPacket(byte[] data, int length).
• DatagramSocket: Sends/receives packets.
o Constructor: DatagramSocket(int port).
• Datagram Server and Client:
o Server listens on a port and processes packets.
o Client sends packets using send().
Return dopamine;
5. JDBC (Java Database Connectivity)

5.1 Introduction to JDBC and ODBC

• JDBC: API for connecting and executing queries in databases using Java.
• ODBC: Platform-independent interface to access databases.

5.2 JDBC Architecture

• Two-tier Model: Direct interaction between the client and the database.
• Three-tier Model: Client interacts with the server, which communicates with the database.

5.3 Types of JDBC Drivers

1. Type 1: JDBC-ODBC Bridge Driver.


2. Type 2: Native API Driver.
3. Type 3: Network Protocol Driver.
4. Type 4: Thin Driver (pure Java).

5.4 Driver Interfaces and DriverManager Class

• Connection Interface: Establishes a connection to the database.


• Statement Interface: Executes SQL queries.
• PreparedStatement Interface: Precompiled SQL queries for better performance.
• ResultSet Interface: Handles results from SQL queries.

5.5 Essential JDBC Program

• Steps:
1. Load the JDBC driver.
2. Establish a connection.
3. Create and execute a statement.
4. Process the results.
5. Close the connection.

Return dopamine;
6. Servlets

6.1 Life Cycle of a Servlet

• Stages:
1. Initialization (init method).
2. Request Handling (service method).
3. Destruction (destroy method).

6.2 Creating a Simple Servlet

• Servlet API: Defines classes and interfaces for servlets.


• javax.servlet Package: Contains core interfaces like:
o Servlet Interface: Basic functionality of a servlet.
o ServletConfig Interface: Provides configuration information.
o ServletContext Interface: Provides servlet-level information.

6.3 The javax.servlet.http Package

• HttpServletRequest Interface: Handles client requests.


• HttpServletResponse Interface: Constructs responses to clients.
• HttpSession Interface: Manages user sessions.
• Cookie Class: Represents cookies sent between the client and server.
• HttpServlet Class: Extends GenericServlet to support HTTP protocol.
• HttpSessionEvent Class: Represents events related to sessions.
• HttpSessionBindingEvent Class: Used for session attribute binding.

6.4 Handling HTTP Requests and Responses

• GET Requests: Retrieve information from the server.


• POST Requests: Send data to the server for processing.

6.5 Cookies and Session Tracking

• Cookies: Small pieces of data stored on the client-side.


• Session Tracking: Maintains stateful interactions with clients.

6.6 Introduction to JSP (JavaServer Pages)

• Simplifies the creation of dynamic web pages using Java.

Return dopamine;

You might also like