Advance Java Technology Java’s Role::MVC Architecture :: Swing Prof.Chintan Dave.

Slides:



Advertisements
Similar presentations
1 Graphical User Interface (GUI) Applications Abstract Windowing Toolkit (AWT) Events Handling Applets.
Advertisements

Introduction to Java 2 Programming
Chapter 16 GUI Programming Basics GUI Overview Event-Driven Programming Basics GUI Classes and Packages A Simple Window Program JFrame Class Java Components.
User Interfaces II GUI – Awt, Swing, Web
1 G54PRG Programming Lecture 1 Amadeo Ascó Adam Moore 22 GUI Programming I.
Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Introduction to Swing Components Chapter 14. Part of the Java Foundation Classes (JFC) Provides a rich set of GUI components Used to create a Java program.
Java Graphical User Interface (GUI) using Visual Editor in eclipse CSI 1390 – Java Programming Instructor: Saeid Nourian University.
Graphical User Interfaces
1 cs205: engineering software university of virginia fall 2006 Wimpy Interfaces.
CSE 1341 Honors Professor Mark Fontenot Southern Methodist University Note Set 21.
Graphics and event-driven programs Learning objectives By the end of this lecture you should be able to: identify and use some of the common components.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 17 Creating User Interfaces.
Basic Java – Interface design. Understand: How to use TextPad for Java How to define classes and objects How to create a GUI interface How event-driven.
Graphical User Interfaces Java’s AWT and Swing APIs.
Graphical User Interfaces (Part IV)
Java Software Development Paradigm Lecture # 12. Basics of GUI.
Examples. // A simple Frame with Rectangle Inside import java.awt.*; import javax.swing.*; import java.awt.geom.*; // For Shapes class rectComponent extends.
Drawing in a frame – Java GUI
CS18000: Problem Solving and Object-Oriented Programming.
Unit 3 Graphical User Interface (GUI) Dr. Magdi AMER.
Graphic User Interfaces Layout Managers Event Handling.
F27SB2 Programming Languages
Problem Solving 6 GUIs and Event Handling ICS-201 Introduction to Computing II Semester 071.
TCU CoSc Programming with Java Handling Events.
CMSC 341 Building Java GUIs. 09/26/2007 CMSC 341 GUI 2 Why Java GUI Development? Course is about Data Structures, not GUIs. We are giving you the opportunity.
Graphical User Interfaces CS 2110 Spring Ivan Sutherland: “Sketchpad”,
Things to mention public static void main(String [] args) –The starting point for a free-standing Java application (i.e. one not run from the DrJava interactions.
Introduction to Java Classes, events, GUI’s. Understand: How to use TextPad How to define a class or object How to create a GUI interface How event-driven.
JAVA API (GUI) Subject:T0934 / Multimedia Programming Foundation Session:1 Tahun:2009 Versi:1/0.
Java Swing Recitation – 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University.
Java GUI Libraries Swing Programming. Swing Components Swing is a collection of libraries that contains primitive widgets or controls used for designing.
Graphical User Interfaces (GUIs) GUI: An application that uses graphical objects to interact with users GUI applications consist of: –Events: A user or.
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
GUI Programming in Java Tim McKenna GUI Programming Concepts l conventional programming: sequence of operations is determined by the program.
Introduction to Java Swing “We are the sultans of swing” – Mark Knopfler.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Object Oriented Programming Ders 11: Interfaces Mustafa Emre İlal
1 Outline 1 Introduction 2 Overview of Swing Components 3 JLabel 4 Event Handling 5 TextFields 6 How Event Handling Works 7 JButton 8 JCheckBox and JRadioButton.
MSc Workshop - © S. Kamin, U. ReddyLect 3 - GUI -1 Lecture 3 - Graphical User Interfaces r GUI toolkits in Java API r JFrame r GUI components.
Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary Litvin, and Skylight.
Object Oriented programming Instructor: Dr. Essam H. Houssein.
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
Creating Windows. How can we use Java to create programs that use windows (GUI applications)? How can we use Java to create programs that use windows.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Swing. Introduction to Swing What is Swing? “ Swing is a diverse collection of lightweight components that can be used to build sophisticated user interfaces.”
Basics of GUI Programming Chapter 11 and Chapter 22.
Ajmer Singh PGT(IP) JAVA IDE Programming - I. Ajmer Singh PGT(IP) GUI (Graphical User Interface) It is an interface that uses a graphic entities along.
Chapter 14: Introduction to Swing Components. Objectives Understand Swing components Use the JFrame class Use the JLabel class Use a layout manager Extend.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Applets. 9/04/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L12: Applets Slide 2 Applets Usually.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
Java Programming Fifth Edition Chapter 13 Introduction to Swing Components.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 7.1 Test-Driving the Dental Payment Application.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
A Quick Java Swing Tutorial
Welcome To java
A First Look at GUI Applications
Java Swing.
Graphical User Interface (pronounced "gooey")
Ellen Walker Hiram College
Chapter 13: Advanced GUIs and Graphics
Introduction to Graphical Interface Programming in Java
Advanced GUIs and Graphics
Graphical User Interface
Presentation transcript:

Advance Java Technology Java’s Role::MVC Architecture :: Swing Prof.Chintan Dave

Who is the Founder of Java???????

Which is the Most Popular Machine Used in Day to Day Life Uses Java????????

Which is the Most Popular OS Uses Java as Prime Framework ???

Most Popular Companies uses Java as Prime Technology… Google Yahoo Microsoft LinkedIn……………..endless list

Usage wise Programming Languages/Technologies

Common Architecture for Any Programming Technology Operating System Run Time Environment Class Libraries Application

Java Architecture Operating System- Windows,Mac,Solaris… Run Time Environment-JVM Class Libraries-Packages Application-Windows,Web, Mobile …….

How Application Can be Developed - Traditional Way of Developing an Application with Forms…Approach -Developing an Application with MVC Architecture None is Best None is Worst Too--- Its Just on Requirements… or Approach for an Application

MVC Architecture a software design pattern for developing web applications. Model - The lowest level of the pattern which is responsible for maintaining data. View - This is responsible for displaying all or a portion of the data to the user. Controller - Software Code that controls the interactions between the Model and View.

What is Swing???? It is a SET of Programs which provides facility to Create GUI. It is a Widget Toolkit It is Part of JFC(Java Foundation Classes It is Useful for Creating Rich Set of Desktop Application IT MEANS it’s a PURE JAVA

What You Need to Run Java- SWING JAVA SE- which can be downloaded from java.sun.com/javase To Make Java Code You’ll Need an Editor….Most Popular Once are….. Notepad Eclipse Net beans JCreator

Pluggable Look n Fell Pluggable L&F (PLAF) is basically a "skin" system for Swing components - you can change the style of your application by changing its LAF Allows an Application Development to Highly Interactive GUI Component and Effects with ready made set of APIs

Applet Vs Swing SwingApplet Swing have its own Layout like most popular Box Layout. Applet uses AWT Layouts like flowlayout. Swing is light weight Component. iTS Heavy Weight Swing uses for stand lone Applications, Swing have main method to execute the program Applet need HTML code for Run the Applet Swing Uses MVCApplet Does not

Swing Features Lightweight - Swing component are independent of native Operating System's API as Swing API controls are rendered mostly using pure JAVA code instead of underlying operating system calls. Rich controls - Swing provides a rich set of advanced controls like Tree, Tabbed Pane, slider, color picker, table controls Highly Customizable - Swing controls can be customized in very easy way as visual appearance is independent of internal representation.

To Use Swing Components.. Create an Object of Component For Example: JButton but = new JButton(); Adding Component For Example: Container cp = getContentPane(); cp.add(new JButton(“but”)); Laying Out Component Not so difficult but takes a little practice JPanel p1 = new JPanel(); p1.setLayout(new FlowLayout(FlowLayout.LEFT));

Simple Swing Example import javax.swing.*; public class Simple { JFrame f; Simple() { f=new JFrame(); JButton b=new JButton("click"); b.setBounds(130,100,100, 40); f.add(b); f.setSize(400,500); f.setLayout(null); f.setVisible(true); } public static void main(String[] args) { new Simple(); } }

JLabel The class JLabel can display either text, an image, or both Example code: import javax.swing.*; class hello { public static void main(String[] args){ JFrame f = new JFrame(“title”); JPanel p = new JPanel(); JLabel b = new JLabel(“Demo Label”); p.add(b);// add labelto panel f.setContentPane(p); // add panel to frame f.show(); }

JButton The class JButton is an implementation of a push button. It can have Image also

Code - JButton import javax.swing.*; public class SimpleButton { JFrame f; SimpleButton() { f=new JFrame("Simple Button Example"); ImageIcon india = new ImageIcon("india.jpg"); JButton jb = new JButton("Our Flag",india); JButton b=new JButton("click"); f.add(b); f.add(jb); b.setBounds(130,100,100, 40); jb.setBounds(130,200,500,200); f.setSize(400,500); f.setLayout(null); f.setVisible(true); f.setDefaultCloseOperation(JF rame.EXIT_ON_CLOSE); } public static void main(String[] args) { new SimpleButton();} }

JTextfield The class JTextField is a component which allows the editing of a single line of text. Common Constructors:- JTextField(String text):- Constructs a new TextField initialized with the specified text.

Code - JTextField import java.awt.*; import java.awt.event.*; import javax.swing.*; //code that demonstrate use of JLabel,JButton,JTextfield and Sample GUI Application public class SimpleTextField { JFrame f; SimpleTextField() { //Setting Layout f=new JFrame("Simple Button Example"); JPanel controlPanel = new JPanel(); controlPanel.setLayout(new FlowLayout()); //Creating GUI Aspects for an Appllication JLabel lblUsername= new JLabel("Username:", JLabel.RIGHT); JLabel lblPassword = new JLabel("Password:", JLabel.CENTER); JTextField txtUsername = new JTextField(10); JTextField txtPassword = new JTextField(10); JButton btnLogin=new JButton("Login");

Code – JTextField-Continue //Adding Instance in Layout controlPanel.add(lblUsernam e); controlPanel.add(txtUsernam e); controlPanel.add(lblPassword); controlPanel.add(txtPasswor d); controlPanel.add(btnLogin); f.add(controlPanel); f.setSize(400,500); f.setVisible(true); f.setDefaultCloseOperation(JFra me.EXIT_ON_CLOSE); } public static void main(String[] args) { new SimpleTextField(); //calling GUI }

Event Handling What is an Event? Change in the state of an object is known as event. Types of Event The events can be broadly classified into two categories: Foreground Events - Those events which require the direct interaction of user. Background Events - Those events that require the interaction of end user are known as background events. Operating system interrupts

Code for Simple Even Handling import java.awt.*; import java.awt.event.*; import javax.swing.*; //code that demonstrate use of JLabel,JButton,JTextfield and Sample GUI Application public class SimpleButtonEvent { JFrame f; JLabel statusLabel=new JLabel("Your Status"); SimpleButtonEvent() { //Setting Layout f=new JFrame("Simple Button Example"); JPanel controlPanel = new JPanel(); controlPanel.setLayout(new FlowLayout()); //Creating GUI Aspects for an Appllication JButton btnOk=new JButton("Ok"); JButton btnCancle=new JButton("Cancle"); JButton btnRetry=new JButton("Retry"); //Adding Instance in Layout controlPanel.add(btnOk); controlPanel.add(btnCancle); controlPanel.add(btnRetry); btnOk.addActionListener(new ButtonClickListener()); btnCancle.addActionListener(new ButtonClickListener()); btnRetry.addActionListener(new ButtonClickListener()); controlPanel.add(statusLabel); f.add(controlPanel); f.setSize(400,500); f.setVisible(true); f.setDefaultCloseOperation(JFrame.EXIT _ON_CLOSE); }

Code for Simple Even Handling private class ButtonClickListener implements ActionListener{ public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); if( command.equals("Ok")) { statusLabel.setText("Ok Button clicked."); } else if( command.equals("Cancle") ) { statusLabel.setText("Cancle Button clicked."); } else { statusLabel.setText("Retry Button clicked."); } } public static void main(String[] args) { new SimpleButtonEvent(); //calling GUI }

JCheckBox The class JCheckBox is an implementation of a check box - an item that can be selected or deselected, and which displays its state to the user. Constructor- JCheckBox(String text): Creates an initially unselected check box with text. Method- getStateChange() – A Boolean Method to get the state of CheckBox Event- Listener Is – ItemListener Event is - ItemEvent

Code for Simple Checkbox import java.awt.*; import java.awt.event.*; import javax.swing.*; //code that demonstrate use of JLabel,JButton,JTextfield and Sample GUI Application public class SimpleCheckBox { JFrame f; SimpleCheckBox() { //Setting Layout f=new JFrame("Simple CheckBox Example"); JPanel controlPanel = new JPanel(); controlPanel.setLayout(new FlowLayout()); //Creating GUI Aspects for an Appllication JCheckBox chkApple = new JCheckBox("Apple"); JCheckBox chkMango = new JCheckBox("Mango"); JCheckBox chkBanana = new JCheckBox("Banana"); //Adding Instance in Layout controlPanel.add(chkApple); controlPanel.add(chkMango); controlPanel.add(chkBanana); chkApple.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { f.setTitle("Apple Checkbox: " + (e.getStateChange()==1?"checked":"unchecked")); } }); f.add(controlPanel); f.setSize(400,500); f.setVisible(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String[] args) { new SimpleCheckBox(); //calling GUI }

JRadioButton Same as Checkbox But……Usage…is Different as per GUI’s Needs

JList The class JList is a component which displays a list of objects and allows the user to select one or more item Constructor:- JList()- Constructs a JList with an empty, read-only, model. Method:- addElement(String) – To add an Element in a List setSelectionMode()- selection mode for the list

Code for Simple List import java.awt.*; import java.awt.event.*; import javax.swing.*; //code that demonstrate use of JLabel,JButton,JTextfield and Sample GUI Application public class SimpleCheckBox { JFrame f; SimpleCheckBox() { //Setting Layout f=new JFrame("Simple CheckBox Example"); JPanel controlPanel = new JPanel(); controlPanel.setLayout(new FlowLayout()); //Creating GUI Aspects for an Appllication JCheckBox chkApple = new JCheckBox("Apple"); JCheckBox chkMango = new JCheckBox("Mango"); JCheckBox chkBanana = new JCheckBox("Banana"); //Adding Instance in Layout controlPanel.add(chkApple); controlPanel.add(chkMango); controlPanel.add(chkBanana); chkApple.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { f.setTitle("Apple Checkbox: " + (e.getStateChange()==1?"checked":"unchecked")); } }); f.add(controlPanel); f.setSize(400,500); f.setVisible(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String[] args) { new SimpleCheckBox(); //calling GUI }

JComboBox Same as Jlist but Usage is Different- Usage is As per GUI NEED