Java Begginers

download Java Begginers

of 20

Transcript of Java Begginers

  • 7/29/2019 Java Begginers

    1/20

    A collection represents a group of objects, known as its elements. This framework is

    provided in the java.util package. Objects can be stored, retrieved, and manipulated

    as elements ofcollections. Collection is a Java Interface. Collections can be used in

    various scenarios like Storing phone numbers, Employee names database etc. They

    are basically used to group multiple elements into a single unit. Some collections

    allow duplicate elements while others do not. Some collections are ordered and

    others are not.

    A Collections Framework mainly contains the following 3 parts

    A Collections Framework is defined by a set ofinterfaces, concrete classimplementations for most of the interfaces and a set ofstandard utility methods

    and algorithms. In addition, the framework also provides several abstract

    implementations, which are designed to make it easier for you to create new anddifferent implementations for handling collections of data.

    Core Collection Interfaces

    The core interfaces that define common functionality and allow collections to bemanipulated independent of their implementation.

    The 6 core Interfaces used in the Collection framework are:

    Collection

    Set

    List

    Iterator (Not a part of the Collections Framework)

    SortedSet

    Map

    SortedMap

    Note: Collection and Map are the two top-level interfaces.

  • 7/29/2019 Java Begginers

    2/20

    Collection Interface

  • 7/29/2019 Java Begginers

    3/20

    Map Interface

    Concrete Classes

    The concrete classes that are specific implementations of the core interfaces,

    providing data structures that a java program can use.

  • 7/29/2019 Java Begginers

    4/20

    Java Vector

    publicclassVector

    extends AbstractListimplements List, RandomAccess, Cloneable, Serializable

    The Vector class implements a growable array of objects where the size of the vector ca

    shrink as needed dynamically.

    Like an array, it contains components that can be accessed using an integer index.

    An application can increase the capacity of a vector before inserting a large number of co

    this reduces the amount of incremental reallocation.

    Below is a Vector Example showing how collections are manipulated using a Vector

    import java.awt.Container;import java.awt.FlowLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.util.Enumeration;import java.util.NoSuchElementException;import java.util.Vector;import javax.swing.JButton;import javax.swing.JFrame;

    import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JTextField;

    public class VectorDemo extends JFrame {

    private JLabel jlbString = new JLabel("Enter a string");public VectorDemo() {

    super("Vector class demo");// Made final as it can be accessed by inner classesfinal JLabel jlbStatus = new JLabel();

    Container contentPane = getContentPane();final Vector vector = new Vector(1);

    contentPane.setLayout(new FlowLayout());contentPane.add(jlbString);final JTextField jtfInput = new JTextField(10);contentPane.add(jtfInput);JButton jbnAdd = new JButton("Add");jbnAdd.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {vector.addElement(jtfInput.getText().trim());

    http://www.javabeginner.com/java-collections/java-vectorhttp://www.javabeginner.com/java-collections/java-vector
  • 7/29/2019 Java Begginers

    5/20

    jlbStatus.setText("Appended to end: "+ jtfInput.getText().trim());

    jtfInput.setText("");}

    });contentPane.add(jbnAdd);JButton jbnRemove = new JButton("Remove");jbnRemove.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {// Returns true if element in vectorif (vector.removeElement(jtfInput.getText().trim()

    jlbStatus.setText("Removed: " + jtfInput.gelse

    jlbStatus.setText(jtfInput.getText().trim(+ " not in vector");

    }});contentPane.add(jbnRemove);JButton jbnFirst = new JButton("First");

    jbnFirst.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {try {

    jlbStatus.setText("First element: "+ vector.firstElement());

    } catch (NoSuchElementException exception) {jlbStatus.setText(exception.toString());

    }}

    });contentPane.add(jbnFirst);JButton jbnLast = new JButton("Last");

    jbnLast.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {try {

    jlbStatus.setText("Last element: "+ vector.lastElement());

    } catch (NoSuchElementException exception) {jlbStatus.setText(exception.toString());

    }}

    });contentPane.add(jbnLast);JButton jbnEmpty = new JButton("Is Empty?");jbnEmpty.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {jlbStatus.setText(vector.isEmpty() ? "Vector is em

    : "Vector is not empty");}

    });contentPane.add(jbnEmpty);JButton jbnContains = new JButton("Contains");jbnContains.addActionListener(new ActionListener() {

  • 7/29/2019 Java Begginers

    6/20

    public void actionPerformed(ActionEvent e) {String searchKey = jtfInput.getText().trim();if (vector.contains(searchKey)) {

    jlbStatus.setText("Vector contains " + sea} else {

    jlbStatus.setText("Vector does not contain + searchKey);

    }}

    });contentPane.add(jbnContains);JButton jbnFindElement = new JButton("Find");jbnFindElement.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {

    jlbStatus.setText("Element found at location "+ vector.indexOf(jtfInput.getText()

    }});

    contentPane.add(jbnFindElement);JButton jbnTrim = new JButton("Trim");jbnTrim.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {vector.trimToSize();jlbStatus.setText("Vector trimmed to size");

    }});contentPane.add(jbnTrim);JButton jbnSize = new JButton("Size/Capacity");jbnSize.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {jlbStatus.setText("Size = " + vector.size()+ "; Capacity = " + vector.capacity

    }});contentPane.add(jbnSize);

    JButton jbnDisplay = new JButton("Display");jbnDisplay.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {Enumeration enum1 = vector.elements();StringBuffer buf = new StringBuffer();while (enum1.hasMoreElements())

    buf.append(enum1.nextElement()).append(" "

    JOptionPane.showMessageDialog(null, buf.toString()"Contents of Vector",

    JOptionPane.PLAIN_MESSAGE);}

    });contentPane.add(jbnDisplay);contentPane.add(jlbStatus);setSize(300, 200);setVisible(true);

  • 7/29/2019 Java Begginers

    7/20

    }public static void main(String args[]) {

    VectorDemo vectorDemo = new VectorDemo();vectorDemo.addWindowListener(new WindowAdapter() {

    public void windowClosing(WindowEvent e) {System.exit(0);

    }});

    }}

    Output

  • 7/29/2019 Java Begginers

    8/20

    Note:Concrete Classes for the Map is shown in the previous section.Standard utility methods and algorithms

    Standard utility methods and algorithms

    that can be used to perform various operations on collections, such as sorting,searching or creating customized collections.

    How are Collections Used

    The collections stores object references, rather than objects themselves.

    Hence primitive values cannot be stored in a collection directly. They need tobe encapsulated (using wrapper classes) into an Object prior to storing them

    into a Collection (such as HashSet, HashMap etc).

    The references are always stored as type Object. Thus, when you retrieve anelement from a collection, you get an Object rather then the actual type of

    the collection stored in the database. Hence we need to downcast it to the

    Actual Type while retrieving an element from a collection.

  • 7/29/2019 Java Begginers

    9/20

    One of the capabilities of the Collection Framework is to create a new

    Collection object and populate it with the contents of an existing Collectionobject of a same or different actual type.

    Below is an example program showing the storing and retrieving of a few CollectionTypes

    import java.util.*;

    public class CollectionsDemo {

    public static void main(String[] args) {List a1 = new ArrayList();a1.add("Beginner");a1.add("Java");

    a1.add("tutorial");System.out.println(" ArrayList Elements");System.out.print("\t" + a1);List l1 = new LinkedList();

    l1.add("Beginner");l1.add("Java");l1.add("tutorial");System.out.println();System.out.println(" LinkedList Elements");System.out.print("\t" + l1);Set s1 = new HashSet(); // or new TreeSet() will order the elements1.add("Beginner");s1.add("Java");s1.add("Java");s1.add("tutorial");System.out.println();System.out.println(" Set Elements");System.out.print("\t" + s1);Map m1 = new HashMap(); // or new TreeMap() will order based on kem1.put("Windows", "98");m1.put("Win", "XP");m1.put("Beginner", "Java");m1.put("Tutorial", "Site");System.out.println();System.out.println(" Map Elements");System.out.print("\t" + m1);

    }}

    Output

    ArrayList Elements[Beginner, Java, tutorial]

    LinkedList Elements[Beginner, Java, tutorial]

    Set Elements[tutorial, Beginner, Java]

    Map Elements{Tutorial=Site, Windows=98, Win=XP, Beginner=Java}

  • 7/29/2019 Java Begginers

    10/20

    Download CollectionsDemo.java

    Java Collections Source Code Examples

    On the following pages in this tutorial I have described how elements can be

    manipulated by different collections namely;

    Java ArrayList

    Java LinkedList

    Java TreeSet

    Java HashMap

    Java Vector

    Java HashTable

    Java HashSet

    http://www.javabeginner.com/java-collections.ziphttp://www.javabeginner.com/java-collections/java-arraylisthttp://www.javabeginner.com/java-collections/javalinked-listhttp://www.javabeginner.com/java-collections/java-treesethttp://www.javabeginner.com/java-collections/java-hashmaphttp://www.javabeginner.com/java-collections/java-vectorhttp://www.javabeginner.com/java-collections/java-hashtablehttp://www.javabeginner.com/java-collections/java-hashsethttp://www.javabeginner.com/java-collections.ziphttp://www.javabeginner.com/java-collections/java-arraylisthttp://www.javabeginner.com/java-collections/javalinked-listhttp://www.javabeginner.com/java-collections/java-treesethttp://www.javabeginner.com/java-collections/java-hashmaphttp://www.javabeginner.com/java-collections/java-vectorhttp://www.javabeginner.com/java-collections/java-hashtablehttp://www.javabeginner.com/java-collections/java-hashset
  • 7/29/2019 Java Begginers

    11/20

    Java Vector

    publicclassVector

    extends AbstractListimplements List, RandomAccess, Cloneable, Serializable

    The Vector class implements a growable array of objects where the size of the vector can grow or

    shrink as needed dynamically.

    Like an array, it contains components that can be accessed using an integer index.

    An application can increase the capacity of a vector before inserting a large number of components;

    this reduces the amount of incremental reallocation.

    Below is a Vector Example showing how collections are manipulated using a Vector

    import java.awt.Container;import java.awt.FlowLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.util.Enumeration;import java.util.NoSuchElementException;import java.util.Vector;import javax.swing.JButton;import javax.swing.JFrame;

    import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JTextField;

    public class VectorDemo extends JFrame {

    private JLabel jlbString = new JLabel("Enter a string");public VectorDemo() {

    super("Vector class demo");// Made final as it can be accessed by inner classesfinal JLabel jlbStatus = new JLabel();

    Container contentPane = getContentPane();final Vector vector = new Vector(1);contentPane.setLayout(new FlowLayout());contentPane.add(jlbString);final JTextField jtfInput = new JTextField(10);contentPane.add(jtfInput);JButton jbnAdd = new JButton("Add");jbnAdd.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {vector.addElement(jtfInput.getText().trim());jlbStatus.setText("Appended to end: "

    http://www.javabeginner.com/java-collections/java-vectorhttp://www.javabeginner.com/java-collections/java-vector
  • 7/29/2019 Java Begginers

    12/20

    HashTable is synchronized.

    Iterator in the HashMap is fail-safe while the enumerator for the Hashtable

    isnt.

    Hashtable doesnt allow nulls

    Below is a HashTable Example showing how collections are manipulated using a

    HashTable

    Please Note that It must be Compiled in Java 1.4.

    // Demonstrates the Hashtable class of the java.util package.

    public class HashTableDemo extends JFrame {

    public HashTableDemo() {super(" Hashtable Sourcecode Example");final JLabel jlbStatus = new JLabel();final Hashtable hashTable = new Hashtable();final JTextArea display = new JTextArea(4, 20);display.setEditable(false);JPanel jplNorth = new JPanel();jplNorth.setLayout(new BorderLayout());JPanel jplNorthSub = new JPanel();jplNorthSub.add(new JLabel("Name (Key)"));final JTextField jtfFirstName = new JTextField(8);jplNorthSub.add(jtfFirstName);jplNorthSub.add(new JLabel("Phone No"));final JTextField jtfPhone = new JTextField(8);jplNorthSub.add(jtfPhone);jplNorth.add(jplNorthSub, BorderLayout.NORTH);jplNorth.add(jlbStatus, BorderLayout.SOUTH);JPanel jplSouth = new JPanel();

    jplSouth.setLayout(new GridLayout(2, 5));JButton jbnAdd = new JButton("Add");

    jbnAdd.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {

    String strNum = jtfPhone.getText().trim();String strName = jtfFirstName.getText().trim();if ((strNum != null && strNum.equals(""))

    || (strName != null && strName.equaJOptionPane.showMessageDialog(HashTableDemo

    "Please enter both Name and No");

    return;}int num = 0;try {

    num = Integer.parseInt(strNum);} catch (NumberFormatException ne) {

    ne.printStackTrace();}EmployeeDetails emp = new EmployeeDetails(strName,

    Object val = hashTable.put(strName, emp);

  • 7/29/2019 Java Begginers

    13/20

    if (val == null)jlbStatus.setText("Added: " + emp.toString(

    elsejlbStatus.setText("Added: " + emp.toString(

    + "; Replaced: " + val.toStr}

    });jplSouth.add(jbnAdd);JButton jbnGet = new JButton("Get");jbnGet.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {Object val = hashTable.get(jtfFirstName.getText().tif (val != null)

    jlbStatus.setText("Get: " + val.toString())else

    jlbStatus.setText("Get: " + jtfFirstName.ge" not

    table");}

    });jplSouth.add(jbnGet);JButton jbnRemove = new JButton("Remove Name");jbnRemove.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {Object val = hashTable.remove(jtfFirstName.getText

    .trim());if (val != null)

    jlbStatus.setText("Remove: " + val.toStringelse

    jlbStatus.setText("Remove: " + jtfFirstName+

    " nottable");}

    });jplSouth.add(jbnRemove);JButton jbnIsEmpty = new JButton("Empty ?");jbnIsEmpty.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {jlbStatus.setText("Empty: " + hashTable.isEmpty())

    }});jplSouth.add(jbnIsEmpty);JButton jbnContains = new JButton("Contains key");

    jbnContains.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {jlbStatus.setText("Contains key: "+

    hashTable.containsKey(jtfFirstName.getText().trim()));}

    });jplSouth.add(jbnContains);

  • 7/29/2019 Java Begginers

    14/20

    JButton jbnClear = new JButton("Clear table");jbnClear.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {hashTable.clear();jlbStatus.setText("HashTable Emptied");

    }});jplSouth.add(jbnClear);JButton jbnDisplay = new JButton("List objects");jbnDisplay.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {StringBuffer buf = new StringBuffer();for (Enumeration enum = hashTable.elements();

    enum.hasMoreElements();)

    buf.append(enum.nextElement()).append('\n')display.setText(buf.toString());

    }

    });jplSouth.add(jbnDisplay);JButton jbnKeys = new JButton("List keys");jbnKeys.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {StringBuffer buf = new StringBuffer();for (Enumeration enum = hashTable.keys();

    enum.hasMoreElements();)buf.append(enum.nextElement()).append('\n')

    JOptionPane.showMessageDialog(null, buf.toString()"Display Keys of HashTable

    ",JOptionPane.PLAIN_MESSAGE);

    }});jplSouth.add(jbnKeys);Container c = getContentPane();c.add(jplNorth, BorderLayout.NORTH);

    c.add(new JScrollPane(display), BorderLayout.CENTER);c.add(jplSouth, BorderLayout.SOUTH);setSize(540, 300);setVisible(true);

    }

    public static void main(String args[]) {HashTableDemo hashTableDemo = new HashTableDemo();hashTableDemo.addWindowListener(new WindowAdapter() {

    public void windowClosing(WindowEvent e) {System.exit(0);

    }});

    }}

    class EmployeeDetails {

  • 7/29/2019 Java Begginers

    15/20

    private String name;private int phoneNp;public EmployeeDetails(String fName, int phNo) {

    name = fName;phoneNp = phNo;

    }public String toString() {return name + " " + phoneNp;

    }}

    Output

  • 7/29/2019 Java Begginers

    16/20

    This site contains brief tutorials for java swing programming along with java swingexamples and source code.

    Java Swings Tutorial

    What is Swings in java ?

    A part of The JFC

    Swing Javaconsists of

    Look and feel

    AccessibilityJava 2D

    Drag and Drop, etc

    Compiling & running programs

    javac &&java

    Or JCreator / IDE

    if you do not explicitly add a GUI component to a container, the GUIcomponent will not be displayed when the container appears on the screen.

    Swing, which is an extension library to the AWT, includes new and improvedcomponents that enhance the look and functionality of GUIs. Swing can beused to build Standalone swing gui Apps as well as Servlets and Applets. It

    employs a model/view design architecture. Swing is more portable and more

    flexible than AWT.

    Swing Model/view design: The view part of the MV design is implemented with a

    component object and the UI object. The model part of the MV design isimplemented by a model object and a change listener object.

    Swing is built on top of AWT and is entirely written in Java, using AWTs lightweight

    component support. In particular, unlike AWT, t he architecture of Swing

    components makes it easy to customize both their appearance and behavior.Components from AWT and Swing can be mixed, allowing you to add Swing support

    to existing AWT-based programs. For example, swing components such as JSlider,JButton and JCheckbox could be used in the same program with standard AWT

    labels, textfields and scrollbars. You could subclass the existing Swing UI, model, or

  • 7/29/2019 Java Begginers

    17/20

    change listener classes without having to reinvent the entire implementation. Swingalso has the ability to replace these objects on-the-fly.

    100% Java implementation of components Pluggable Look & Feel

    Lightweight components Uses MVC Architecture

    Model represents the data

    View as a visual representation of the data

    Controller takes input and translates it to changes in data

    Three parts

    Component set (subclasses of JComponent)

    Support classes

    Interfaces

    In Swing, classes that represent GUI components have names beginning with theletter J. Some examples are JButton, JLabel, and JSlider. Altogether there are more

    than 250 new classes and 75 interfaces in Swing twice as many as in AWT.

    Java Swing class hierarchy

    The class JComponent, descended directly from Container, is the root class for mostof Swings user interface components.

    Swing contains components that youll use to build a GUI. I am listing you some ofthe commonly used Swing components. To learn and understand these swing

    programs, AWT Programming knowledge is not required.

  • 7/29/2019 Java Begginers

    18/20

    Java Swing ExamplesBelow is a java swing code for the traditional Hello World program.

    Basically, the idea behind this Hello World program is to learn how to create a java

    program, compile and run it. To create your java source code you can use any

    editor( Text pad/Edit plus are my favorites) or you can use an IDE like Eclipse.

    import javax.swing.JFrame;import javax.swing.JLabel;

    //import statements//Check if window closes automatically. Otherwise add suitable codepublic class HelloWorldFrame extends JFrame {

    public static void main(String args[]) {new HelloWorldFrame();

    }HelloWorldFrame() {

    JLabel jlbHelloWorld = new JLabel("Hello World");add(jlbHelloWorld);this.setSize(100, 100);// pack();setVisible(true);

    }}

    Output

    Note: Below are some links to java swing tutorials that forms a helping hand to get

    started withjava programming swing.

    JPanel is Swings version of the AWT class Panel and uses the same default

    layout, FlowLayout. JPanel is descended directly from JComponent.

    JFrame is Swings version of Frame and is descended directly fromthat class. The components added to the frame are referred to as itscontents; these are managed by the contentPane. To add a component to a

    JFrame, we must use its contentPane instead.

    JInternalFrame is confined to a visible area of a container itis placed in. It can be iconified , maximized and layered.

    JWindow is Swings version of Window and is descended directlyfrom that class. Like Window, it uses BorderLayout by default.

    JDialog is Swings version of Dialog and is descended directly from that class.Like Dialog, it uses BorderLayout by default. Like JFrame and JWindow,

    http://www.javabeginner.com/java-swing/java-jframe-class-examplehttp://www.javabeginner.com/java-swing/java-jinternalframe-class-examplehttp://www.javabeginner.com/java-swing/java-jwindow-class-examplehttp://www.javabeginner.com/java-swing/java-jframe-class-examplehttp://www.javabeginner.com/java-swing/java-jinternalframe-class-examplehttp://www.javabeginner.com/java-swing/java-jwindow-class-example
  • 7/29/2019 Java Begginers

    19/20

    JDialog contains a rootPane hierarchy including a contentPane, and it allowslayered and glass panes. All dialogs are modal, which means the current

    thread is blocked until user interaction with it has been completed. JDialogclass is intended as the basis for creating custom dialogs; however, some

    of the most common dialogs are provided through static methods in the classJOptionPane.

    JLabel, descended from JComponent, is used to create text labels. The abstract class AbstractButton extends class JComponent and provides a

    foundation for a family ofbutton classes, including

    JButton.

    JTextField allows editing of a single line of text. New featuresinclude the ability to justify the text left, right, or center, and to set the textsfont.

    JPasswordField (a direct subclass of JTextField) you cansuppress the display of input. Each character entered can be replaced by an

    echo character.This allows confidential input for passwords, for example. By default, the echo

    character is the asterisk, *.

    JTextArea allows editing of multiple lines of text. JTextArea canbe used in conjunction with class JScrollPane to achieve scrolling. The

    underlying JScrollPane can be forced to always or never haveeither the vertical or horizontal scrollbar;

    JButton is a component the user clicks to trigger a specific action.

    JRadioButton is similar to JCheckbox, except for the defaulticon for each class. A set of radio buttons can be associated as a group in

    which onlyone button at a time can be selected.

    JCheckBox is not a member of a checkbox group. A checkboxcan be selected and deselected, and it also displays its current state.

    JComboBox is like a drop down box. You can click a drop-downarrow and select an option from a list. For example, when the component has

    focus,pressing a key that corresponds to the first character in some entrys name

    selects that entry. A vertical scrollbar is used for longer lists.

    JList provides a scrollable set of items from which one or more may beselected. JList can be populated from an Array or Vector. JList does notsupport scrolling directly, instead, the list must be associated with ascrollpane. The view port used by the scroll pane can also have a user-definedborder. JList actions are handled using ListSelectionListener.

    JTabbedPane contains a tab that can have a tool tip and amnemonic, and it can display both text and an image.

    http://www.javabeginner.com/java-swing/java-jlabel-class-examplehttp://www.javabeginner.com/java-swing/java-jlabel-class-examplehttp://www.javabeginner.com/java-swing/java-jtextfield-class-examplehttp://www.javabeginner.com/java-swing/java-jpasswordfield-class-examplehttp://www.javabeginner.com/java-swing/java-jtextarea-class-examplehttp://www.javabeginner.com/java-swing/java-jbutton-class-examplehttp://www.javabeginner.com/java-swing/java-jcheckbox-class-examplehttp://www.javabeginner.com/java-swing/java-jcombobox-class-examplehttp://www.javabeginner.com/java-swing/java-jlist-class-examplehttp://www.javabeginner.com/java-swing/java-jtabbedpane-class-examplehttp://www.javabeginner.com/java-swing/java-jtabbedpane-class-examplehttp://www.javabeginner.com/java-swing/java-jlabel-class-examplehttp://www.javabeginner.com/java-swing/java-jtextfield-class-examplehttp://www.javabeginner.com/java-swing/java-jpasswordfield-class-examplehttp://www.javabeginner.com/java-swing/java-jtextarea-class-examplehttp://www.javabeginner.com/java-swing/java-jbutton-class-examplehttp://www.javabeginner.com/java-swing/java-jcheckbox-class-examplehttp://www.javabeginner.com/java-swing/java-jcombobox-class-examplehttp://www.javabeginner.com/java-swing/java-jlist-class-examplehttp://www.javabeginner.com/java-swing/java-jtabbedpane-class-example
  • 7/29/2019 Java Begginers

    20/20

    JToolbar contains a number of components whose type is usuallysome kind of button which can also include separators to group relatedcomponents

    within the toolbar.

    FlowLayout when used arranges swing components from left toright until theres no more space available. Then it begins a new row below itand movesfrom left to right again. Each component in a FlowLayout gets as much space

    as it needs and no more.

    BorderLayout places swing components in the North, South,East, West and center of a container. You can add horizontal and vertical gapsbetween

    the areas.

    GridLayout is a layout manager that lays out a containerscomponents in a rectangular grid. The container is divided into equal-sized

    rectangles,and one component is placed in each rectangle.

    GridBagLayout is a layout manager that lays out acontainers components in a grid of cells with each component occupying one

    or more cells,called its display area. The display area aligns components vertically and

    horizontally, without requiring that the components be of the same size.

    JMenubar can contain several JMenus. Each of the JMenus cancontain a series of JMenuItem s that you can select. Swing provides support

    forpull-down and popup menus.

    Scrollable JPopupMenu is a scrollable popup menuthat can be used whenever we have so many items in a popup menu that

    exceeds the screen visible height.

    Java Swing Projects

    Java Swing Calculator developed using Java Swing.It is a basic four-function calculator java program source code.

    Java Swing Address Book demonstrates how to createa simple free address book program using java swing and jdbc. Also you willlearn to use

    the following swing components like Jbuttons, JFrames, JTextFields andLayout Manager (GridBagLayout).

    http://www.javabeginner.com/java-swing/java-jtoolbar-class-examplehttp://www.javabeginner.com/java-swing/java-jtoolbar-class-examplehttp://www.javabeginner.com/java-swing/java-flowlayout-class-examplehttp://www.javabeginner.com/java-swing/java-borderlayout-class-examplehttp://www.javabeginner.com/java-swing/java-gridlayout-class-examplehttp://www.javabeginner.com/java-swing/java-gridbaglayout-class-examplehttp://www.javabeginner.com/java-swing/java-jmenu-class-examplehttp://www.javabeginner.com/java-swing/java-scrollable-popup-menuhttp://www.javabeginner.com/java-swing/java-swing-calculatorhttp://www.javabeginner.com/java-swing/java-swing-address-bookhttp://www.addthis.com/bookmark.php?v=120&winname=addthis&pub=unknown&source=men-120&lng=en&s=&url=http%253A%252F%252Fwww.javabeginner.com%252Fjava-swing%252Fjava-swing-tutorial&title=Java%2BSwing%2BTutorial&logo=&logobg=&logocolor=&ate=AT-unknown/-/-/4dc9430a88fb128d/1&uid=4dc9430aaaeb8e88&sms_ss=1&at_xt=1&pre=http%3A%2F%2Fwww.javabeginner.com%2Ftoc.htm&tt=0http://www.javabeginner.com/java-swing/java-jtoolbar-class-examplehttp://www.javabeginner.com/java-swing/java-flowlayout-class-examplehttp://www.javabeginner.com/java-swing/java-borderlayout-class-examplehttp://www.javabeginner.com/java-swing/java-gridlayout-class-examplehttp://www.javabeginner.com/java-swing/java-gridbaglayout-class-examplehttp://www.javabeginner.com/java-swing/java-jmenu-class-examplehttp://www.javabeginner.com/java-swing/java-scrollable-popup-menuhttp://www.javabeginner.com/java-swing/java-swing-calculatorhttp://www.javabeginner.com/java-swing/java-swing-address-book