Applets using Swing Components Object Oriented Programming using
Applets using Swing Components Object Oriented Programming using Java Computer Science/Application Mr. K. Ravindra M. Tech. K. R. K. Govt. Degree College, Addanki Email. Id: ravi. btech 2002@gmail. com
Learning Objectives At the end of the session, students will able to v Explore the Swing Components v Demonstration of Simple Applet with Swing Components 2
Swings ▪ Swings provides the event-driven, light weight, platform independent and pure java components which are built on AWT. ▪ Swings were introduced with Java Foundation classes, in 1997, completely incorporated in JDK 1. 2. ▪ JApplet is used for creating applets using swings which is derived class of java. applet. Applet. ▪ swings have 18 packages but generally, most programmers use the following packages: javax. swing and javax. swing. event. ▪ In Swings, All components are named like Jxxx, e. g. , JApplet, JFrame, JButton, JLabel, etc. 3
Swings (Contd. ) ▪ In Swings, we uses the java. swing. JApplet class which is subclass of java. applet. Applet. ▪ The lifecycle of a JApplet is same as the life cycle of an applet. ▪ We can override any of the life cycle methods whichever is required by our swing applet. ▪ Swing is not thread safe. When creating a swing GUI, you need to take extra care if multiple threads are accessing it. 4 For more Info: https: //docs. oracle. com/javase/7/docs/api/javax/swing/package-summary. html
Swing Components ▪ Components present in AWT are all present in swings, e. g. , Check. Box (JCheck. Box), Radio. Button (JRadio. Button and Button. Group), Button (JButton), Label (JLabel), Text. Field (JText. Field), etc. ▪ Apart from this we have a special type of button known as toggle button, when clicked upon remains selected and state of the toggle button becomes deselected on clicking again. ▪ Apart from the layouts introduced in AWT, a few new layouts have been introduced in swing package as well. For example: Box. Layout, Spring. Layout etc. ▪ The Box. Layout places all the components in a single row or column. Without making it complex, we can put more than one panel in horizontal and vertical directions, similar to Grid. Bag. Layout. ▪ The Spring. Layout is a very flexible layout in the sense that it does not place components on its own but according to the constraints specified by the put. Constraint method. 5
Sample Applet Program with Swing Components Objective: Addition of 2 Numbers The applet enables the user to enter 2 numbers, Click the Compute SUM button, and the applet displays the sum of the given 2 numbers. 6
Summary ▪ Swings are light weight platform independent classes to develop flexible GUI. ▪ Swings is built on AWT. ▪ Swings have additional components and layouts over AWT. 7
References Web Links: 1. Programming in Java by Prof. Debasis Samanta, IIT, Kharagpur, NPTEL Swayam course. 2. https: //condor. depaul. edu/jpetlick/extra/212/GUIs. htm 3. https: //docs. oracle. com/javase/7/docs/api/java/applet/Applet. html Text Books: 1. Core Java: An Integrated Approach, Authored by Dr. R. Nageswara Rao &Kogent Learning Solutions Inc. 2. E. Balaguruswamy, Programming with JAVA, A primer, 3 e, TATA Mc. Graw-Hill Company. 3. John R. Hubbard, Programming with Java, Second Edition, Schaum’s outline Series, TMH. 4. Deitel& Deitel. Java TM: How to Program, PHI (2007) 5. The complete reference JAVA 2, Hervert schildt. TMH. 8
THANK YOU
- Slides: 9