0
GUI Programming  in Java Tim McKenna [email_address]
GUI Programming Concepts <ul><li>conventional programming:  </li></ul><ul><ul><li>sequence of operations is determined  by...
GUI Design Concepts <ul><li>a wealth of information creates a poverty of attention - Herbert Simon  </li></ul><ul><li>Prin...
GUI Programming Concepts in Java <ul><li>Java GUI (&quot;Swing&quot;) has  components </li></ul><ul><li>Windows GUI has  c...
Java GUI history: the AWT <ul><li>AWT(JDK 1.0, 1.1):  Abstract Window Toolkit </li></ul><ul><li>package: java.awt, java.aw...
Swing in Java <ul><li>Swing(Java 2, JDK 1.2+)  </li></ul><ul><li>lightweight components that do not rely on the native GUI...
Swing Components in Java <ul><li>advanced GUI support. e.g. drag-and-drop </li></ul><ul><li>package names: javax.swing, ja...
running a Swing application <ul><li>java -Dswing.aatext=true  MySwingClass </li></ul><ul><ul><li>the option sets the syste...
Basic GUI Programming Steps in Java <ul><li>declare a container and components </li></ul><ul><li>add components to one or ...
Basic GUI Programming Concepts  in Java <ul><li>Example:  JFrameDemoTM.java, JFrameDemoTM2.java, JFrameDemo.java </li></ul...
GUI Programming: The Java Approach <ul><li>event-driven programming </li></ul><ul><ul><li>a piece of code (i.e.  event han...
Event-driven Programming  in Java <ul><li>event source:  a GUI component that  generates / fires  an  event </li></ul><ul>...
Event Handling in Java <ul><li>the delegation event model - event listeners must be    registered  with an event   source ...
Event Handling in Java <ul><li>registration of an event listener - write a class that  implements  an [ event type]Listene...
Event Handling in Java <ul><li>a listener interface has a list of standard event handlers (i.e. methods) </li></ul><ul><li...
Event Handling in Java <ul><li>different ways of coding the event listeners </li></ul><ul><li>JFrameDemoTM.java uses named...
Upcoming SlideShare
Loading in...5
×

Gu iintro(java)

367

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
367
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
14
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Gu iintro(java)"

  1. 1. GUI Programming in Java Tim McKenna [email_address]
  2. 2. GUI Programming Concepts <ul><li>conventional programming: </li></ul><ul><ul><li>sequence of operations is determined by the program </li></ul></ul><ul><ul><li>what you want to happen, happens when you want it </li></ul></ul><ul><li>event-driven programming: </li></ul><ul><ul><li>sequence of operations is determined by the user ’s interaction with the application’s interface </li></ul></ul><ul><ul><li>anything that can happen, happens at any time </li></ul></ul>
  3. 3. GUI Design Concepts <ul><li>a wealth of information creates a poverty of attention - Herbert Simon </li></ul><ul><li>Principles of good GUI Design </li></ul><ul><li>IBM's Design concepts </li></ul><ul><li>Saul Greenberg's HCI pages </li></ul><ul><li>Tim's HCI notes </li></ul>
  4. 4. GUI Programming Concepts in Java <ul><li>Java GUI (&quot;Swing&quot;) has components </li></ul><ul><li>Windows GUI has controls </li></ul><ul><li>Unix GUI has widgets </li></ul><ul><li>examples: labels, buttons, check boxes, radio buttons, text input boxes, pull down lists </li></ul><ul><li>Java Swing components: JLabel, JButton, JCheckBox, JRadioButton, JTextField, JTextArea, JComboBox </li></ul>
  5. 5. Java GUI history: the AWT <ul><li>AWT(JDK 1.0, 1.1): Abstract Window Toolkit </li></ul><ul><li>package: java.awt, java.awt.event </li></ul><ul><li>heavyweight components using native GUI system elements </li></ul><ul><li>used for applets until most browsers supported JRE 1.2 </li></ul>
  6. 6. Swing in Java <ul><li>Swing(Java 2, JDK 1.2+) </li></ul><ul><li>lightweight components that do not rely on the native GUI or OS </li></ul><ul><li>“ look and feel” of Swing components </li></ul><ul><ul><li>are identical on different platforms </li></ul></ul><ul><ul><li>can be customized </li></ul></ul><ul><li>Swing inherits from AWT </li></ul><ul><li>AWT still used for events, layouts </li></ul>
  7. 7. Swing Components in Java <ul><li>advanced GUI support. e.g. drag-and-drop </li></ul><ul><li>package names: javax.swing, javax.swing.event </li></ul><ul><li>components inherit from JComponent </li></ul><ul><li>components are added to a top-level container: JFrame, JDialog, or JApplet. </li></ul>
  8. 8. running a Swing application <ul><li>java -Dswing.aatext=true MySwingClass </li></ul><ul><ul><li>the option sets the system property &quot;swing.aatext&quot; to &quot;true&quot; to enable anti-aliasing for every JComponent </li></ul></ul><ul><li>javaw runs a GUI without the console window </li></ul><ul><li>e.g. HelloWorldSwing.java </li></ul>
  9. 9. Basic GUI Programming Steps in Java <ul><li>declare a container and components </li></ul><ul><li>add components to one or more containers using a layout manager </li></ul><ul><li>register event listener(s) with the components </li></ul><ul><li>create event listener method(s) </li></ul>
  10. 10. Basic GUI Programming Concepts in Java <ul><li>Example: JFrameDemoTM.java, JFrameDemoTM2.java, JFrameDemo.java </li></ul><ul><li>container : a screen window/applet window/panel that groups and arranges GUI components </li></ul><ul><li>GUI component: an object with visual representation </li></ul><ul><li>Swing containers: JFrame, JApplet, JPanel </li></ul><ul><li>AWT containers: Frame, Applet, Panel </li></ul>
  11. 11. GUI Programming: The Java Approach <ul><li>event-driven programming </li></ul><ul><ul><li>a piece of code (i.e. event handler ) is attached to a GUI component </li></ul></ul><ul><ul><li>an event handler is called when an event (e.g. a mouse click) is activated / fired </li></ul></ul><ul><li>The Delegation Event Model in Java </li></ul><ul><ul><li>processing of an event is delegated to an object (the listener) in the program </li></ul></ul>
  12. 12. Event-driven Programming in Java <ul><li>event source: a GUI component that generates / fires an event </li></ul><ul><li>event: a user interaction (e.g. a click on the button) </li></ul><ul><li>event listener: an object that has implemented event handlers to react to an event </li></ul>
  13. 13. Event Handling in Java <ul><li>the delegation event model - event listeners must be registered with an event source in order to receive notification </li></ul>
  14. 14. Event Handling in Java <ul><li>registration of an event listener - write a class that implements an [ event type]Listener interface - create an instance of that class (i.e. an event listener) - register the listener with a GUI component: add[event type]Listener ( <an event listener> ) </li></ul>
  15. 15. Event Handling in Java <ul><li>a listener interface has a list of standard event handlers (i.e. methods) </li></ul><ul><li>API documentation - java.awt.event - event classes - listener interfaces - adapter classes </li></ul>
  16. 16. Event Handling in Java <ul><li>different ways of coding the event listeners </li></ul><ul><li>JFrameDemoTM.java uses named inner classes. </li></ul><ul><li>JFrameDemoTM2.java uses named inner classes and shows how to consolidate window closing from two different events. </li></ul><ul><li>JFrameDemo.java does not use inner classes. </li></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×