Adv Java

1. What Is the Java Technology 2. Points to keep in mind for pyramid. 3. Java Pyramid Program on type 1 4. Java Pyramid Program on type 2 5. Java Pyramid Programs on Type 3 6. Java Pyramid Programs on type 4 7. Java Pyramid Programs on type 5 8. Classes and Objects 9. Recursive functions 10. Constructors in Java 11. Method Overloading 12. Constructor Overloading 13. Inheritance in Java 14. Interface in Java 15. Method Overriding and Hiding Method 16. The final keyword 17. Exception Handling 18. Properties, System & Runtime Class in Java 19. Building Java GUI 20. Layout Managers 21. Menu Bar 22. Applets 23. Threading 24. Java Netwoking 25. Programs for Science and Engineer 26. Prg to demonstrate pre and post increment 27. Prg to convert Farenheit to Celsius temperature 28. Prg to convert kilogram to different units 29. Prg to calculate surface area and volume of sphere 30. Prg to calculate frequency 31. Prg to determine co-ordinate points 32. Prg to determine Equilateral, Isosceles or Scalene triangle 33. Prg to demonstrate conditional operator 34. Prg to calculate Final and initial interest amount 35. Prg to separate entered number 36. Prg to examine while loops and conditions 37. Prg to calculate number of year 38. Prg to find Armstrong number or not 39. Prg to find all Armstrong number 40. Prg to find limited Armstrong number 41. Prg to find Armstrong number using user defined function 42. Prg to find frequency of student 43. Prg to find maximum and minimum number 44. Prg to print number triangle 45. Prg to print vertical number triangle 46. Prg to print number triangle 47. Prg to print binary right angle triangle 48. Prg to print * triangle 49. Prg to to print rhombus 50. Prg to print entered number triangle 51. Prg to to find nCr and nPr 52. Prg to enter an element in array 53. Prg to sort number using array 54. Prg to find the position of element in array 55. Prg to find the position of element in array using boolean flag 56. Prg to add one extra element in an array 57. Prg to find the equation of line 58. Prg to find the common element from two array 59. Prg to find the highest scorer 60. Prg to create a square of number 61. Prg to create Pascal triangle 62. Prg to subtraction, multiplication and division using methods and classes 63. Prg to determine salary grade 64. Prg for complex number 65. Prg to calculate area 66. Prg for Greatest Common Divisior 67. Prg for displaying studenta mark sheet 68. Prg for demonstrating inheritance 69. Prg to calculate area of triangle 70. Prg for calculating volume of sphere or hemisphere 71. Prg for demonstrate classes 72. Prg for employee details 73. Prg for demonstrating super and base class 74. Prg for Bank Account 75. Prg for professor and student details 76. Prg for Addition, Multiplication and finding Transpose of two matrix 77. Prg for counting number of words in a string 78. Prg to count number of vowels and consonants in a string 79. Prg to fine number of upper case, lower case, white spaces and digit in a string 80. Prg to fine number of upper case, lower case, white spaces and digit in a string without inbuilt function 81. Prg to arrange a string in alphabetic order 82. Prg to count the number of character occurrence in a string 83. Prg to find the string length and character position 84. Prg for converting first character of word into upper case 85. Prg for demonstrating vectors for manipulating records 86. Prg for manupulting items record using vectors 87. Prg for bank transaction 88. Prg for counting number of days between any two different date 89. Prg for exception handling 90. Prg for throwing exception 91. Prg for exception 92. Prg to throw exception when number is invalid 93. Prg for renaming the current thread 94. Prg for demonstrating strat method of thread 95. Prg to demonstrate sleep and and join method of thread 96. Prg to demonstrate yield method of thread 97. Prg for demonstrating thread in class inheritance 98. Threading program using runnable interface 99. Thread program using sleep 100. Java Applet program for creating fancy round eye 101. Java Applet program for creating fancy face 102. Java Applet program for drawing string 103. Java Applet program for creating fancy face 104. Java Applet program for displaying fancy fonts 105. Java Applet program for drawing and filling rectangle 106. Java Applet program for creating house 107. Java Applet program to show lifecycle of applet 108. Java Applet program for creating polygon 109. Java Applet program for creating rectangle 110. Java Applet program for drawing line 111. Java Applet program for getting applet width and height 112. Interview Question & Answer part 1 113. Interview Question & Answer part 2 114. Interview Question & Answer part 3 115. Interview Question & Answer part 4 116. Interview Question & Answer part 5 117. Interview Question & Answer part 6 118. Interview Question & Answer part 7 119. Interview Question & Answer part 8 120. Interview Question & Answer part 9 121. Interview Question & Answer part 10 122. Interview Question & Answer part 11
Pr.Pg Next Pg

