It attached with method ,class and interface etc…

Slides:



Advertisements
Similar presentations
CS18000: Problem Solving and Object-Oriented Programming.
Advertisements

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.
Fall 2007CS 225 Graphical User Interfaces Event Handling Appendix C.
Gui Interfaces a la Swing Up to speed with Swing by Steven Gutz is a good source It don’t mean a thing if it ain’t got that swing Duke Ellington.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
CS3157 Java UI Recitation. Material Covered: Overview of AWT components, Event Handling, creating applets, and sample UI. Not covered in recitation: Drawing,
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 14 GUI and Event-Driven Programming.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 14 GUI and Event-Driven Programming.
Creating a GUI with Swing. Introduction Very useful link: Swing – is a part of JFC (Java Foundation.
Unit 111 Java GUI Components and Events  Learning Outcomes oDistinguish between GUI components and containers. oIdentify and distinguish top-level containers.
Scott Grissom, copyright 2006Ch 11: GUI Slide 1 Graphical User Interfaces (Ch 11) Careful design of a graphical user interface is key to a viable software.
GUI and Event-Driven Programming Part 2. Event Handling An action involving a GUI object, such as clicking a button, is called an event. The mechanism.
PROGRAMMING REVIEW Lab 2 EECS 448 Dr Fengjun Li and Meenakshi Mishra.
Chapter 8: Graphical User Interfaces Objectives - by the end of this chapter, you should be able to do the following: –write a simple graphical user interface.
1 Event Driven Programming wirh Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Introduction to GUI in Java 1. Graphical User Interface Java is equipped with many powerful,easy to use GUI component such as input and output dialog.
MIT AITI 2003 Lecture 17. Swing - Part II. The Java Event Model Up until now, we have focused on GUI's to present information (with one exception) Up.
Java GUI CSCE 190 – Java Instructor: Joel Gompert Mon, July 26, 2004.
Java GUIs and Graphics CNS Outline  Introduction  Events  Components  Layout managers  Drawing  Introduction  Events  Components  Layout.
עקרונות תכנות מונחה עצמים תרגול 4 - GUI. Outline  Introduction to GUI  Swing  Basic components  Event handling.
GUI programming Graphical user interface-based programming.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
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.
Objectives of This Session
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
SWING. AbstractButton Swing Buttons are subclasses of the AbstractButton class, which extends JComponent. Abstract class javax.swing.AbstractButton AbstractButton.
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.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
GUI Clients 1 Enterprise Applications CE00465-M Clients with Graphical User Interfaces.
Copyright © 2002, Systems and Computer Engineering, Carleton University c-Gui3.ppt * Object-Oriented Software Development Part 18-c Building.
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.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
 GUI – Graphic User Interface  Up to now in the programs we have written all output has been sent to the standard output device i.e.: the DOS console.
CS1054: Lecture 21 - Graphical User Interface. Graphical User Interfaces vs. Text User Interface.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Ch13 Creating windows and applets. Short overview AWT (Abstract Windowing Toolkit) Early Java development used graphic classesEarly Java development used.
GUI DYNAMICS Lecture 11 CS2110 – Fall GUI Statics and GUI Dynamics  Statics: what’s drawn on the screen  Components buttons, labels, lists, sliders,
Java Swing One of the most important features of Java is its ability to draw graphics.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
1 Event Driven Programs with a Graphical User Interface Rick Mercer.
What Is an Event? Events – Objects that describe what happened Event sources – The generator of an event Event handlers – A method that receives an event.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
Graphical User Interface (GUI)
Frame Windows Application program, not applet Construct and show frame JFrame frame = new JFrame(); *** frame.show(); *** Set default close operation..
MIT AITI 2004 Swing Event Model Lecture 17. The Java Event Model In the last lecture, we learned how to construct a GUI to present information to the.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
TENTH LECTURE Event and listener. Events and Listeners An event can be defined as a type of signal to the program that something has happened. The event.
1 A Quick Java Swing Tutorial. 2 Introduction Swing – A set of GUI classes –Part of the Java's standard library –Much better than the previous library:
Dept. of CSIE, National University of Tainan 10/21/2012 Responding to User Input.
Chapter 6 Building Java GUIs. MVC Model View Controller The model passes its data to the view for rendering The view determines which events are passed.
Module 13: Swing API Object Oriented Programming(Java)
Java Swing What is swing? Swing is a ”Lightweight” GUI ToolKit for Java Different from AWT / SWT Toolkits for GUIs Few lines of code to produce GUI elements.
A Quick Java Swing Tutorial
GUIs and Events Rick Mercer.
CSC 205 Programming II Lecture 5 AWT - I.
Welcome To java
CompSci 230 S Programming Techniques
Web Design & Development Lecture 11
A Quick Java Swing Tutorial
Abstract Window ToolKit (AWT)
CSE 114 – Computer Science I Event Programming
Ellen Walker Hiram College
MVC Paradigm The MVC paradigm breaks applications or interfaces into three parts: the model, the view, and the controller. A --> 25 % B --> 60 % C -->
Graphical user interface-based programming
Graphics Programming - Frames
A Quick Java Swing Tutorial
Advanced Programming in Java
CiS 260: App Dev I Chapter 6: GUI and OOD.
Presentation transcript:

It attached with method ,class and interface etc… Annotations in java It provides additional information and that can be used by JVM and Java Compiler It attached with method ,class and interface etc… Type 1. Built-in annotation 2.Custom annotation

Built –in annotation 1.Used in java code 1.@override 2.@supppresswarning 3.@deprecated 2. Used in other annotation 1.@inherited 2.@target 3.@rentention

Built-in (cont..) @override : =========== It assures that method of subclass overriding method of super class Class cse{ void get() { s.o.p(“srm”); } Class ece extends cse @override Void get() s.o.p(“vit”);

Cont.. @Suppresswarning =========================== Class cse { @suppresswaring(“unchecked “) PSVM(string arg[]) Stack st=new stack (); St.push(10); St.push(20); }

Cont.. @deprecated ========== Class cse { Void get1() s.o.p(“hai”); } Void get2() s.o.p(“hi”);

Custom annotation It allows user to create annotation . It start with @interface . Type: 1.Marker annotation 2.Single value 3.Multivalue

Cont.. 1.Marker annotation:(no method) @interface user{} ================== 2. Single value(only one method) @interface user{ Int t() default 0; } ============= 3.Mutivalue @interface user { Int t1(); Int t2();

Cont.. @target ========= it is used to specify at which type, the annotation is used. The java.lang.annotation.ElementType enum declares many constants to specify the type of element where annotation is to be applied such as TYPE, METHOD, FIELD etc..

Cont.. @Retention =============== @Retention annotation is used to specify to what level annotation will be available. Whether compiler level or JVM level

Cont.. @Inherited =========== annotations are not inherited automatically to subclasses. The @Inherited annotation marks the annotation to be inherited to subclasses. Example @inherited class super {} Class derive extends super{}

Cont.. import java.lang.annotation.*; import java.lang.reflect.*; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) @interface user{ int count(); } //Applying annotation class H{ @user(count=10) public void get(){ System.out.println(“srm"); } } //Accessing annotation class customclass{ public static void main(String args[])throws Exception { H h=new H(); Method m=h.getClass().getMethod(“get"); user ob=m.getAnnotation(user.class); System.out.println("value is: "+ob.count()); }}

Java Swing Swing API is a set of extensible GUI Components that used to create JAVA based Front End/GUI Applications. MVC M-Model represents data from view V-View represents visual representation of the component's data. C-Controller gets input from user and perform manipulation on that data.

JFRAME import javax.swing.*; public class FirstSwingExample { public static void main(String[] args) { JFrame f=new JFrame(); //creating instance of JFrame JButton b=new JButton("click"); //creating instance of JButton b.setBounds(130,100,100, 40); f.add(b);//adding button in JFrame f.setSize(400,500); f.setLayout(null); f.setVisible(true); } }

JDialog It is used to create small dialog window JFrame f= new JFrame();           d = new JDialog(f , "Dialog Example", true);  

Jpanel It provides space for placing components.   JPanel panel=new JPanel();           panel.setBounds(40,80,200,200);          panel.setBackground(Color.gray);  

Jrootpane public class RootExample2 {   public static void main(String[] args) {     JFrame f = new JFrame();     f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     JRootPane root = f.getRootPane();     // Create a menu bar     JMenuBar bar = new JMenuBar();     JMenu menu = new JMenu("File");     bar.add(menu);     menu.add("Open");     menu.add("Close");     root.setJMenuBar(bar);     // Add a button to the content pane     root.getContentPane().add(new JButton("Hello World"));     // Display the UI     f.pack();     f.setVisible(true);   } }

JlayerdPane JLayeredPane lp = getLayeredPane(); // Create 3 buttons JButton top = new JButton(); top.setBackground(Color.white); top.setBounds(20, 20, 50, 50); JButton middle = new JButton(); middle.setBackground(Color.gray); middle.setBounds(40, 40, 50, 50); JButton bottom = new JButton(); bottom.setBackground(Color.black); bottom.setBounds(60, 60, 50, 50); // Place the buttons in different layers lp.add(middle, new Integer(2)); lp.add(top, new Integer(3)); lp.add(bottom, new Integer(1));

Swing –Components Jbutton : ================= JFrame f=new JFrame("Button Example"); JButton b=new JButton("Click Here"); b.setBounds(50,100,95,30); f.add(b); f.setSize(400,400); f.setLayout(null); f.setVisible(true);

Cont.. Jlable: JFrame f= new JFrame("Label Example"); JLabel l1,l2; l1=new JLabel("First Label."); l1.setBounds(50,50, 100,30); l2=new JLabel("Second Label."); l2.setBounds(50,100, 100,30); f.add(l1); f.add(l2); f.setSize(300,300);

Cont.. JTextField: JFrame f= new JFrame("TextField Example"); JTextField t1,t2; t1=new JTextField("Welcome to Javatpoint."); t1.setBounds(50,100, 200,30); t2=new JTextField("AWT Tutorial"); t2.setBounds(50,150, 200,30); f.add(t1); f.add(t2); f.setSize(400,400);

Cont.. JComboBox: f=new JFrame("ComboBox Example"); String country[]={"India","Aus","U.S.A","England","Newzealand"}; JComboBox cb=new JComboBox(country); cb.setBounds(50, 50,90,20); f.add(cb);

Cont.. Jlist ===================== JFrame f= new JFrame(); DefaultListModel<String> l1 = new DefaultListModel<>(); l1.addElement("Item1"); l1.addElement("Item2"); l1.addElement("Item3"); l1.addElement("Item4"); JList<String> list = new JList<>(l1); list.setBounds(100,100, 75,75); f.add(list);

Cont.. Jtable: =============== f=new JFrame(); String data[][]={ {"101","Amit","670000"}, {"102","Jai","780000"}, {"101","Sachin","700000"}}; String column[]={"ID","NAME","SALARY"}; JTable jt=new JTable(data,column);

Cont.. JTabbedPane: f=new JFrame(); JTextArea ta=new JTextArea(200,200); JPanel p1=new JPanel(); p1.add(ta); JPanel p2=new JPanel(); JPanel p3=new JPanel(); JTabbedPane tp=new JTabbedPane(); tp.setBounds(50,50,200,200); tp.add("main",p1); tp.add("visit",p2); tp.add("help",p3); f.add(tp);

Event handling ActionEvent ---- ActionListener MouseEvent---- MouseListener and MouseMotionListener MouseWheel EventMouseWheelListener KeyEvent KeyListener ItemEvent ItemListener

Event Methods Button MenuItem TextField TextArea Checkbox Choice List public void addActionListener(ActionListener a){} MenuItem TextField public void addTextListener(TextListener a){} TextArea Checkbox public void addItemListener(ItemListener a){} Choice List

Example for event import java.awt.*; import java.awt.event.*; class AEvent extends Frame implements ActionListener{   TextField tf;   AEvent(){      //create components   tf=new TextField();   tf.setBounds(60,50,170,20);   Button b=new Button("click me");   b.setBounds(100,120,80,30);   //register listener   b.addActionListener(this);//passing current instance   //add components and set size, layout and visibility   add(b);add(tf);   setSize(300,300);   setLayout(null);   setVisible(true);   }   public void actionPerformed(ActionEvent e){   tf.setText("Welcome");   public static void main(String args[]){   new AEvent();