Presentation is loading. Please wait.

Presentation is loading. Please wait.

Object Oriented Programming Ders 11: Interfaces Mustafa Emre İlal

Similar presentations


Presentation on theme: "Object Oriented Programming Ders 11: Interfaces Mustafa Emre İlal"— Presentation transcript:

1 Object Oriented Programming Ders 11: Interfaces Mustafa Emre İlal emreilal@iyte.edu.tr

2 Recap Assignment 9 The Collections Framework

3 Today Assignment 10 Interfaces – Swing classes Thinking in Java – Chapter 14

4 User Interface Graphical User Interface [GUI] "gooey" Every operating system’s (platform) windowing mechanisms differ vastly For each platform the GUI code needs to be redesigned Java interface runs on the Java platform and is developed only once

5 java.awt.* and javax.swing.* Java’s GUI classes are in these two packages AWT (Abstract Windowing Toolkit) – old; were not totally platform independent –Button –TextField Swing (part of JFC) – recommended; platform independent, provides more options –JButton –JTextField

6 Main windows 3 often used windows (top-level containers) JFrame JDialog JApplet

7 Containers JPanel JScrollPane JTabbedPane JToolBar JSplitPane

8 Controls (widgets) JMenu JSpinner JSlider JTextField JComboBox JButton JList JRadioButton JCheckBox

9 Information JProgressBar JLabel JToolTip

10 Complex Classes JFileChooser JTree JTable JColorChooser

11 Windows Components are placed in containers which are in turn placed inside other containers to form a tree- like hierarchy

12 Layout Manager When components are placed into a containers, where they appear is controlled by rules that are handled by LayoutManager s Each container will have a LayoutManager. Various LayoutManagers: –FlowLayout –GridLayout –BorderLayout –etc.

13 Example Layouts

14 Event User interacts with our application through the operating system interface Keyboard and mouse is tracked by the OS. Movement of the mouse, click on a button, pressing on a key are all “events” Applications are notified by the OS about events that occur over their windows. Making sense out of events (user requests) and responding to them are the applications’ responsibility.

15 Event The events that are sent by the OS to the Java apps are represented by either an “awt event” or a “swing event” and are associated with the component they occur on. AWTEvent ActionEventComponentEventWindowEvent MouseEventMouseMotionEventFocusEvent KeyEventContainerEventHierarchyEvent InputMethodEventItemEventvs Swing Event ListSelectionListenerMenuListenerHyperlinkListener TreeSelectionListenerDocumentEventvs

16 EventListener When an event takes place, starting with the component it takes place on, all the elements in the GUI hierarchy above the source component gets notified These components in turn notify all the EventListeners that have registered with them for the type of event that has occured EventListeners need to be written by you and have to implement the proper EventListener interface.

17 Example – EventListener public class MyClass implements ActionListener {... public void actionPerformed(ActionEvent e) {... } MyClass mc = new MyClass(); someComponent.addActionListener(mc);

18 Assignment 12a Write an application that reads a text file and displays the number of vowels and consonents on a GUI. TextFile.txt Consonents Vowels Read 785 5543 Reading complete

19 Assignment 12b Develop a GUI for the application you have written for assignment 11 : –Whenever the “Create Shapes” button is pressed, create 10 random shapes and display them on the canvas. (pay attention to shape sizes) Create Shapes

20 Next Week Final exam? Review Projects...


Download ppt "Object Oriented Programming Ders 11: Interfaces Mustafa Emre İlal"

Similar presentations


Ads by Google