1 / 34

SE204 Object-Oriented Development

SE204 Object-Oriented Development Jacqueline McQuillan B.Sc. NUI Maynooth Overview Java Graphics Threads I/O in Java Object Serialization Remote Method Invocation (RMI) More … Java Graphics Basic Java Graphics

paul
Download Presentation

SE204 Object-Oriented Development

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. SE204 Object-Oriented Development Jacqueline McQuillan B.Sc. NUI Maynooth

  2. Overview • Java Graphics • Threads • I/O in Java • Object Serialization • Remote Method Invocation (RMI) • More … 2004/5: SE204: Lecture 1&2

  3. Java Graphics

  4. Basic Java Graphics • We can use Java to develop computer graphics based applications, both for 2-dimensional drawing and for Graphical User Interfaces(GUIs). • We will begin by looking at GUI programming in Java 2004/5: SE204: Lecture 1&2

  5. A Simple Example 2004/5: SE204: Lecture 1&2

  6. Another Example 2004/5: SE204: Lecture 1&2

  7. Graphical User Interface • Use components to build our GUI • It is possible for a component to have a peer • The peer is a native implementation of that component • for instance, a button object in an application will correspond to the native button implemented by the operating system 2004/5: SE204: Lecture 1&2

  8. AWTThe Abstract Windows Toolkit • java.awt • components are heavyweight • appearance of awt component is determined by the peer component • look is platform dependent 2004/5: SE204: Lecture 1&2

  9. Swing • javax.swing • most of its components are lightweight • component has no peer • look is determined by the java runtime environment, so will look the same regardless of the platform being used • it is possible to make the swing components look like anything you want. This is referred to as pluggable look and feel(PLAF) 2004/5: SE204: Lecture 1&2

  10. Main categories of Java GUI Framework • Components:These are the building blocks of GUI based applications. Examples: JFrame, JButton, JLabel • Containers: A container is a component that holds other components. Examples: JFrame, JPanel, JWindow • Layout managers:These are used for laying out components in a container. 2004/5: SE204: Lecture 1&2

  11. Main categories of Java GUI Framework • Events: An action is translated into an EventObject. This object contains details about the event including type of action and where it occurred. Examples: key presses, button presses, mouse moves • Event Listeners: A class indicates which events it would like to receive. This is done by installing event listener objects. 2004/5: SE204: Lecture 1&2

  12. Main categories of Java GUI Framework • Graphics and Imaging classes:These are used for drawing and displaying images. Examples: Graphics, Color, Font, Rectangle, Image 2004/5: SE204: Lecture 1&2

  13. Swing classes in UML notation 2004/5: SE204: Lecture 1&2

  14. JFrame • A Frame object is an (optionally) resizable top-level window with • a title • a minimize box • a maximize box • a close box • JFrame is a direct extension of the AWT Frame class. The AWT Frame class extends the Window class 2004/5: SE204: Lecture 1&2

  15. An Example of a JFrame 2004/5: SE204: Lecture 1&2

  16. Using JFrame Let’s look at an example 2004/5: SE204: Lecture 1&2

  17. Using JFrame Let’s look at another example 2004/5: SE204: Lecture 1&2

  18. Both of the above programs give the same output 2004/5: SE204: Lecture 1&2

  19. Another JFrame Example 2004/5: SE204: Lecture 1&2

  20. Let’s look at the output of the previous program 2004/5: SE204: Lecture 1&2

  21. Now, lets look at the code • super(s); • this invokes the constructor of the parent superclass … the positioning of this is vital (it can/should only be done on the first line of the constructor method of the new subclass) • getContentPane().setBackground(Color.blue); • here, we use the Color blue to set the background colour, note the use of getContentPane(), this gives a reference to the JFrame’s container. 2004/5: SE204: Lecture 1&2

  22. setSize(250, 100); • specifies the width and height of theframe in pixels • setLocation(0,0); • specifies where to place the frame on the desktop • setVisible(true); • used to tell the screen to display the frame 2004/5: SE204: Lecture 1&2

  23. The Toolkit Class • This is an abstract class that provides an interface to platform specificdetails like window size, available fonts and images. • We never directly instantiate an object of type Toolkit. We obtain a toolkitobject by invoking the static getDefaultToolkit() method. This will give usan object that is appropriate for our system. Toolkit tk = Toolkit.getDefaultToolkit(); 2004/5: SE204: Lecture 1&2

  24. The Toolkit Class • Situations where you might need to use a Toolkit • want to load an image file, use getImage() • want to obtain information about the screen, use getScreenSize() • want information about available fonts, use getFontList() 2004/5: SE204: Lecture 1&2

  25. Construct a frame that fills the entire window 2004/5: SE204: Lecture 1&2

  26. 2004/5: SE204: Lecture 1&2

  27. JPanel • It is a component • It can contain other components • It can be structured using the layout managers • Constructors • JPanel() -- Creates a new JPanel with a FlowLayout 2004/5: SE204: Lecture 1&2

  28. Using JPanel 2004/5: SE204: Lecture 1&2

  29. 2004/5: SE204: Lecture 1&2

  30. Let’s look at the output of the previous program 2004/5: SE204: Lecture 1&2

  31. Adding Components • We will not try to learn everything about a particular user interfacecomponent. • It will be better if we try to understand the concepts and then we will beable to search the Java documentation for the details. • Adding a component to a container: 1. Construct the component object 2. Add it to the container 2004/5: SE204: Lecture 1&2

  32. Using JButton 2004/5: SE204: Lecture 1&2

  33. 2004/5: SE204: Lecture 1&2

  34. Now, lets look at the code • b1 = new JButton(“Button 1”); • creates an instance of JButton with the label “Button 1” • add(b1); • adds the JButton b1 to the container buttonPanel • getContentPane().add(p1); • adds the component p1 to the frame, note the use of getContentPane(), this gives a reference to the JFrame’s container. 2004/5: SE204: Lecture 1&2

More Related