CS 209 Programming in Java #13 Multimedia

Size: px
Start display at page:

Download "CS 209 Programming in Java #13 Multimedia"

Transcription

1 CS 209 Programming in Java #13 Multimedia Part of Textbook Chapter 14 Spring, 2006 Instructor: J.G. Neal 1 Topics Multimedia Displaying Images Using the MediaTracker class Images in Applets and Applications Playing Audio Clips Audio Clips in Applets Using the Timer Class for Animation Example Programs 2

2 Multimedia Media Can include images, audio, video, etc. Java program needs to: Get the media files Display/play/pause/replay/stop the media objects How to handle media in: Applets Applications 3 Image Display Relevant Classes Relevant classes for getting and displaying Images: 1. Use the Toolkit class and its methods such as getdefaulttoolkit and getimage 2. Use the Applet class and its methods such as getcodebase, getimage 3. Use the Class class and its methods such as getresouce 4. Use the Image class and its methods such as getheight and getwidth 5. Use the Graphics class and its method drawimage 6. Use the ImageIcon class and its methods such as loadimage and painticon 4

3 Methods Used to Get an Image for Display Methods in the Applet class Get base URL URL getcodebase() - Gets the base URL for folder URL getdocumentbase() - Returns an absolute URL for the document in which the applet is embedded Get the image public Image getimage(url url) public Image getimage(url url, String filename) 5 Getting Images in a Java Program Approach 1: Use JApplet methods getcodebase and getimage Example: String imagepath0 = "images/dukewave.gif"; String imagepath1 = "images/duke2.gif"; img0 = getimage(getcodebase(), imagepath0); img1 = getimage(getcodebase(), imagepath1); try { mt.addimage(img0, 0); mt.addimage(img1, 0); mt.waitforid(0); } catch (Exception ex) { System.out.println("\n" + ex.tostring()); } 6

4 Getting Images in a Java Program Approach 2: Use the URL class and method getresource from class Class Example: String imagepath0a = "../images/dukewave.gif"; String imagepath1a = "../images/duke2.gif"; Class object = this.getclass(); URL url0 = object.getresource(imagepath0a); URL url1 = object.getresource(imagepath1a); System.out.println("url0 = " + url0.tostring()); System.out.println("url1 = " + url1.tostring()); if ((url0!= null) && (url1!= null)) { img0 = getimage(url0); img1 = getimage(url1); try { mt.addimage(img0, 0); mt.addimage(img1, 0); mt.waitforid(0); } catch (Exception ex) { System.out.println("\n" + ex.tostring()); } } 7 Getting Images in a Java Program Approach 3: Use the Toolkit class Static Toolkit getdefaulttoolkit() - Gets the default AWT toolkit Image getimage(string filename) - Returns an image which gets pixel data from the specified file, whose format can be either GIF, JPEG or PNG Image getimage(url url) - Returns an image which gets pixel data from the specified URL Also has methods to: Get the screen resolution in dots-per-inch Get the screen size Get the system clipboard Among others Example: img[i] = Toolkit.getDefaultToolkit().getImage(imgFileName); 8

5 Displaying Images Using Graphics Methods Methods in the Graphics class to draw the image drawimage(image img, int x, int y, Color bgcolor, ImageObserver observer) - Draws the image in the specified location. The image s upper left corner is at (x, y) in the coordinate space of the graphics context. Transparent pixels are drawn in the bgcolor. The observer is the object on which the image is displayed. The image is cut off if it is larger than the area upon which it is drawn. drawimage(image img, int x, int y, ImageObserver observer) - Same as above, but no bgcolor. drawimage(image img, int x, int y, int width, int height, ImageObserver observer) - Draws a scaled version of the image. drawimage(image img, int x, int y, int width, int height, ImageObserver observer) - Same as above, but includes background color. 9 MediaTracker Class A utility class to track the status of media objects In the package: java.awt Use the import statement: import java.awt.mediatracker; Or use import statement: import java.awt.*; Media objects Could include images, audio clips, etc. As of j2sdk1.4.0, only images were supported (continued on next slide) 10

6 MediaTracker Class (cont.) To use a MediaTracker: Create an instance of the MediaTracker class MediaTracker(Component c) - Track for component c Call the MediaTracker addimage method for each image to be tracked addimage(image image, int id) - adds an image to the list of images being tracked by this media tracker addimage(image image, int id, int w, int h) - adds a scaled image to the list of images being tracked by this tracker Call the MediaTracker checkall method checkall() - checks to see if all images being tracked by this media tracker have finished loading; does not start loading any images checkall(boolean load) - checks to see if all images being tracked by this media tracker have finished loading; if the parameter is true, this method starts loading any images that are not yet being loaded (continued on next slide) 11 MediaTracker Class (cont.) Each image can be assigned a priority level identifier ID The ID controls the priority order in which images are fetched The ID is commonly not unique per image Images with a lower ID are loaded in preference to those with a higher ID number Call one of the wait methods to control processing void waitforall() - starts loading all tracked images; waits until all the images being tracked have finished loading void waitforid(int id) - starts loading all tracked images with specified ID (priority level); waits until all the images with the specified ID have finished loading 12

7 Example Java Program Purpose: To demonstrate Use of images in a Java program Providing adequate display area and scroll capabilities Program: Class name: ImageEx Package name: mymediaexs Project name: MyMediaExs Program code: See next pages 13 Example Program Execution 14

