APJ-I - Lab1 - Introduction Swing Application Programming I Module 1: Introduction to Swing Lab Guide for Lab1 Session Objectives In this session, you will be practicing with Container Components Lightweight Components Common Methods of Swing Components Part – Getting started (30 minutes) Create a Frame using AWT (10 minutes) The following code show a Frame (AWT toolkit) with title: “Testing components” and contains a Button and a Label Create a java application and add a class named AcceptNameAWT and copy following code to AcceptNameAWT class (15 minutes) Scan the code first, type the code, compile, run and observe the result import java.awt.*; class AcceptNameAWT extends Frame { TextField txtName = new TextField(20); Label lblName = new Label("Name :"); public AcceptNameAWT (String title) { super(title); setLayout(new FlowLayout()); add(lblName); add(txtName); } public static void main(String args[]) { AcceptNameAWT ObjAccName = new AcceptNameAWT ("Testing components!"); ObjAccName.setSize(300,200); ObjAccName.setVisible(true); } } Create a JFrame adding component (20 minutes – Use Netbeans) © 2011 FPT-Aptech Page / APJ-I - Lab1 - Introduction Swing Create a JFrame contains a JLabel, a JButton and when the button is pressed, the label’s text change from “old name” to “new name” Part – Workshops (30 minutes) Quickly look at workshops for Module for reviewing basic steps Try to compile, run and observe the output of sample code provided for related workshop Discuss with your class-mate and your instructor if needed Part – Lab Assignment (60 minutes) Do the assignment for Module carefully Discuss with your class-mates and your instructor if needed © 2011 FPT-Aptech Page /