Building Java GUI tutorials

  • GUI, which stands for graphical user interface, refers to that portion of a program that the user visually sees and interacts with.

  • The GUI is an essential part of programs that run on windows-based operating systems such as Windows, Macintosh, and Unix.

  • Almost every Windows program you have used is probably a GUI program: for example, Microsoft Word or Internet Explorer.

  • When Java was first released in 1995, it contained a GUI API referred to as the Abstract Windowing Toolkit (AWT).

  • This API contained classes like Frame to represent a typical window, Button to represent buttons, Menu to represent a window’s menu, and so on. The classes and interfaces of the AWT are in the java.awt packages.

  • Nowadays, most Java GUI programming is done by using Swing. We will still discuss the AWT in this course, though, because it is an important part of GUI programming, and many of the AWT classes are used in Swing, includingthe layout managers, and event-handling classes and interfaces.

  • After you understand the way a GUI is created, you will find that using AWT and Swing is the same in terms of developing the code. For example, creating and using a Button in AWT is very similar to creating and using a JButton, Swing’s version of a GUI button. And the event-handling code behind the scenes is exactly the same, no matter if you are using a Button or JButton.


Creating Windows

  • The basic starting point of a GUI is the container because you need a container before you can start laying out your components.

  • The java.awt.Frame and javax.swing.JFrame classes are containers that represent a basic window with a title bar and common windowing capabilities such as resizing, minimizing, maximizing, and closing.

  • The Frame class is used for AWT programs and is the parent class of JFrame, which is used for Swing programs.

  • Below is the simple program which creates the Window or a Frame in AWT:



Example: Java program for creating frame

 Sam Madam

//Program name

//Java program for creating frame

import java.awt.Frame;

public class AWTFrame


public static void main(String[] args)


Frame fr=new Frame("cbtSAM");

fr.setSize(400, 350);






Creating Windows using Swing

  • The javax.swing.JFrame class represents a window similar to Frame, except that JFrame adds support for the Swing component architecture.

  • From a user’s point of view, a JFrame and a Frame look the same. Creating and displaying a JFrame is also similar to creating and displaying aFrame. However, a JFrame is different in terms of how components are added to the JFrame. As opposed to a Frame.

  • The following JFrameDemo program demonstrates creating and displaying a JFrame in swing:



Example: Java program to demonstrate JFrame

 Sam Madam

//Program name

//Java program to demonstrate JFrame

import javax.swing.*;

public class SwingJFrame {


public static void main(String[] args) {

JFrame f = new JFrame("cbtSAM");

f.setSize(400, 350);







  • Note: setDefaultCloseOperation() takes many different parameters as below:

    1. WindowConstants.HIDE_ON_CLOSE. Hides the JFrame. This is the default behavior.

    2. WindowConstants.DO_NOTHING_ON_CLOSE. Does nothing, which is similar to the behavior of Frame objects.

    3. WindowConstants.DISPOSE_ON_CLOSE. Hides and disposes the JFrame, but does not terminate the program.

    4. WindowConstants.EXIT_ON_CLOSE. Causes the program to stop executing.

Containers and Components

  • There are two basic elements of a GUI:

    1. Containers

    2. Components

  • A container is for displaying components, and components must be displayed within a container.

  • A Button is an example of a component, whereas a Frame is an example of a container. To display a Button, you place it within a Frame and display the Frame.

  • The JComponent class is a child of Container, and it is the parent class of all of the Swing components, such as JComboBox, JLabel, JSlider, JSpinner, and JMenuBar.

  • One of the ways that Swing is different from AWT is that not all AWT components are containers. However, all Swing components extend JComponent, which extends Container.

  • Therefore, all Swing components are also containers, allowing them to be nested within each other. For example, a JButton can be placed within a JFrame a typical use of JButton.

  • However, because JButton is a child of Container, you can place a JFrame inside a JButton which is not a typical GUI feature, but it can be done in Swing.

  • For adding component to the container use add() method.

  • Below is the simple program demonstrate how to add button in the container frame:


Example: Java Program to add button inside the frame

 Sam Madam

//Program name

//Java Program to add button inside the frame

import java.awt.*;

public class AddDemo


public static void main(String[] args)


Frame f = new Frame("cbtSAM");

Button cancel = new Button("Add");

f.add(cancel); //Add the Button to the Frame






Pr.Pg border                                              Next Pg