8 Printing C:\Documents and Settings\jgneal\My Documents\MyDev\MyJava\MyMedia\MyMediaExs\src\mymediaexs\ImageEx.java at 4/27/06 5:16 1 package 2 3 import 4 import 5 import 6 import 7 8 public class ImageEx extends JFrame { 9 // Instance variables 10 private 11 private 12 private private Image img = null 15 private MediaTracker mt = new MediaTracker( this 16 private int 17 private float 18 private float // The main method required for an application program 21 public static void main( String[] args ) { 22 JFrame frame = new ImageEx // Construct the window 23 frame.setsize(new Dimension 24 frame.setdefaultcloseoperation 25 frame.setvisible( true // Make the window visible 26 } public ImageEx() { 29 super 30 Container c = getcontentpane // Get content pane for JFrame window 31 c.setlayout( new BorderLayout // Set layout manager for window 32 CanvasPanel cpan = new CanvasPanel img = Toolkit.getDefaultToolkit().getImage 35 try { 36 mt.addimage 37 mt.waitforid 38 System.out.println 39 } catch ( Exception ex ) { 40 System.out.println( "\n" + ex.tostring 41 } 42 h = img.getheight( null 43 w = img.getwidth( null 44 cpan.setpreferredsize( new Dimension( Math.round(scaleFactorUp * w), 45 Math.round((scaleFactorUp + Page 1

9 Printing C:\Documents and Settings\jgneal\My Documents\MyDev\MyJava\MyMedia\MyMediaExs\src\mymediaexs\ImageEx.java at 4/27/06 5:16 46 cpan.setvisible( true 47 JScrollPane jscrollpane = new JScrollPane(cPan, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, 49 c.add 50 } // Class to provide a drawing surface for graphics display 53 class CanvasPanel extends JPanel { 54 // Constructor 55 public CanvasPanel() { 56 setbackground 57 } public void paintcomponent ( Graphics g ) { 60 super.paintcomponent 61 int 62 int 63 int 64 g.drawstring( "Image Width: " + w + ", Height: " + h, xpos, ypos 65 g.drawimage( img, xpos, ypos + sp, null // Draw scaled down version of image using method drawimage 68 int wdown = Math.round 69 int hdown = Math.round 70 g.drawstring( "Image scaled down by factor of: " + scalefactordown + 71 ", Width: " + wdown + ", Height: " + hdown, 73 g.drawimage( img, xpos, 5*sp + h, wdown, hdown, null // Create new scaled up version of image and draw it 76 int wup = Math.round 77 int hup = Math.round 78 g.drawstring( "Image scaled up by factor of: " + scalefactorup + 79 ", Width: " + w*scalefactorup + ", Height: " + h*scalefactorup, 81 g.drawimage( img, xpos, 8*sp + h + hdown, wup, hup, null 82 } 83 } // End canvaspanel class 84 } 85 Page 2

10 Displaying Images Using the ImageIcon Class Constructors and methods in the ImageIcon class Create an ImageIcon ImageIcon(Image img) - Creates ImageIcon from Image object ImageIcon(String filename) - Creates ImageIcon from file ImageIcon(URL url) - Creates ImageIcon from url Methods in the ImageIcon class int geticonheight() - Gets height of ImageIcon object int geticonwidth() - Gets width of ImageIcon object void loadimage(image img) - Loads image, returning when load is complete void painticon(component c, Graphics g, int x, int y) - Paints the icon 15 Create New Component to Display Image Various components can display images Using the JLabel class JLabel(Icon icon) JLabel(Icon icon, int halignment) JLabel(String text, Icon icon, int halignment) void seticon(icon icon) Using the JButton class JButton(Icon icon) JButton(String text, Icon icon) 16

11 Example Program Purpose: To demonstrate Use of an application program and Use of images in the graphical user interface Program: Class name: TextCompEx2Done Package name: widgetexs Project name: WidgetExs Questions: Can an image be replaced during runtime? If so, how? 17 Example Program 18

12 Printing C:\Documents and Settings\jgneal\My Documents\MyDev\MyJava\GuiDev\WidgetExs\src\widgetexs\TextCompEx2Done.java at 4/28/06 1 package 2 3 import 4 import 5 import 6 import 7 import 8 9 public class TextCompEx2Done extends JFrame implements ActionListener, ItemListener { 10 // Declare instance variables 11 private // Explanatory info for user 12 private 13 private //JCheckBox for setting line wrap 14 private // The JComboBox for font selection 15 private //JCheckBoxes for two font styles 16 private // The JComboBox for font size selection 17 private // Display area for text private // The color defined by user 20 private int 21 private int 22 private 23 private Font selectedfont = new Font(selectedFace, selectedstyle, 25 private String fontnames[] = { 27 private String fontsizes[] = { // The main method required for an application program 31 public static void main(string[] args) { 32 JFrame frame = new TextCompEx2Done // Construct the window 33 frame.setsize(new Dimension // Set its size 34 frame.setdefaultcloseoperation 35 frame.setvisible(true // Make the window visible 36 } public TextCompEx2Done() { 39 // Call parent constructor and set title in title bar of window 40 super 41 Container c = getcontentpane // Get reference to content pane 42 c.setlayout(new BorderLayout // Set layout for content pane JPanel jpan = new JPanel(new GridLayout // Create JComboBoxes for user selection of font and font size Page 1

13 Printing C:\Documents and Settings\jgneal\My Documents\MyDev\MyJava\GuiDev\WidgetExs\src\widgetexs\TextCompEx2Done.java at 4/28/06 47 jcboxfont = new JComboBox 48 jcboxfont.additemlistener(this 49 jpan.add jcboxsize = new JComboBox 52 jcboxsize.setmaximumrowcount 53 jcboxsize.additemlistener(this 54 jpan.add // Create JButton for user to choose text color 57 coloritem = new JButton 58 coloritem.addactionlistener(this 59 jpan.add // Create JCheckBox to enable user to line wrap on/off 62 linewrap = new JCheckBox("Line Wrap", false 63 linewrap.additemlistener(this 64 jpan.add // Create JCheckBoxes for two font styles, but not as a group 67 fstylebold = new JCheckBox("Bold", false 68 fstylebold.additemlistener(this 69 jpan.add fstyleitalic = new JCheckBox("Italic", false 72 fstyleitalic.additemlistener(this 73 jpan.add c.add // Get and display images for decorative purposes 78 URL url1 = this.getclass().getresource 79 JLabel jlabel1 = new JLabel(new ImageIcon 80 jlabel1.setborder(new EtchedBorder 81 c.add URL url2 = this.getclass().getresource 84 JLabel jlabel2 = new JLabel(new ImageIcon 85 jlabel2.setborder(new EtchedBorder 86 c.add // Create and add the JTextArea to be used for text display and editing 90 textarea = new JTextArea 91 textarea.setfont 92 textarea.setlinewrap(false 93 textarea.setborder(new TitledBorder Page 2

14 Printing C:\Documents and Settings\jgneal\My Documents\MyDev\MyJava\GuiDev\WidgetExs\src\widgetexs\TextCompEx2Done.java at 4/28/06 94 JScrollPane jspane = new JScrollPane 95 c.add 96 } public void actionperformed(actionevent e) { 99 if (e.getsource() == coloritem) { 100 Color returnedcolor = JColorChooser.showDialog(this, 102 if (returnedcolor!= null) { 104 textarea.setforeground 105 } 106 } 107 } public void itemstatechanged(itemevent e) { // If the JCheckBox for Bold style was clicked, set the applet's font 112 // style based on whether Bold was selected or deselected 113 if (e.getsource() == fstylebold) 114 if (e.getstatechange() == ItemEvent.SELECTED) 116 else 117 if (e.getstatechange() == ItemEvent.DESELECTED) // If the JCheckBox for Italic style was clicked, set the applet's font 121 // style based on whether Italic was selected or deselected 122 if (e.getsource() == fstyleitalic) 123 if (e.getstatechange() == ItemEvent.SELECTED) 125 else 126 if (e.getstatechange() == ItemEvent.DESELECTED) // If the JCheckBox for line wrap was selected or not, set 130 // the JTextArea's line wrap accordingly 131 if (e.getsource() == linewrap) 132 if (e.getstatechange() == ItemEvent.SELECTED) 133 textarea.setlinewrap(true 134 else 135 if (e.getstatechange() == ItemEvent.DESELECTED) 136 textarea.setlinewrap(false // If one of the items in the JComboBox was selected, 139 // set the fontname variable to the user's selection 140 if (e.getsource() == jcboxfont) { Page 3

15 Printing C:\Documents and Settings\jgneal\My Documents\MyDev\MyJava\GuiDev\WidgetExs\src\widgetexs\TextCompEx2Done.java at 4/28/ selectedface = fontnames[jcboxfont.getselectedindex 142 } if (e.getsource() == jcboxsize) { 145 selectedsize = Integer.parseInt(fontSizes[jcboxSize. getselectedindex 146 } textarea.setfont(new Font(selectedFace, selectedstyle, 149 } } Page 4

16 Using Audio Clips Methods in the Applet class Methods for using audio clips AudioClip getaudioclip(url url) - Returns the AudioClip object specified by the url; always returns immediately; data loaded when attempt to play is made static AudioClip newaudioclip(url url) - Returns the AudioClip object specified by the url Methods in the AudioClip interface class Methods for using audio clips void play() - Plays this audio clip starting from the beginning void loop() - Plays this audio clip in a loop starting at beginning void stop() - Stops playing this audio clip 19 Purpose: To demonstrate Example Program Use of an applet program and Use of audio and images in the graphical user interface Program: Class name: FlagAnthem Package name: mediaexs Project name: MediaExs Code is available on instructor s webpage Questions: What are some problems or shortcomings of this program? 20

17 Example Program 21 Timer Class Purpose Has a specified delay time interval, and repeatedly fires an action event once per time interval (e.g., once per second) The delay time interval is the time between action events For example, an animation object can use a Timer as the trigger for drawing its frames Setting up a Timer involves 1. Creating a Timer object, 2. Registering one or more action listeners on it, and 3. Starting the timer using the start method 22

18 Timer Class Selected constructors and methods Constructor Timer(int delay, ActionListener listener) - Creates a Timer that will notify its listeners every delay milliseconds Methods void setdelay(int delay) - Sets the Timer s delay, the number of milliseconds between successive action events void start() - Starts the Timer, causing it to start sending action events to its listeners void stop() - Stops the Timer, causing it to stop sending action events to its listeners 23 Example Program Purpose: To demonstrate Use of an application program and Use of a Timer object to implement animation Program: Class name: ApplicWTimer Package name: mymediaexs Project name: MyMediaExs Questions: How would you vary (e.g., slow down or speed up) the rate at which the images appear to move across the applet? 24

19 Example Program 25

20 Printing C:\Documents and Settings\jgneal\My Documents\MyDev\MyJava\MyMedia\MyMediaExs\src\mymediaexs\ApplicWTimer.java at 4/28/06 1 package 2 import 3 import 4 import 5 import 6 import 7 8 public class ApplicWTimer extends JFrame implements ActionListener { 9 private 10 private String fname[] = {"Assets.gif", "Contacts.gif", "Evtmgmt. 11 private 12 private int 13 private int 14 private 15 private Image img[] = new 16 private MediaTracker mt = new MediaTracker(this private int 19 private int private int 22 private int 23 private int 24 private int 25 private int 26 private Timer timer = new Timer(15, this // The main method required for an application program 29 public static void main( String[] args ) { 30 JFrame frame = new ApplicWTimer // Construct the window 31 frame.setdefaultcloseoperation 32 frame.setvisible( true // Make the window visible 33 } /** Creates a new instance of ApplicWTimer */ 36 public ApplicWTimer() { 37 super 38 Container c = getcontentpane 39 setsize( new Dimension 40 c.setlayout(new BorderLayout 41 setbackground // Create a panel to display moving banner 44 imgpan = new ImagePanel 45 imgpan.setborder(new EtchedBorder 46 imgpan.setborder(new TitledBorder("Demonstration of Timer-Based Page 1

21 Printing C:\Documents and Settings\jgneal\My Documents\MyDev\MyJava\MyMedia\MyMediaExs\src\mymediaexs\ApplicWTimer.java at 4/28/06 47 c.add timer.start 50 } public void actionperformed(actionevent e) { 53 imgpan.repaint 54 } public class ImagePanel extends JPanel { 57 int 58 // Constructor 59 public ImagePanel(int w) { 61 // Get images and assign into array 62 for (int 64 img[i] = Toolkit.getDefaultToolkit().getImage 65 try { 66 mt.addimage 67 mt.waitforid 68 } catch (Exception ex) { 69 System.out.println("\n" + ex.tostring 70 } 71 } set image width and height variables 74 imgwidth = img[0].getwidth(null 75 imgheight = img[0].getheight(null setbackground 78 setpreferredsize(new Dimension(apWidth, imgheight + ypos * 79 setvisible(true 80 } // Paint the JPanel 83 public void paintcomponent(graphics g) { 84 super.paintcomponent 85 int 86 int // Create and draw image 89 while (xpos < panelwidth) { 91 g.drawimage(img[currentimgindex], xpos, ypos, null Page 2

22 Printing C:\Documents and Settings\jgneal\My Documents\MyDev\MyJava\MyMedia\MyMediaExs\src\mymediaexs\ApplicWTimer.java at 4/28/06 93 } // Establish the horizontal start position for the next repaint of banner 96 // and the image with which to start if (startxpos > betweenspace) { 102 /* if (startimageindex < 0) */ 108 if (startimgindex >= fname.length) 110 } 111 } // End paintcomponent 112 } } 115 Page 3

CSC 160 LAB 8-1 DIGITAL PICTURE FRAME. 1. Introduction

CSC 160 LAB 8-1 DIGITAL PICTURE FRAME. 1. Introduction CSC 160 LAB 8-1 DIGITAL PICTURE FRAME PROFESSOR GODFREY MUGANDA DEPARTMENT OF COMPUTER SCIENCE 1. Introduction Download and unzip the images folder from the course website. The folder contains 28 images

More information

The AWT Package, Graphics- Introduction to Images

The AWT Package, Graphics- Introduction to Images Richard G Baldwin (512) 223-4758, baldwin@austin.cc.tx.us, http://www2.austin.cc.tx.us/baldwin/ The AWT Package, Graphics- Introduction to Images Java Programming, Lecture Notes # 170, Revised 09/23/98.

More information

CS 209 Programming in Java #10 Exception Handling

CS 209 Programming in Java #10 Exception Handling CS 209 Programming in Java #10 Exception Handling Textbook Chapter 15 Spring, 2006 Instructor: J.G. Neal 1 Topics What is an Exception? Exception Handling Fundamentals Errors and Exceptions The try-catch-finally

More information

Image Java Foundation Classes (JFC) java.awt.image JFC. Image. Image. Image PNG GIF JPEG

Image Java Foundation Classes (JFC) java.awt.image JFC. Image. Image. Image PNG GIF JPEG 11 2013 6 25 11.1.............................. 11 1 11.2.............................. 11 2 11.3................................... 11 5 11.4.............................. 11 6 11.5.......................................

More information

Graphic Interface Programming II Events and Threads. Uppsala universitet

Graphic Interface Programming II Events and Threads. Uppsala universitet Graphic Interface Programming II Events and Threads IT Uppsala universitet Animation Animation adds to user experience Done right, it enhances the User Interface Done wrong, it distracts and irritates

More information

Module 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Module 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani Module 5 The Applet Class, Swings OOC 4 th Sem, B Div 2016-17 Prof. Mouna M. Naravani The layout manager helps lay out the components held by this container. When you set a layout to null, you tell the

More information

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics Topic 9: Swing Outline Swing = Java's GUI library Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 7: Expand moving shapes from Assignment 4 into game. "Programming

More information

Part I: Learn Common Graphics Components

Part I: Learn Common Graphics Components OOP GUI Components and Event Handling Page 1 Objectives 1. Practice creating and using graphical components. 2. Practice adding Event Listeners to handle the events and do something. 3. Learn how to connect

More information

Graphic User Interfaces. - GUI concepts - Swing - AWT

Graphic User Interfaces. - GUI concepts - Swing - AWT Graphic User Interfaces - GUI concepts - Swing - AWT 1 What is GUI Graphic User Interfaces are used in programs to communicate more efficiently with computer users MacOS MS Windows X Windows etc 2 Considerations

More information

Introduction to the JAVA UI classes Advanced HCI IAT351

Introduction to the JAVA UI classes Advanced HCI IAT351 Introduction to the JAVA UI classes Advanced HCI IAT351 Week 3 Lecture 1 17.09.2012 Lyn Bartram lyn@sfu.ca About JFC and Swing JFC Java TM Foundation Classes Encompass a group of features for constructing

More information

AP CS Unit 11: Graphics and Events

AP CS Unit 11: Graphics and Events AP CS Unit 11: Graphics and Events This packet shows how to create programs with a graphical interface in a way that is consistent with the approach used in the Elevens program. Copy the following two

More information

Chapter 12 Advanced GUIs and Graphics

Chapter 12 Advanced GUIs and Graphics Chapter 12 Advanced GUIs and Graphics Chapter Objectives Learn about applets Explore the class Graphics Learn about the classfont Explore the classcolor Java Programming: From Problem Analysis to Program

More information

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7 PROGRAMMING DESIGN USING JAVA (ITT 303) Graphical User Interface Unit 7 Learning Objectives At the end of this unit students should be able to: Build graphical user interfaces Create and manipulate buttons,

More information

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT CSE 143 Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia http://www.cs.washington.edu/331/

More information

Java Swing. based on slides by: Walter Milner. Java Swing Walter Milner 2005: Slide 1

Java Swing. based on slides by: Walter Milner. Java Swing Walter Milner 2005: Slide 1 Java Swing based on slides by: Walter Milner Java Swing Walter Milner 2005: Slide 1 What is Swing? A group of 14 packages to do with the UI 451 classes as at 1.4 (!) Part of JFC Java Foundation Classes

More information

H212 Introduction to Software Systems Honors

H212 Introduction to Software Systems Honors Introduction to Software Systems Honors Lecture #19: November 4, 2015 1/14 Third Exam The third, Checkpoint Exam, will be on: Wednesday, November 11, 2:30 to 3:45 pm You will have 3 questions, out of 9,

More information

Welcome to CIS 068! 1. GUIs: JAVA Swing 2. (Streams and Files we ll not cover this in this semester, just a review) CIS 068

Welcome to CIS 068! 1. GUIs: JAVA Swing 2. (Streams and Files we ll not cover this in this semester, just a review) CIS 068 Welcome to! 1. GUIs: JAVA Swing 2. (Streams and Files we ll not cover this in this semester, just a review) Overview JAVA and GUIs: SWING Container, Components, Layouts Using SWING Streams and Files Text

More information

CSC 1214: Object-Oriented Programming

CSC 1214: Object-Oriented Programming CSC 1214: Object-Oriented Programming J. Kizito Makerere University e-mail: jkizito@cis.mak.ac.ug www: http://serval.ug/~jona materials: http://serval.ug/~jona/materials/csc1214 e-learning environment:

More information

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 5: Will be an open-ended Swing project. "Programming Contest"

More information

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun! Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Why are we studying Swing? 1. Useful & fun! 2. Good application of OOP techniques

More information

Graphical User Interfaces 2

Graphical User Interfaces 2 Graphical User Interfaces 2 CSCI 136: Fundamentals CSCI 136: Fundamentals of Computer of Science Computer II Science Keith II Vertanen Keith Vertanen Copyright 2011 Extending JFrame Dialog boxes Overview

More information

Datenbank-Praktikum. Universität zu Lübeck Sommersemester 2006 Lecture: Swing. Ho Ngoc Duc 1

Datenbank-Praktikum. Universität zu Lübeck Sommersemester 2006 Lecture: Swing. Ho Ngoc Duc 1 Datenbank-Praktikum Universität zu Lübeck Sommersemester 2006 Lecture: Swing Ho Ngoc Duc 1 Learning objectives GUI applications Font, Color, Image Running Applets as applications Swing Components q q Text

More information

Lecture 5: Java Graphics

Lecture 5: Java Graphics Lecture 5: Java Graphics CS 62 Spring 2019 William Devanny & Alexandra Papoutsaki 1 New Unit Overview Graphical User Interfaces (GUI) Components, e.g., JButton, JTextField, JSlider, JChooser, Containers,

More information

CoSc Lab # 5 (The Controller)

CoSc Lab # 5 (The Controller) CoSc 10403 Lab # 5 (The Controller) Due Date: Part I, Experiment classtime, Thursday, Oct 25 th, 2018. Part II, Program - by midnight, Thursday, Oct 25 th, 2018. Part I MUST be typed and submitted to your

More information

Java Programming Lecture 6

Java Programming Lecture 6 Java Programming Lecture 6 Alice E. Fischer Feb 15, 2013 Java Programming - L6... 1/32 Dialog Boxes Class Derivation The First Swing Programs: Snow and Moving The Second Swing Program: Smile Swing Components

More information

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008 Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008 Announcements A3 is up, due Friday, Oct 10 Prelim 1 scheduled for Oct 16 if you have a conflict, let us know now 2 Interactive

More information

Graphics programming. COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson)

Graphics programming. COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson) Graphics programming COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson) Overview Aims To provide an overview of Swing and the AWT To show how to build

More information

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class CHAPTER GRAPHICAL USER INTERFACES 10 Slides by Donald W. Smith TechNeTrain.com Final Draft 10/30/11 10.1 Frame Windows Java provides classes to create graphical applications that can run on any major graphical

More information

CS 251 Intermediate Programming GUIs: Components and Layout

CS 251 Intermediate Programming GUIs: Components and Layout CS 251 Intermediate Programming GUIs: Components and Layout Brooke Chenoweth University of New Mexico Fall 2017 import javax. swing.*; Hello GUI public class HelloGUI extends JFrame { public HelloGUI ()

More information

Graphic Interface Programming II Using Swing and OOP more advanced issues. Uppsala universitet

Graphic Interface Programming II Using Swing and OOP more advanced issues. Uppsala universitet Graphic Interface Programming II Using Swing and OOP more advanced issues IT Uppsala universitet Good interface programming Swing is an EXTENDIBLE toolkit Build your OWN components Many times you need

More information

Graphical User Interfaces. Comp 152

Graphical User Interfaces. Comp 152 Graphical User Interfaces Comp 152 Procedural programming Execute line of code at a time Allowing for selection and repetition Call one function and then another. Can trace program execution on paper from

More information

CompSci 125 Lecture 17. GUI: Graphics, Check Boxes, Radio Buttons

CompSci 125 Lecture 17. GUI: Graphics, Check Boxes, Radio Buttons CompSci 125 Lecture 17 GUI: Graphics, Check Boxes, Radio Buttons Announcements GUI Review Review: Inheritance Subclass is a Parent class Includes parent s features May Extend May Modify extends! Parent

More information

Here is a list of a few of the components located in the AWT and Swing packages:

Here is a list of a few of the components located in the AWT and Swing packages: Inheritance Inheritance is the capability of a class to use the properties and methods of another class while adding its own functionality. Programming In A Graphical Environment Java is specifically designed

More information

Part 3: Graphical User Interface (GUI) & Java Applets

Part 3: Graphical User Interface (GUI) & Java Applets 1,QWURGXFWLRQWR-DYD3URJUDPPLQJ (( Part 3: Graphical User Interface (GUI) & Java Applets EE905-GUI 7RSLFV Creating a Window Panels Event Handling Swing GUI Components ƒ Layout Management ƒ Text Field ƒ

More information

Lecture 3: Java Graphics & Events

Lecture 3: Java Graphics & Events Lecture 3: Java Graphics & Events CS 62 Fall 2017 Kim Bruce & Alexandra Papoutsaki Text Input Scanner class Constructor: myscanner = new Scanner(System.in); can use file instead of System.in new Scanner(new

More information

Graphical User Interface (GUI)

Graphical User Interface (GUI) Graphical User Interface (GUI) An example of Inheritance and Sub-Typing 1 Java GUI Portability Problem Java loves the idea that your code produces the same results on any machine The underlying hardware

More information

Chapter 17 Creating User Interfaces

Chapter 17 Creating User Interfaces Chapter 17 Creating User Interfaces 1 Motivations A graphical user interface (GUI) makes a system user-friendly and easy to use. Creating a GUI requires creativity and knowledge of how GUI components work.

More information

G51PRG: Introduction to Programming Second semester Applets and graphics

G51PRG: Introduction to Programming Second semester Applets and graphics G51PRG: Introduction to Programming Second semester Applets and graphics Natasha Alechina School of Computer Science & IT nza@cs.nott.ac.uk Previous two lectures AWT and Swing Creating components and putting

More information

Page 1 of 7. public class EmployeeAryAppletEx extends JApplet

Page 1 of 7. public class EmployeeAryAppletEx extends JApplet CS 209 Spring, 2006 Lab 9: Applets Instructor: J.G. Neal Objectives: To gain experience with: 1. Programming Java applets and the HTML page within which an applet is embedded. 2. The passing of parameters

More information

CS 209 Spring, 2006 Lab 8: GUI Development Instructor: J.G. Neal

CS 209 Spring, 2006 Lab 8: GUI Development Instructor: J.G. Neal CS 209 Spring, 2006 Lab 8: GUI Development Instructor: J.G. Neal Objectives: To gain experience with the programming of: 1. Graphical user interfaces (GUIs), 2. GUI components, and 3. Event handling (required

More information

Chapter 8. Java continued. CS Hugh Anderson s notes. Page number: 264 ALERT. MCQ test next week. This time. This place.

Chapter 8. Java continued. CS Hugh Anderson s notes. Page number: 264 ALERT. MCQ test next week. This time. This place. Chapter 8 Java continued CS3283 - Hugh Anderson s notes. Page number: 263 ALERT MCQ test next week This time This place Closed book CS3283 - Hugh Anderson s notes. Page number: 264 ALERT Assignment #2

More information

Java continued. Chapter 8 ALERT ALERT. Last week. MCQ test next week. This time. This place. Closed book. Assignment #2 is for groups of 3

Java continued. Chapter 8 ALERT ALERT. Last week. MCQ test next week. This time. This place. Closed book. Assignment #2 is for groups of 3 Chapter 8 Java continued MCQ test next week This time This place Closed book ALERT CS3283 - Hugh Anderson s notes. Page number: 263 CS3283 - Hugh Anderson s notes. Page number: 264 ALERT Last week Assignment

More information

User interfaces and Swing

User interfaces and Swing User interfaces and Swing Overview, applets, drawing, action listening, layout managers. APIs: java.awt.*, javax.swing.*, classes names start with a J. Java Lectures 1 2 Applets public class Simple extends

More information

CS 315 Software Design Homework 1 First Sip of Java Due: Sept. 10, 11:30 PM

CS 315 Software Design Homework 1 First Sip of Java Due: Sept. 10, 11:30 PM CS 315 Software Design Homework 1 First Sip of Java Due: Sept. 10, 11:30 PM Objectives The objectives of this assignment are: to get your first experience with Java to become familiar with Eclipse Java

More information

MULTIMEDIA PROGRAMMING IN JAVA. Prof.Asoc. Alda Kika Department of Informatics Faculty of Natural Sciences University of Tirana

MULTIMEDIA PROGRAMMING IN JAVA. Prof.Asoc. Alda Kika Department of Informatics Faculty of Natural Sciences University of Tirana MULTIMEDIA PROGRAMMING IN JAVA Prof.Asoc. Alda Kika Department of Informatics Faculty of Natural Sciences University of Tirana Objectives Applets in Java Getting, displaying and scaling the image How to

More information

Window Interfaces Using Swing Objects

Window Interfaces Using Swing Objects Chapter 12 Window Interfaces Using Swing Objects Event-Driven Programming and GUIs Swing Basics and a Simple Demo Program Layout Managers Buttons and Action Listeners Container Classes Text I/O for GUIs

More information

Introduction to Graphical Interface Programming in Java. Introduction to AWT and Swing

Introduction to Graphical Interface Programming in Java. Introduction to AWT and Swing Introduction to Graphical Interface Programming in Java Introduction to AWT and Swing GUI versus Graphics Programming Graphical User Interface (GUI) Graphics Programming Purpose is to display info and

More information

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

Graphics. Lecture 18 COP 3252 Summer June 6, 2017 Graphics Lecture 18 COP 3252 Summer 2017 June 6, 2017 Graphics classes In the original version of Java, graphics components were in the AWT library (Abstract Windows Toolkit) Was okay for developing simple

More information

To gain experience using GUI components and listeners.

To gain experience using GUI components and listeners. Lab 5 Handout 7 CSCI 134: Fall, 2017 TextPlay Objective To gain experience using GUI components and listeners. Note 1: You may work with a partner on this lab. If you do, turn in only one lab with both

More information

Java - Applications. The following code sets up an application with a drop down menu, as yet the menu does not do anything.

Java - Applications. The following code sets up an application with a drop down menu, as yet the menu does not do anything. Java - Applications C&G Criteria: 5.3.2, 5.5.2, 5.5.3 Java applets require a web browser to run independently of the Java IDE. The Dos based console applications will run outside the IDE but have no access

More information

Graphical User Interface (GUI) components in Java Applets. With Abstract Window Toolkit (AWT) we can build an applet that has the basic GUI

Graphical User Interface (GUI) components in Java Applets. With Abstract Window Toolkit (AWT) we can build an applet that has the basic GUI CBOP3203 Graphical User Interface (GUI) components in Java Applets. With Abstract Window Toolkit (AWT) we can build an applet that has the basic GUI components like button, text input, scroll bar and others.

More information

Building Graphical User Interfaces. Overview

Building Graphical User Interfaces. Overview Building Graphical User Interfaces 4.1 Overview Constructing GUIs Interface components GUI layout Event handling 2 1 GUI Principles Components: GUI building blocks. Buttons, menus, sliders, etc. Layout:

More information

Dr. Shahanawaj Ahamad. Dr. S.Ahamad, SWE-423, Unit-05

Dr. Shahanawaj Ahamad. Dr. S.Ahamad, SWE-423, Unit-05 Dr. Shahanawaj Ahamad Dr. S.Ahamad, SWE-423, Unit-05 1 Outlines: JMF Core Model Architecture Models: time, event, data JMF Core Functionality Presentation Processing Capture Storage and Transmission JMF

More information

Graphical User Interfaces 2

Graphical User Interfaces 2 Graphical User Interfaces 2 CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2011 Extending JFrame Dialog boxes Ge?ng user input Overview Displaying message or error Listening for

More information

Swing Programming Example Number 2

Swing Programming Example Number 2 1 Swing Programming Example Number 2 Problem Statement (Part 1 and 2 (H/w- assignment) 2 Demonstrate the use of swing Label, TextField, RadioButton, CheckBox, Listbox,Combo Box, Toggle button,image Icon

More information

Command-Line Applications. GUI Libraries GUI-related classes are defined primarily in the java.awt and the javax.swing packages.

Command-Line Applications. GUI Libraries GUI-related classes are defined primarily in the java.awt and the javax.swing packages. 1 CS257 Computer Science I Kevin Sahr, PhD Lecture 14: Graphical User Interfaces Command-Line Applications 2 The programs we've explored thus far have been text-based applications A Java application is

More information

Java - Applets. public class Buttons extends Applet implements ActionListener

Java - Applets. public class Buttons extends Applet implements ActionListener Java - Applets Java code here will not use swing but will support the 1.1 event model. Legacy code from the 1.0 event model will not be used. This code sets up a button to be pushed: import java.applet.*;

More information

Window Interfaces Using Swing Objects

Window Interfaces Using Swing Objects Chapter 12 Window Interfaces Using Swing Objects Event-Driven Programming and GUIs Swing Basics and a Simple Demo Program Layout Managers Buttons and Action Listeners Container Classes Text I/O for GUIs

More information

Starting Out with Java: From Control Structures Through Objects Sixth Edition

Starting Out with Java: From Control Structures Through Objects Sixth Edition Starting Out with Java: From Control Structures Through Objects Sixth Edition Chapter 12 A First Look at GUI Applications Chapter Topics 12.1 Introduction 12.2 Creating Windows 12.3 Equipping GUI Classes

More information

Java Coordinate System

Java Coordinate System Java Graphics Drawing shapes in Java such as lines, rectangles, 3-D rectangles, a bar chart, or a clock utilize the Graphics class Drawing Strings Drawing Lines Drawing Rectangles Drawing Ovals Drawing

More information

Tool Kits, Swing. Overview. SMD158 Interactive Systems Spring Tool Kits in the Abstract. An overview of Swing/AWT

Tool Kits, Swing. Overview. SMD158 Interactive Systems Spring Tool Kits in the Abstract. An overview of Swing/AWT INSTITUTIONEN FÖR Tool Kits, Swing SMD158 Interactive Systems Spring 2005 Jan-28-05 2002-2005 by David A. Carr 1 L Overview Tool kits in the abstract An overview of Swing/AWT Jan-28-05 2002-2005 by David

More information

Packages: Putting Classes Together

Packages: Putting Classes Together Packages: Putting Classes Together 1 Introduction 2 The main feature of OOP is its ability to support the reuse of code: Extending the classes (via inheritance) Extending interfaces The features in basic

More information

JAVA NOTES GRAPHICAL USER INTERFACES

JAVA NOTES GRAPHICAL USER INTERFACES 1 JAVA NOTES GRAPHICAL USER INTERFACES Terry Marris 24 June 2001 5 TEXT AREAS 5.1 LEARNING OUTCOMES By the end of this lesson the student should be able to understand how to get multi-line input from the

More information

CSE 331. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

CSE 331. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT CSE 331 Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia http://www.cs.washington.edu/331/

More information

Programming graphics

Programming graphics Programming graphics Need a window javax.swing.jframe Several essential steps to use (necessary plumbing ): Set the size width and height in pixels Set a title (optional), and a close operation Make it

More information

SIMPLE APPLET PROGRAM

SIMPLE APPLET PROGRAM APPLETS Applets are small applications that are accessed on Internet Server, transported over Internet, automatically installed and run as a part of web- browser Applet Basics : - All applets are subclasses

More information

We are on the GUI fast track path

We are on the GUI fast track path We are on the GUI fast track path Chapter 13: Exception Handling Skip for now Chapter 14: Abstract Classes and Interfaces Sections 1 9: ActionListener interface Chapter 15: Graphics Skip for now Chapter

More information

Advanced Java Unit 6: Review of Graphics and Events

Advanced Java Unit 6: Review of Graphics and Events Advanced Java Unit 6: Review of Graphics and Events This is a review of the basics of writing a java program that has a graphical interface. To keep things simple, all of the graphics programs will follow

More information

Java - Applets. C&G criteria: 1.2.2, 1.2.3, 1.2.4, 1.3.4, 1.2.4, 1.3.4, 1.3.5, 2.2.5, 2.4.5, 5.1.2, 5.2.1,

Java - Applets. C&G criteria: 1.2.2, 1.2.3, 1.2.4, 1.3.4, 1.2.4, 1.3.4, 1.3.5, 2.2.5, 2.4.5, 5.1.2, 5.2.1, Java - Applets C&G criteria: 1.2.2, 1.2.3, 1.2.4, 1.3.4, 1.2.4, 1.3.4, 1.3.5, 2.2.5, 2.4.5, 5.1.2, 5.2.1, 5.3.2. Java is not confined to a DOS environment. It can run with buttons and boxes in a Windows

More information

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Events and Listeners CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/ Some slides

More information

Handout 14 Graphical User Interface (GUI) with Swing, Event Handling

Handout 14 Graphical User Interface (GUI) with Swing, Event Handling Handout 12 CS603 Object-Oriented Programming Fall 15 Page 1 of 12 Handout 14 Graphical User Interface (GUI) with Swing, Event Handling The Swing library (javax.swing.*) Contains classes that implement

More information

Graphical User Interfaces 2

Graphical User Interfaces 2 Graphical User Interfaces 2 CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2014 2011 Extending JFrame Dialog boxes Overview Ge

More information

Chapter 12 GUI Basics

Chapter 12 GUI Basics Chapter 12 GUI Basics 1 Creating GUI Objects // Create a button with text OK JButton jbtok = new JButton("OK"); // Create a label with text "Enter your name: " JLabel jlblname = new JLabel("Enter your

More information

Chapter 13 Lab Advanced GUI Applications Lab Objectives. Introduction. Task #1 Creating a Menu with Submenus

Chapter 13 Lab Advanced GUI Applications Lab Objectives. Introduction. Task #1 Creating a Menu with Submenus Chapter 13 Lab Advanced GUI Applications Lab Objectives Be able to add a menu to the menu bar Be able to use nested menus Be able to add scroll bars, giving the user the option of when they will be seen.

More information

Assignment 2. Application Development

Assignment 2. Application Development Application Development Assignment 2 Content Application Development Day 2 Lecture The lecture covers the key language elements of the Java programming language. You are introduced to numerical data and

More information

AP CS Unit 12: Drawing and Mouse Events

AP CS Unit 12: Drawing and Mouse Events AP CS Unit 12: Drawing and Mouse Events A JPanel object can be used as a container for other objects. It can also be used as an object that we can draw on. The first example demonstrates how to do that.

More information

PIC 20A GUI with swing

PIC 20A GUI with swing PIC 20A GUI with swing Ernest Ryu UCLA Mathematics Last edited: November 22, 2017 Hello swing Let s create a JFrame. import javax. swing.*; public class Test { public static void main ( String [] args

More information

Dr. Hikmat A. M. AbdelJaber

Dr. Hikmat A. M. AbdelJaber Dr. Hikmat A. M. AbdelJaber JWindow: is a window without a title bar or move controls. The program can move and resize it, but the user cannot. It has no border at all. It optionally has a parent JFrame.

More information

Java Applets / Flash

Java Applets / Flash Java Applets / Flash Java Applet vs. Flash political problems with Microsoft highly portable more difficult development not a problem less so excellent visual development tool Applet / Flash good for:

More information

Class 16: The Swing Event Model

Class 16: The Swing Event Model Introduction to Computation and Problem Solving Class 16: The Swing Event Model Prof. Steven R. Lerman and Dr. V. Judson Harward 1 The Java Event Model Up until now, we have focused on GUI's to present

More information

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp DM550 / DM857 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk http://imada.sdu.dk/~petersk/dm550/ http://imada.sdu.dk/~petersk/dm857/ GRAPHICAL USER INTERFACES 2 HelloWorld Reloaded

More information

Chapter 14: Applets and More

Chapter 14: Applets and More Chapter 14: Applets and More Starting Out with Java: From Control Structures through Objects Fifth Edition by Tony Gaddis Chapter Topics Chapter 14 discusses the following main topics: Introduction to

More information

8/23/2014. Chapter Topics. Introduction to Applets. Introduction to Applets. Introduction to Applets. Applet Limitations. Chapter 14: Applets and More

8/23/2014. Chapter Topics. Introduction to Applets. Introduction to Applets. Introduction to Applets. Applet Limitations. Chapter 14: Applets and More Chapter 14: Applets and More Starting Out with Java: From Control Structures through Objects Fifth Edition by Tony Gaddis Chapter Topics Chapter 14 discusses the following main topics: Introduction to

More information

Computer Science 210: Data Structures. Intro to Java Graphics

Computer Science 210: Data Structures. Intro to Java Graphics Computer Science 210: Data Structures Intro to Java Graphics Summary Today GUIs in Java using Swing in-class: a Scribbler program READING: browse Java online Docs, Swing tutorials GUIs in Java Java comes

More information

Final Examination Semester 2 / Year 2010

Final Examination Semester 2 / Year 2010 Southern College Kolej Selatan 南方学院 Final Examination Semester 2 / Year 2010 COURSE : JAVA PROGRAMMING COURSE CODE : PROG1114 TIME : 2 1/2 HOURS DEPARTMENT : COMPUTER SCIENCE LECTURER : LIM PEI GEOK Student

More information

An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a

An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a CBOP3203 An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a page. When you use a Java technology-enabled

More information

+! Today. Lecture 3: ArrayList & Standard Java Graphics 1/26/14! n Reading. n Objectives. n Reminders. n Standard Java Graphics (on course webpage)

+! Today. Lecture 3: ArrayList & Standard Java Graphics 1/26/14! n Reading. n Objectives. n Reminders. n Standard Java Graphics (on course webpage) +! Lecture 3: ArrayList & Standard Java Graphics +! Today n Reading n Standard Java Graphics (on course webpage) n Objectives n Review for this week s lab and homework assignment n Miscellanea (Random,

More information

Chapter 14: Applets and More

Chapter 14: Applets and More Chapter 14: Applets and More Starting Out with Java: From Control Structures through Objects Fourth Edition by Tony Gaddis Addison Wesley is an imprint of 2010 Pearson Addison-Wesley. All rights reserved.

More information

FirstSwingFrame.java Page 1 of 1

FirstSwingFrame.java Page 1 of 1 FirstSwingFrame.java Page 1 of 1 2: * A first example of using Swing. A JFrame is created with 3: * a label and buttons (which don t yet respond to events). 4: * 5: * @author Andrew Vardy 6: */ 7: import

More information

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written. HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC212, FALL TERM, 2006 FINAL EXAMINATION 7pm to 10pm, 19 DECEMBER 2006, Jeffrey Hall 1 st Floor Instructor: Alan

More information

Chapter 13 Lab Advanced GUI Applications

Chapter 13 Lab Advanced GUI Applications Gaddis_516907_Java 4/10/07 2:10 PM Page 113 Chapter 13 Lab Advanced GUI Applications Objectives Be able to add a menu to the menu bar Be able to use nested menus Be able to add scroll bars, giving the

More information

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written. QUEEN'S UNIVERSITY SCHOOL OF COMPUTING HAND IN Answers Are Recorded on Question Paper CISC124, WINTER TERM, 2011 FINAL EXAMINATION 7pm to 10pm, 26 APRIL 2011, Ross Gym Instructor: Alan McLeod If the instructor

More information

Adding Buttons to StyleOptions.java

Adding Buttons to StyleOptions.java Adding Buttons to StyleOptions.java The files StyleOptions.java and StyleOptionsPanel.java are from Listings 5.14 and 5.15 of the text (with a couple of slight changes an instance variable fontsize is

More information

What Is an Event? Some event handler. ActionEvent. actionperformed(actionevent e) { }

What Is an Event? Some event handler. ActionEvent. actionperformed(actionevent e) { } CBOP3203 What Is an Event? Events Objects that describe what happened Event Sources The generator of an event Event Handlers A method that receives an event object, deciphers it, and processes the user

More information

Programming: You will have 6 files all need to be located in the dir. named PA4:

Programming: You will have 6 files all need to be located in the dir. named PA4: PROGRAMMING ASSIGNMENT 4: Read Savitch: Chapter 7 and class notes Programming: You will have 6 files all need to be located in the dir. named PA4: PA4.java ShapeP4.java PointP4.java CircleP4.java RectangleP4.java

More information

CSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing

CSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing CSEN401 Computer Programming Lab Topics: Graphical User Interface Window Interfaces using Swing Prof. Dr. Slim Abdennadher 22.3.2015 c S. Abdennadher 1 Swing c S. Abdennadher 2 AWT versus Swing Two basic

More information

Chapter 4. Swing 18 marks

Chapter 4. Swing 18 marks Chapter 4 Swing 18 marks 1) Distinguish Between the Swing and AWT Ans: Swing It uses javax.swing package. It uses JApplet class Swing is light weight component It is Platform independent code Swing Support

More information

Overview. Building Graphical User Interfaces. GUI Principles. AWT and Swing. Constructing GUIs Interface components GUI layout Event handling

Overview. Building Graphical User Interfaces. GUI Principles. AWT and Swing. Constructing GUIs Interface components GUI layout Event handling Overview Building Graphical User Interfaces Constructing GUIs Interface components GUI layout Event handling 4.1 GUI Principles AWT and Swing Components: GUI building blocks. Buttons, menus, sliders, etc.

More information

Week Chapter Assignment SD Technology Standards. 1,2, Review Knowledge Check JP3.1. Program 5.1. Program 5.1. Program 5.2. Program 5.2. Program 5.

Week Chapter Assignment SD Technology Standards. 1,2, Review Knowledge Check JP3.1. Program 5.1. Program 5.1. Program 5.2. Program 5.2. Program 5. Week Chapter Assignment SD Technology Standards 1,2, Review JP3.1 Review exercises Debugging Exercises 3,4 Arrays, loops and layout managers. (5) Create and implement an external class Write code to create

More information