Java Advanced Chapter Two
Java Advanced Chapter Two
Presenter:
Eng: Bishaar Abdisalam mohamed
Course Outline:
Introduction SWING
Java SWING Hierarchy
Difference between AWT and Swing
Jlabel
JTextField
JTextArea
JPasswordField
JCheckBox
JRadioButton
Jbutton
JComboBox
Java Swing
• Java Swing is a part of Java Foundation Classes (JFC) that is used to create window-
based applications. It is built on the top of AWT (Abstract Windowing Toolkit) API and
entirely written in java.
• The javax.swing package provides classes for java swing API such as JButton,
JTextField, JTextArea, JRadioButton, JCheckbox, JMenu, JColorChooser etc.
Difference between AWT and Swing
• There are many differences between java AWT and swing that are
given below.
import javax.swing.*;
f.add(b);//adding button in JFrame
public class FirstSwingExample {
public static void main(String[] args) {
f.setSize(400,500);//400 width and 500 height
JFrame f=new JFrame
f.setLayout(null);//using no layout managers
JButton b=new JButton("click");
f.setVisible(true);//making the frame visible
//creating instance of JButton
}
b.setBounds(130,100,100, 40);//
}
x axis, y axis, width, height
Example of Swing by Association inside constructor
• We can also write all the codes of creating JFrame, JButton and
method call inside the java constructor.
import javax.swing.*;
public class Simple { f.setSize(400,500);//400 width and 500 height
JFrame f; f.setLayout(null);//using no layout managers
Simple(){ f.setVisible(true);//making the frame visible
f=new JFrame(); }
//creating instance of JFrame
JButton b=new JButton("click");// public static void main(String[] args) {
creating instance of JButton new Simple();
b.setBounds(130,100,100, 40); }
}
f.add(b);//adding button in JFrame
Simple example of Swing by inheritance
• We can also inherit the JFrame class, so there is no need to create the
instance of JFrame class explicitly.
• The object of a JTextArea class is a multi line region that displays text.
It allows the editing of multiple line text. It inherits JTextComponent
class
JPasswordField