1 / 15

GUI programming in java

GUI programming in java. Overview. Window System Visualization Containers and Components Layout Manager User Interface Event Model. Basic of Windows Programming. Message Queue A loop Fetch message from the queue Action Paint Deliver message to proper object.

banyan
Télécharger la présentation

GUI programming in java

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. GUI programming in java

  2. Overview • Window System • Visualization • Containers and Components • Layout Manager • User Interface • Event Model

  3. Basic of Windows Programming • Message Queue • A loop • Fetch message from the queue • Action • Paint • Deliver message to proper object

  4. Basic of Windows Programming User’s Action key event mouse event … while(1) { message = fetch(queue)) switch(message) { case KEY_PRESSED: … case KEY_RELEASED: … case PAINT: … } }

  5. Containers and Components JFrame jf = new JFrame(“Programming Methodology”); JTabbedPane jt = new JTabbedPane(); jt.addTab(“1”, new Label(“Introduction to Compiler”)); jt.addTab(“2”, new Label(“Programming Methodology”)); jt.addTab(“3”, new Label(“Data Structure and Algorithm”)); jt.addTab(“4”, new Label(“Introduction to Compiler”)); jf.getContentPane().add(jt); jf.show(); JFrame ContentPane JTabbedPane Label

  6. Containers and Components JFrame JFrame jf = new JFrame(“Programming Methodology”); JPanel jp = new JPanel(); jp.add(new Button(“Introduction to Compiler”)); jp.add(new Button(“Programming Methodology”)); jp.add(new Button(“Data Structure and Algorithm”)); jp.add(new Button(“Introduction to Compiler”)); jf.getContentPane().add(jp); jf.show(); ContentPane JPanel Button

  7. Layout Manager • Determine position and size of components in a container. • GridLayout, GridBagLayout, FlowLayout, BorderLayout, BoxLayout…

  8. Layout Manager Border layout Border layout + Box layout

  9. User Interface • Interaction with user • Low level input • keyboard input • mouse input • High level input • click a button component • select between a radio buttons • select a menu item

  10. User Interface • Event Source • Every Components you can see • Canvas, TextField, Button, Menu, ScrollBar… • Event Listener • Each event source has its listener • You register your own listener to event creator you have interest in.

  11. invoke registered event listener class A implements ActionListener { public void actionPerformed(ActionEvent e) { System.out.println(“action”); } } User Interface ActionEvent is created Component action

  12. Look and Feel in Swing • AWT vs. Swing • Platform widget vs. Component UI • MVC • Model is logical representation • View is visual representation • Controller handles user input

  13. Look and Feel in Swing

  14. Look and Feel in Swing • Pluggable look and feel try{ UIManager.setLookAndFeel( "javax.swing.plaf.metal.MetalLookAndFeel"); } catch (java.lang.ClassNotFoundException e) { // Can't change look and feel }

  15. References • http://developer.java.sun.com/developer/onlineTraining/new2java/divelog/part1/ • http://developer.java.sun.com/developer/onlineTraining/new2java/divelog/part2/ • http://developer.java.sun.com/developer/onlineTraining/new2java/divelog/part3/ • http://developer.java.sun.com/developer/onlineTraining/new2java/divelog/part4/ • http://developer.java.sun.com/developer/onlineTraining/GUI/Swing1/shortcourse.html • http://developer.java.sun.com/developer/onlineTraining/GUI/Swing2/shortcourse.html

More Related