Download
object oriented programming n.
Skip this Video
Loading SlideShow in 5 Seconds..
Object Oriented Programming PowerPoint Presentation
Download Presentation
Object Oriented Programming

Object Oriented Programming

70 Vues Download Presentation
Télécharger la présentation

Object Oriented Programming

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
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. JFrame JDialog JApplet Main windows • 3 often used windows (top-level containers)

  7. Containers JScrollPane JPanel JToolBar JTabbedPane JSplitPane

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

  9. Information JToolTip JLabel JProgressBar

  10. Complex Classes JColorChooser JFileChooser JTree JTable

  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.

  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 Read 785 Vowels 5543 Consonents 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...