Www.javacup.ir Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.

Slides:



Advertisements
Similar presentations
Introduction to classes Sangeetha Parthasarathy 06/11/2001.
Advertisements

Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
GUI Tutorial Day 3. Custom Dialog Create, display, hide, retrieve information.
Unit 08 & 091 Nested Classes Introduction Inner Classes Local Classes Anonymous Classes Exercises.
Java GUI Libraries Swing Programming. Swing Components Swing is a collection of libraries that contains primitive widgets or controls used for designing.
© L.Lúcio, An example GUI in Java n Two graphic libraries in Java u AWT u Swing n Swing is more recent than AWT: u Built on top of AWT classes;
Inner Classes. Lecture Objectives Learn about inner classes. Know the differences between static and non- static inner classes. Designing and using inner.
Creating a GUI with Swing. Introduction Very useful link: Swing – is a part of JFC (Java Foundation.
Graphical User Interfaces
Unit 081 Introduction to Nested Classes Nested classes are classes defined within other classes The class that includes the nested class is called the.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
CSE 501N Fall ‘09 20: Event Handling and Inner Classes 17 November 2009 Nick Leidenfrost.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
1 Block1 – unit 2 (The Case study in Budd 5-6).  create a small application that uses the Abstract Windowing Toolkit (AWT)  Swing packages to simulate.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Object-Oriented Programming (Java), Unit 18 Kirk Scott 1.
 2003 Joel C. Adams. All Rights Reserved. Calvin CollegeDept of Computer Science(1/20) More Swing Widgets and Listeners Joel Adams and Jeremy Frens Calvin.
Swing GUI Components You can create graphics components to place on your applet using classes available in the Swing package ( javax.swing ) Class names.
Chapter 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
1 Class 6. 2 Objectives Objectives Enable your applications to perform actions in response to JButton clicks Get the text the user enters in a textfield.
Creating a GUI with JFC/Swing. What are the JFC and Swing? JFC –Java Foundation Classes –a group of features to help people build graphical user interfaces.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
2-Dec-15 Inner Classes By Alguien Soy. 2 Inner classes All the classes so far have been “top level” It is possible (and useful) to define a class inside.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Graphical User Interface(GUI)
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Nested Classes CompSci 230 S Software Construction.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 5.1 Test-Driving the Enhanced Inventory Application.
Access Specifier. Anything declared public can be accessed from anywhere. Anything declared private cannot be seen outside of its class. When a member.
Event-Driven Programming F Procedural programming is executed in procedural order. F In event-driven programming, code is executed upon activation of events.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
Frame Windows Application program, not applet Construct and show frame JFrame frame = new JFrame(); *** frame.show(); *** Set default close operation..
Sadegh Aliakbary Sharif University of Technology Fall 2010.
1 DemoBasic_v3, DemoBasic_v4 JButton JLabel. 2 Registering an ActionListener Register by invoking the following from within constructor DemoBasicFrame.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Modular Event Handling
CompSci 230 S Software Construction
Graphical User Interface(GUI)
CompSci 230 S Programming Techniques
MVC Paradigm The MVC paradigm breaks applications or interfaces into three parts: the model, the view, and the controller. A --> 25 % B --> 60 % C -->
Inner Classes 11/14/ Dec-04 inner_classes.ppt.
Overloading and Overriding
Introduction to Event Handling
Inner Classes 29-Nov-18.
class PrintOnetoTen { public static void main(String args[]) {
Advanced Programming in Java
어서와 Java는 처음이지! 제13장 실전프로젝트.
Inner Classes 17-Apr-19.
Inner Classes 21-Apr-19.
Inner Classes 1-May-19.
Inner Classes 11-May-19.
CiS 260: App Dev I Chapter 6: GUI and OOD.
Inner Classes 18-May-19.
Inner Classes.
Presentation transcript:

Sadegh Aliakbary

Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP is clearly noted as the source in the used case. JAVACUP shall not be liable for any errors in the content, or for any actions taken in reliance thereon. Please send your feedback to 2

Agenda Inner classes Anonymous inner class 3

Class Types class FriendlyClass{ } public class OuterClass { private int value; public class Inner{ public void f(){ … } JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source4 Friendly Class Public class Inner Class

Inner Classes Declared in another class Instantiated using a reference object of outer class Has access to this object The inner class can be static No reference object of outer class is needed No access to outer class is provided JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source5

public class OuterClass { private int value = 2; class Inner{ public void innerMethod(){ OuterClass.this.value = 5; } public void outerMethod(){ Inner inner = new Inner(); inner.innerMethod(); } public static void main(String[] args) { OuterClass outer = new OuterClass(); System.out.println(outer.value); outer.outerMethod(); System.out.println(outer.value); } JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source6 OuterClass.this is implicitly saved in inner object

public class OuterClass { private int value = 2; class Inner{ public void f(){ OuterClass.this.value = 5; } public static void main(String[] args) { OuterClass outer = new OuterClass(); OuterClass.Inner inner = outer.new Inner(); System.out.println(outer.value); inner.f(); System.out.println(outer.value); } JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source7 Why we need outer reference?

class OuterClass { static class Inner{ public void f(){ System.out.println("f() invoked"); } public class MainClass { public static void main(String[] args) { OuterClass.Inner in = new OuterClass.Inner() ; in.f(); } JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source8

Inner Class Specifiers static final Access Specifiers public private Friendly (no specifier) protected JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source9

Anonymous Inner Class An inner class With no name Created once Used once No access to this class from any other place Once created and used JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source10

interface Inner{ void innerMethod();} public class OuterClass { private int value = 2; public void outerMethod(){ Inner inner = new Inner() { public void innerMethod() { OuterClass.this.value = 5; } }; inner.innerMethod(); } public static void main(String[] args) { OuterClass outer = new OuterClass(); System.out.println(outer.value); outer.outerMethod(); System.out.println(outer.value); } JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source11

Anonymous Inner Class Usually implements an interface Or extends another class And Overrides some special method Main Application : Event Handlers JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source12

public class MyFrame extends JFrame{ JButton button; JTextField textbox; public MyFrame(){ button = new JButton("Click!"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, textbox.getText()); } }); add(button); textbox = new JTextField(10); add(textbox); } JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source13

JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source14