AWT (Abstract Window Toolkit) : Return Dopamine
AWT (Abstract Window Toolkit) : Return Dopamine
• 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().
• 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.
Return dopamine;
2. 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) |
• JButton:
o Constructor: JButton(String label).
o Methods: addActionListener(ActionListener l).
• Checkbox:
o Constructor: JCheckBox(String label).
• Radio Button:
o Constructor: JRadioButton(String label).
Return dopamine;
3. Event Handling
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
• 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).
• 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.5 URL
4.6 URLConnection
4.7 Datagrams
• JDBC: API for connecting and executing queries in databases using Java.
• ODBC: Platform-independent interface to access databases.
• Two-tier Model: Direct interaction between the client and the database.
• Three-tier Model: Client interacts with the server, which communicates with the database.
• 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
• Stages:
1. Initialization (init method).
2. Request Handling (service method).
3. Destruction (destroy method).
Return dopamine;