AP CS Unit 12: Drawing and Mouse Events

Size: px
Start display at page:

Download "AP CS Unit 12: Drawing and Mouse Events"

Transcription

1 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. Copy these files and run them. The first file simply contains the main method which instantiates the frame and displays it. The MyFrame1 class looks very similar to the classes that we wrote in Unit 11. However, one difference is that we are adding a DemoPanel object. The DemoPanel class extends JPanel and is on the next page. public class RunDemo1 { public static void main(string[] args) { MyFrame1 mf = new MyFrame1(); mf.display(); import javax.swing.jframe; import javax.swing.jpanel; import java.awt.color; import java.awt.dimension; import java.awt.eventqueue; public class MyFrame1 extends JFrame { public MyFrame1(){ setdefaultcloseoperation(exit_on_close); settitle( "HEY" ); JPanel jp = new JPanel(); jp.setbackground( Color.LIGHT_GRAY ); jp.setpreferredsize( new Dimension( 300, 250 ) ); jp.setlayout( null ); DemoPanel d = new DemoPanel( Color.WHITE); d.setbounds( 5, 50, 290, 150 ); jp.add( d ); getcontentpane().add( jp ); pack(); public void display() { EventQueue.invokeLater(new Runnable() { public void run() { setvisible(true); ); 1

2 import javax.swing.*; import java.awt.*; public class DemoPanel extends JPanel { public DemoPanel( Color c ) { setbackground( c ); setborder( BorderFactory.createLineBorder(Color.BLACK ) public void paintcomponent( Graphics g ) { super.paintcomponent( g ); int w = getwidth(); int h = getheight(); g.setcolor( Color.GREEN ); g.drawrect( 50, 10, w/2, 4*h/5 ); g.setcolor( Color.BLUE ); g.filloval( 0, h/2, w, h/4 ); Some of the Graphics methods are described below. Note: the panel has its own coordinate plane. Its origin is in its upper left hand corner. Who calls the paintcomponent method?!? In the above example, we override the paintcomponent method but there are no statements in our program that actually call this method. So how is it being called? The JVM executes our program and every time certain events occur (such as when the program is loaded or the frame is resized), the JVM calls the paintcomponent for each component. Some Methods of the Graphics Class void drawline( int x1, int y1, int x2, int y2 ) Draws a line from (x1, y1) to (x2, y2) void drawoval( int x, int y, int width, int height ) Every oval can be enclosed in a rectangle. x and y specify the coordinates of the upper left hand corner. void drawpolygon(int[] x, int[] y, int n) Draws a polygon where the vertices are (x[0],y[0]), (x[1],y[1]), to (x[n-1],y[n-1]). The arrays should have a length of at least three and n should be less than or equal to the length of the arrays. void drawrect( int x, int y, int width, int height ) x and y specify the coordinates of the upper left hand corner. void filloval( int x, int y, int width, int height ) Same as drawoval except that the oval is filled. void fillpolygon(int[] x, int[] y, int n) Same as drawpolygon except that the polygon is filled. void fillrect( int x, int y, int width, int height ) Same as drawrect except that the rectangle is filled. void setcolor( Color c ) Sets the color to use for all future drawing 2

3 Ex. 1. Create a program like the one shown. The main panel has a preferred size of 350 by 200 pixels. Inside the main panel is a panel with the following: - the background color is orange. - there is a light gray rectangle drawn so that there is a ten pixel space between the rectangle and the edges of the panel. - there is a white circle with a 25 pixel radius in the upper left hand corner. - there is a gray circle with a 25 pixel radius in the lower right hand corner. Ex. 2. Create a program like the one to the right. The main panel has a preferred size 450 pixels wide by 300 pixels high. Write a class that extends JPanel and it draws 4 evenly spaced vertical lines. The height of these lines should match the height of the panel. Instantiate two objects of this class. The one on the left has an orange background and the one on the right has a yellow background. Both have red borders. You should size and position them so that it looks similar to the figure but it doesn t have to be exact. Handling Interactions Between a JPanel Subclass and Other Components. In this example there is a button, label, and panel. When the button is clicked, (1) a random number between 1 and 50 is generated, (2) the number is displayed in the label, and (3) that number of lines is drawn on the panel. I did not provide the code for the runner class but the code for the other two classes is on the next page. 3

4 import javax.swing.*; import java.awt.*; public class Demo2Panel extends JPanel { private int numlines = 0; New. There s an instance variable for the number of lines to draw. public Demo2Panel( Color c ) { setbackground( c ); setborder( BorderFactory.createLineBorder(Color.BLACK ) public void paintcomponent( Graphics g ) { super.paintcomponent( g ); g.setcolor( Color.BLACK ); int h = getheight(); for ( int n = 1; n <= numlines; n++ ) g.drawline( 0, 0, n*25, h ); public void update( int n ){ if ( n < 0 ) numlines = 0; else numlines = n; repaint(); This method gets called from the frame class whenever the button is clicked. New and important. The repaint method sends a message to the JVM that it needs to call the paintcomponent method. import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Demo2Frame extends JFrame { private JButton button = new JButton("Update Panel"); private JLabel lbl = new JLabel("Number of Lines: 0"); private Demo2Panel p1 = new Demo2Panel( Color.ORANGE ); public Demo2Frame(){ setdefaultcloseoperation(exit_on_close); settitle( "Graphics" ); JPanel jp = new JPanel(); jp.setbackground( Color.WHITE ); jp.setpreferredsize( new Dimension( 400, 250 ) ); jp.setlayout( null ); 4

5 button.setbounds( 10, 10, 150, 30 ); button.addactionlistener( new ButtonEars() ); lbl.setbounds( 10, 50, 150, 30 ); p1.setbounds( 170, 10, 200, 200 ); jp.add( button ); jp.add( lbl ); jp.add( p1 ); getcontentpane().add( jp ); pack(); public void display() { EventQueue.invokeLater(new Runnable() { public void run() { setvisible(true); ); private class ButtonEars implements ActionListener{ public void actionperformed(actionevent e) { int num = (int)( 50*Math.random() ) + 1; lbl.settext( "Number of Lines: " + num ); p1.update( num ); Everything in the Demo2Frame class should look familiar. The only real change is adding an object that is a subclass of JPanel and calling one of its methods whenever the button is clicked. Ex. 3. Create a program like the one to the right. The panel has a solid oval that just touches the four sides of the panel. The initial color of the circle is black. Add a method to this class that allows the color of the circle to be updated. The main panel contains a button and two panels. Whenever the button is clicked, generate a random color and pass this color to the two sub-panels. Every time the button is clicked the circles should change color. The exact sizes and positions do not matter for this exercise. 5

6 Ex. 4. Create a program like the one shown. When the button is clicked, those number of vertical and horizontal lines, evenly spaced, should be displayed in the two panels. Assume the textboxes are either empty or contain an integer. If the textbox is empty, assume the value is 0. The update method for the panel will have two int parameters for the number of lines. Remember that the coordinates are integer values. There are two consequences to this. (1) If the number of lines is greater than the width/height of the panel, the spacing between lines will be zero - which is bad. If your calculated spacing is zero, make it one instead. (2) Depending on the number of lines and the size of the panel, there may be some extra space on the right or bottom. This is unavoidable. Ex. 5. Create a program like the one shown. There are two buttons and three panels. In each panel there is rectangle drawn that fills the panel except for a 10 pixel edge. When the Start button is clicked, start a timer which causes the background color of each panel to swap with the color of the rectangle. Clicking the Stop button stops the timer. Here s an outline of the sub-panel public class Ex5Panel extends JPanel { private Color backcolor, rectcolor; public Ex5Panel( Color bg, Color rect ) { initialize the instance variables, set the background color, and draw a public void paintcomponent( Graphics g ) { super.paintcomponent( g ); draw a rectangle that s the right color in the right location with the right size public void swapcolors(){ switch the colors, resets the background color, and calls repaint 6

7 Ex. 6. Create a program like the one shown. There are three panels and one timer. When the program starts there are 10 circles in every panel that are moving upward. When a circle hits the top of the panel it reappears at the bottom of the panel. You will need to use the Point class. Here s some sample code: Point p = new Point( 4, 7 ); System.out.println( p.x ); // 4 p.y = 1; System.out.println( p.y ); // 1 Here is an outline of the panel class. public class Ex6Panel extends JPanel { private ArrayList<Point> pts = new ArrayList<Point>(); public Ex6Panel( Color bg, int w, int h ) { w and h should be the width and height of the panel do not use getwidth and getheight in the constructor Add 10 Point objects to the array list. Their initial x and y coordinates should be random values based on the width and height of the panel. set the background color and put a black border around public void paintcomponent( Graphics g ) { Draw circles with a diameter of 10 pixels based on the points in the array list public void move(){ Loop through the array list and change the y coordinates by 10 pixels so that the circles move up. If the circle moves off the top of the panel reset y to the bottom of the panel. You can use the getheight method here. Be sure to call repaint. 7

8 The MouseListener interface is used to detect certain events associated with the mouse. It has five methods: void mousepressed( MouseEvent e ) Invoked when the mouse button has been pressed (this event occurs before the click event). void mousereleased( MouseEvent e ) Invoked when the mouse button has been released. void mouseclicked( MouseEvent e ) Invoked when a mouse button has been clicked (pressed and released) on a component. You can use this with a JButton but the ActionListener is simpler. Use a MouseListener when you want to know where a mouse was when it was clicked. void mouseentered( MouseEvent e ) Invoked when a mouse enters a component. You could use this is change the color of a component (panel, label, etc.) when the mouse goes over it. void mouseexited( MouseEvent e ) Invoked when a mouse exits a component. You could use this is change the color of a component (panel, label, etc.) when the mouse leaves it. Note. For a click event to occur, the pressed and released event must both occur on the same component with a short amount of time. Notice that the parameter for all of the above methods is a MouseEvent object. Here a few methods of the MouseEvent class. int getx() Returns the horizontal x position of the event relative to the source component. int gety() Returns the vertical y position of the event relative to the source component. To detect if it was a right or left click, where e is the MouseEvent if ( SwingUtilities.isLeftMouseButton( e ) ) if ( SwingUtilities. isrightmousebutton( e ) ) SwingUtilities is in the javax.swing package. Here s a program that demonstrates one way to use a MouseListener. In this program I placed the MouseListener inner class in the class that extends JPanel. My reasoning was that I only wanted to respond to mouse events within those panels. Four things will happen. 1) When you press the mouse a circle will appear where the mouse was pressed down. If you release the mouse the circle disappears. 2) When the mouse enters a panel the background color gets brighter. This will not effect the red panel but it does effect the orange panel. When the mouse leaves the panel the background color gets darker. 3) No code was written for the mouseclicked. The code for the runner class was not provided. The code for the other two classes is on the next page. 8

9 import javax.swing.*; import java.awt.*; import java.awt.event.*; public class DemoMousePanel extends JPanel { private int x = -50; // x and y are coordinates of the circle that is drawn private int y = -50; // arbitrary values outside the viewable area of the panel public DemoMousePanel( Color bg ) { setbackground( bg ); setborder( BorderFactory.createLineBorder(Color.BLACK ) ); addmouselistener( new Mickey() public void paintcomponent( Graphics g ) { super.paintcomponent( g ); g.setcolor( Color.BLACK ); g.drawoval( x-20, y- 20, 40, 40 ); private class Mickey implements MouseListener{ public void mousepressed( MouseEvent e ){ x = e.getx(); y = e.gety(); repaint(); public void mousereleased( MouseEvent e ) { x = -50; y = -50; repaint(); public void mouseentered( MouseEvent e ){ Color c = getbackground(); setbackground( c.brighter() ); public void mouseexited( MouseEvent e ){ Color c = getbackground(); setbackground( c.darker() ); public void mouseclicked( MouseEvent e ){ Code for the class that extends JFrame is on the next page. 9

10 import javax.swing.*; import java.awt.*; import java.awt.event.*; public class DemoMouseFrame extends JFrame { private DemoMousePanel p1 = new DemoMousePanel( Color.RED ); private DemoMousePanel p2 = new DemoMousePanel( Color.ORANGE ); public DemoMouseFrame(){ setdefaultcloseoperation(exit_on_close); settitle( "Graphics" ); JPanel jp = new JPanel(); jp.setbackground( Color.WHITE ); jp.setpreferredsize( new Dimension( 300, 250 ) ); jp.setlayout( null ); p1.setbounds( 20, 20, 100, 200 ); p2.setbounds( 160, 20, 100, 200 ); jp.add( p1 ); jp.add( p2 ); getcontentpane().add( jp ); pack(); public void display() { EventQueue.invokeLater(new Runnable() { public void run() { setvisible(true); ); Ex. 7. Create two panels. Whenever you left-click on the a panel, a 20 by 20 pixel square appears centered on the point you clicked on. If you right click all the squares should disappear. Here are some hints. You may use the mousepressed or the mouseclicked methods. The only instance variable the panel class should have is an array list of points. The array list class has a clear method that removes everything from the array list. 10

11 Ex. 8. There is a button, a label, and an 8 x 8 array of panels. Yeehaw! When a mouse enters a panel its background color turns black, when the mouse exits the background color goes back to white. At no time will more than one panel have a black background. Whenever the user clicks on the button, a random color will appear in the label. Then if a mouse enters a panel its background color turns to that color. Here are some hints for the panel class. There should only be two instance variables, the starting color of white and its special color which starts out as black. Add a mutator method that can change the special color. There s no need to override the paintcomponent method because nothing is being drawn on the panels. You will need to add an inner class that implements the MouseListener interface. Here are some hints for the frame class JLabels are transparent by default. Call the setopaque method and set the label s background to black. When the button is clicked, generate a random color. Change the background color of the label to this color and call the mutator method for each of the 62 panels. You can pick your own dimensions. My panels are 50 by 50 pixels. Ex. 9. There is one label and one panel. At the start there are 10 blue circles are moving to the right. When one goes off the right side it reappears on the left. Yes, there s a timer and so far this is very similar to exercise 6. Whenever the user clicks on a circle, the circle disappears and the label is updated. Nothing special happens when the last circle is clicked on. In this program the timer needs to tell the panel to update itself and the panel needs to tell the label in the frame to change whenever a circle is clicked on. The outline on the next page shows how this can be done. 11

12 Many now familiar details are left out so that we can focus on key new details. public class Ex9Frame extends JFrame { private Ex9Panel p1; private JLabel lblstatus = new JLabel( "There are 10 circle(s)" ); private javax.swing.timer timer; public Ex9Frame(){ usual stuff plus somewhere you need to have the following statement p1 = new Ex9Panel( Color.YELLOW, 300, 300, this ); public void updatelabel( int n ){ lblstatus.settext( "There are " + n + " circle(s) left." ); Display method Inner class to handle Action events from the timer. Whenever an action event is received, call the move method of the panel class. public class Ex9Panel extends JPanel { private ArrayList<Point> pts = new ArrayList<Point>(); private Ex9Frame frame; private static final int RADIUS = 15; public Ex9Panel( Color bg, int w, int h, Ex9Frame f ) { frame = f; Create the 10 points which represent the center of each circle Be sure to add a mouse public void paintcomponent( Graphics g ) { Loop through the array list and draw the circles. The points in the array are the centers of the circles, not the upper left hand corners public void move(){ Loop through the array list and move each point to the right 5 pixels. If the point went outside the visible region of the panel, move it back to the left side. Remember to call the method that causes paintcomponent to be called. Inner class to respond to the mouse events. When the mouse is pressed, calculate the distance between that point and each of the points in the array list. Remove any point with 15 pixels of where the mouse went down. Afterwards update the label and call the method. 12

13 Ex. 10. There are four JLabels over one panel. The panel is initially white and empty. If you press, drag, and then release the mouse a red rectangle should appear. This should work no matter where you start on the panel and which direction you drag the mouse. HOWEVER, the rectangle does not appear until you release the mouse. If you click on one of the four colored labels, any future rectangles will be that color. Hints for the panel class. Create a Color instance variable to represent the current color being used when creating rectangles. Initialize this to red. Create an array list of Rectangle objects. The Rectangle constructor looks like this: Rectangle r = new Rectangle( x, y, width, height); and it has four public instance variables: x, y, width, and height. Create an array list of Colors to hold the rectangle colors. Create two instance variables, x and y, to store the coordinates of where the mouse is pressed down. Add a mutator method for the current color. Override the paintcomponent method to draw the rectangles. Add a mouse listener to the panel. When the mouse is pressed, store that point. When the mouse is released, create a rectangle based on the starting ending points. This isn t as simple as it seems but it s not that hard either. Add the rectangle and current color to the array lists. Hints for the frame class. You cannot add an action listener to a JLabel so you ll have to add a mouse listener. This is a different inner class from the one you wrote for the panel. Whenever someone presses the mouse on a JLabel (or clicks, your choice though one is better than the other), get the color of the label and call the panel s mutator method for the current color. If you have trouble figuring out how to do this, the answer (slightly obfuscated) is below. 13

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

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

AP Computer Science Unit 13. Still More Graphics and Animation.

AP Computer Science Unit 13. Still More Graphics and Animation. AP Computer Science Unit 13. Still More Graphics and Animation. In this unit you ll learn about the following: Mouse Motion Listener Suggestions for designing better graphical programs Simple game with

More information

TWO-DIMENSIONAL FIGURES

TWO-DIMENSIONAL FIGURES TWO-DIMENSIONAL FIGURES Two-dimensional (D) figures can be rendered by a graphics context. Here are the Graphics methods for drawing draw common figures: java.awt.graphics Methods to Draw Lines, Rectangles

More information

2IS45 Programming

2IS45 Programming Course Website Assignment Goals 2IS45 Programming http://www.win.tue.nl/~wsinswan/programmeren_2is45/ Rectangles Learn to use existing Abstract Data Types based on their contract (class Rectangle in Rectangle.

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

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

OBJECT ORIENTED PROGRAMMING. Course 8 Loredana STANCIU Room B613

OBJECT ORIENTED PROGRAMMING. Course 8 Loredana STANCIU Room B613 OBJECT ORIENTED PROGRAMMING Course 8 Loredana STANCIU loredana.stanciu@upt.ro Room B613 Applets A program written in the Java programming language that can be included in an HTML page A special kind of

More information

CSIS 10A Assignment 14 SOLUTIONS

CSIS 10A Assignment 14 SOLUTIONS CSIS 10A Assignment 14 SOLUTIONS Read: Chapter 14 Choose and complete any 10 points from the problems below, which are all included in the download file on the website. Use BlueJ to complete the assignment,

More information

Practice Midterm 1. Problem Points Score TOTAL 50

Practice Midterm 1. Problem Points Score TOTAL 50 CS 120 Software Design I Spring 2019 Practice Midterm 1 University of Wisconsin - La Crosse February 25 NAME: Do not turn the page until instructed to do so. This booklet contains 10 pages including the

More information

public static void main(string[] args) { GTest mywindow = new GTest(); // Title This program creates the following window and makes it visible:

public static void main(string[] args) { GTest mywindow = new GTest(); // Title This program creates the following window and makes it visible: Basics of Drawing Lines, Shapes, Reading Images To draw some simple graphics, we first need to create a window. The easiest way to do this in the current version of Java is to create a JFrame object which

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

Name CS/120 Sample Exam #1 -- Riley. a) Every program has syntax, which refers to the form of the code, and, which refers to the meaning of the code.

Name CS/120 Sample Exam #1 -- Riley. a) Every program has syntax, which refers to the form of the code, and, which refers to the meaning of the code. Name CS/120 Sample Exam #1 -- Riley Please show all of your work. 1. For each part below write the term, symbols, or phrase from class that best fits the description. (Each part is worth 2 points.) a)

More information

Unit 7: Event driven programming

Unit 7: Event driven programming Faculty of Computer Science Programming Language 2 Object oriented design using JAVA Dr. Ayman Ezzat Email: ayman@fcih.net Web: www.fcih.net/ayman Unit 7: Event driven programming 1 1. Introduction 2.

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

Practice Midterm 1 Answer Key

Practice Midterm 1 Answer Key CS 120 Software Design I Fall 2018 Practice Midterm 1 Answer Key University of Wisconsin - La Crosse Due Date: October 5 NAME: Do not turn the page until instructed to do so. This booklet contains 10 pages

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

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

Designing Classes Part 2

Designing Classes Part 2 Designing Classes Part 2 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/ Graphical

More information

cs Java: lecture #5

cs Java: lecture #5 cs3101-003 Java: lecture #5 news: homework #4 due today homework #5 out today today s topics: applets, networks, html graphics, drawing, handling images graphical user interfaces (GUIs) event handling

More information

CS 201 Advanced Object-Oriented Programming Lab 10 - Recursion Due: April 21/22, 11:30 PM

CS 201 Advanced Object-Oriented Programming Lab 10 - Recursion Due: April 21/22, 11:30 PM CS 201 Advanced Object-Oriented Programming Lab 10 - Recursion Due: April 21/22, 11:30 PM Introduction to the Assignment In this assignment, you will get practice with recursion. There are three parts

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

Appendix F: Java Graphics

Appendix F: Java Graphics Appendix F: Java Graphics CS 121 Department of Computer Science College of Engineering Boise State University August 21, 2017 Appendix F: Java Graphics CS 121 1 / 15 Topics Graphics and Images Coordinate

More information

Graphics Applets. By Mr. Dave Clausen

Graphics Applets. By Mr. Dave Clausen Graphics Applets By Mr. Dave Clausen Applets A Java application is a stand-alone program with a main method (like the ones we've seen so far) A Java applet is a program that is intended to transported

More information

Computer Science II - Test 2

Computer Science II - Test 2 Computer Science II - Test 2 Question 1. (15 points) The MouseListener interface requires methods for mouseclicked, mouseentered, mouseexited, mousepressed, and mousereleased. Java s MouseAdapter implements

More information

Appendix F: Java Graphics

Appendix F: Java Graphics Appendix F: Java Graphics CS 121 Department of Computer Science College of Engineering Boise State University August 21, 2017 Appendix F: Java Graphics CS 121 1 / 1 Topics Graphics and Images Coordinate

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

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

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

Example: Building a Java GUI

Example: Building a Java GUI Steven Zeil October 25, 2013 Contents 1 Develop the Model 2 2 Develop the layout of those elements 3 3 Add listeners to the elements 9 4 Implement custom drawing 12 1 The StringArt Program To illustrate

More information

Dr. Hikmat A. M. AbdelJaber

Dr. Hikmat A. M. AbdelJaber Dr. Hikmat A. M. AbdelJaber Portion of the Java class hierarchy that include basic graphics classes and Java 2D API classes and interfaces. java.lang.object Java.awt.Color Java.awt.Component Java.awt.Container

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

Example: Building a Java GUI

Example: Building a Java GUI Steven Zeil October 25, 2013 Contents 1 Develop the Model 3 2 Develop the layout of those elements 4 3 Add listeners to the elements 12 4 Implement custom drawing 15 1 The StringArt Program To illustrate

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

Control Statements: Part Pearson Education, Inc. All rights reserved.

Control Statements: Part Pearson Education, Inc. All rights reserved. 1 5 Control Statements: Part 2 5.2 Essentials of Counter-Controlled Repetition 2 Counter-controlled repetition requires: Control variable (loop counter) Initial value of the control variable Increment/decrement

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

CSCI 053. Week 5 Java is like Alice not based on Joel Adams you may want to take notes. Rhys Price Jones. Introduction to Software Development

CSCI 053. Week 5 Java is like Alice not based on Joel Adams you may want to take notes. Rhys Price Jones. Introduction to Software Development CSCI 053 Introduction to Software Development Rhys Price Jones Week 5 Java is like Alice not based on Joel Adams you may want to take notes Objectives Learn to use the Eclipse IDE Integrated Development

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

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

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

Garfield AP CS. Graphics

Garfield AP CS. Graphics Garfield AP CS Graphics Assignment 3 Working in pairs Conditions: I set pairs, you have to show me a design before you code You have until tomorrow morning to tell me if you want to work alone Cumulative

More information

More about GUIs GEEN163

More about GUIs GEEN163 More about GUIs GEEN163 The best programmers are not marginally better than merely good ones. They are an order-ofmagnitude better, measured by whatever standard: conceptual creativity, speed, ingenuity

More information

public void mouseexited (MouseEvent e) setminute(getminute()+increment); 11.2 public void mouseclicked (MouseEvent e) int x = e.getx(), y = e.gety();

public void mouseexited (MouseEvent e) setminute(getminute()+increment); 11.2 public void mouseclicked (MouseEvent e) int x = e.getx(), y = e.gety(); 11 The Jav aawt Part I: Mouse Events 11.1 public void mouseentered (MouseEvent e) setminute(getminute()+increment); 53 public void mouseexited (MouseEvent e) setminute(getminute()+increment); 11.2 public

More information

Graphics Applets. By Mr. Dave Clausen

Graphics Applets. By Mr. Dave Clausen Graphics Applets By Mr. Dave Clausen Applets A Java application is a stand-alone program with a main method (like the ones we've seen so far) A Java applet is a program that is intended to transported

More information

CSC System Development with Java Introduction to Java Applets Budditha Hettige

CSC System Development with Java Introduction to Java Applets Budditha Hettige CSC 308 2.0 System Development with Java Introduction to Java Applets Budditha Hettige Department of Statistics and Computer Science What is an applet? applet: a Java program that can be inserted into

More information

AplusBug dude = new AplusBug(); A+ Computer Science -

AplusBug dude = new AplusBug(); A+ Computer Science - AplusBug dude = new AplusBug(); AplusBug dude = new AplusBug(); dude 0x234 AplusBug 0x234 dude is a reference variable that refers to an AplusBug object. A method is a storage location for related program

More information

11/7/12. Discussion of Roulette Assignment. Objectives. Compiler s Names of Classes. GUI Review. Window Events

11/7/12. Discussion of Roulette Assignment. Objectives. Compiler s Names of Classes. GUI Review. Window Events Objectives Event Handling Animation Discussion of Roulette Assignment How easy/difficult to refactor for extensibility? Was it easier to add to your refactored code? Ø What would your refactored classes

More information

Method Of Key Event Key Listener must implement three methods, keypressed(), keyreleased() & keytyped(). 1) keypressed() : will run whenever a key is

Method Of Key Event Key Listener must implement three methods, keypressed(), keyreleased() & keytyped(). 1) keypressed() : will run whenever a key is INDEX Event Handling. Key Event. Methods Of Key Event. Example Of Key Event. Mouse Event. Method Of Mouse Event. Mouse Motion Listener. Example of Mouse Event. Event Handling One of the key concept in

More information

Building Java Programs

Building Java Programs Building Java Programs Supplement 3G: Graphics 1 drawing 2D graphics Chapter outline DrawingPanel and Graphics objects drawing and filling shapes coordinate system colors drawing with loops drawing with

More information

Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how to paint graphics on GUI components

Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how to paint graphics on GUI components CS112-Section2 Hakan Guldas Burcin Ozcan Meltem Kaya Muge Celiktas Notes of 6-8 May Graphics Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how

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

CS2110. GUIS: Listening to Events

CS2110. GUIS: Listening to Events CS2110. GUIS: Listening to Events Also anonymous classes Download the demo zip file from course website and look at the demos of GUI things: sliders, scroll bars, combobox listener, etc 1 mainbox boardbox

More information

IT101. Graphical User Interface

IT101. Graphical User Interface IT101 Graphical User Interface Foundation Swing is a platform-independent set of Java classes used for user Graphical User Interface (GUI) programming. Abstract Window Toolkit (AWT) is an older Java GUI

More information

Programmierpraktikum

Programmierpraktikum Programmierpraktikum Claudius Gros, SS2012 Institut für theoretische Physik Goethe-University Frankfurt a.m. 1 of 18 17/01/13 11:46 Java Applets 2 of 18 17/01/13 11:46 Java applets embedding Java applications

More information

(listener)... MouseListener, ActionLister. (adapter)... MouseAdapter, ActionAdapter. java.awt AWT Abstract Window Toolkit GUI

(listener)... MouseListener, ActionLister. (adapter)... MouseAdapter, ActionAdapter. java.awt AWT Abstract Window Toolkit GUI 51 6!! GUI(Graphical User Interface) java.awt javax.swing (component) GUI... (container) (listener)... MouseListener, ActionLister (adapter)... MouseAdapter, ActionAdapter 6.1 GUI(Graphics User Interface

More information

Building Java Programs

Building Java Programs Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2 Objects (briefly) object: An entity that contains data and behavior. data: variables inside the object behavior: methods inside

More information

CS/120 Final Exam. Name

CS/120 Final Exam. Name CS/120 Final Exam Name 16 pts 1. Trace the following segment of code and to the left of each System.out.println instruction show the precise output that results when this code segment executes. java.awt.container

More information

(0,0) (600, 400) CS109. PictureBox and Timer Controls

(0,0) (600, 400) CS109. PictureBox and Timer Controls CS109 PictureBox and Timer Controls Let s take a little diversion and discuss how to draw some simple graphics. Graphics are not covered in the book, so you ll have to use these notes (or the built-in

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

9. APPLETS AND APPLICATIONS

9. APPLETS AND APPLICATIONS 9. APPLETS AND APPLICATIONS JAVA PROGRAMMING(2350703) The Applet class What is an Applet? An applet is a Java program that embedded with web content(html) and runs in a Web browser. It runs inside the

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

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

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

CSE115 Lab 4 Fall 2016

CSE115 Lab 4 Fall 2016 DUE DATES: Monday recitations: 9:00 PM on 10/09 Wednesday recitations: 9:00 PM on 10/11 Thursday recitations: 9:00 PM on 10/12 Friday recitations: 9:00 PM on 10/13 Saturday recitations: 9:00 PM on 10/14

More information

Block I Unit 2. Basic Constructs in Java. AOU Beirut Computer Science M301 Block I, unit 2 1

Block I Unit 2. Basic Constructs in Java. AOU Beirut Computer Science M301 Block I, unit 2 1 Block I Unit 2 Basic Constructs in Java M301 Block I, unit 2 1 Developing a Simple Java Program Objectives: Create a simple object using a constructor. Create and display a window frame. Paint a message

More information

Building Java Programs

Building Java Programs Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2 Objects (briefly) object: An entity that contains data and behavior. data: Variables inside the object. behavior: Methods inside

More information

EXCEPTIONS & GUI. Errors are signals that things are beyond help. Review Session for. -Ankur Agarwal

EXCEPTIONS & GUI. Errors are signals that things are beyond help. Review Session for. -Ankur Agarwal Review Session for EXCEPTIONS & GUI -Ankur Agarwal An Exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions. Errors are signals

More information

Queen s University Faculty of Arts and Science School of Computing CISC 124 Final Examination December 2004 Instructor: M. Lamb

Queen s University Faculty of Arts and Science School of Computing CISC 124 Final Examination December 2004 Instructor: M. Lamb Queen s University Faculty of Arts and Science School of Computing CISC 124 Final Examination December 2004 Instructor: M. Lamb HAND IN Answers recorded on Examination paper This examination is THREE HOURS

More information

2. (True/False) All methods in an interface must be declared public.

2. (True/False) All methods in an interface must be declared public. Object and Classes 1. Create a class Rectangle that represents a rectangular region of the plane. A rectangle should be described using four integers: two represent the coordinates of the upper left corner

More information

Lab 10: Inheritance (I)

Lab 10: Inheritance (I) CS2370.03 Java Programming Spring 2005 Dr. Zhizhang Shen Background Lab 10: Inheritance (I) In this lab, we will try to understand the concept of inheritance, and its relation to polymorphism, better;

More information

Advanced Internet Programming CSY3020

Advanced Internet Programming CSY3020 Advanced Internet Programming CSY3020 Java Applets The three Java Applet examples produce a very rudimentary drawing applet. An Applet is compiled Java which is normally run within a browser. Java applets

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

Please show all of your work.

Please show all of your work. Please show all of your work. Name CS/120 Exam #2 Sample Exam 1. For each part below write the term, symbols, or phrase from class that best fits the description. (Each part is worth 2 points.) a) This

More information

CS 201 Advanced Object-Oriented Programming Lab 1 - Improving Your Image Due: Feb. 3/4, 11:30 PM

CS 201 Advanced Object-Oriented Programming Lab 1 - Improving Your Image Due: Feb. 3/4, 11:30 PM CS 201 Advanced Object-Oriented Programming Lab 1 - Improving Your Image Due: Feb. 3/4, 11:30 PM Objectives The objectives of this assignment are: to refresh your Java programming to become familiar with

More information

MIT AITI Swing Event Model Lecture 17

MIT AITI Swing Event Model Lecture 17 MIT AITI 2004 Swing Event Model Lecture 17 The Java Event Model In the last lecture, we learned how to construct a GUI to present information to the user. But how do GUIs interact with users? How do applications

More information

Inheritance. One class inherits from another if it describes a specialized subset of objects Terminology:

Inheritance. One class inherits from another if it describes a specialized subset of objects Terminology: Inheritance 1 Inheritance One class inherits from another if it describes a specialized subset of objects Terminology: the class that inherits is called a child class or subclass the class that is inherited

More information

GUI (Graphic User Interface) Programming. Part 2 (Chapter 8) Chapter Goals. Events, Event Sources, and Event Listeners. Listeners

GUI (Graphic User Interface) Programming. Part 2 (Chapter 8) Chapter Goals. Events, Event Sources, and Event Listeners. Listeners GUI (Graphic User Interface) Programming Part 2 (Chapter 8) Chapter Goals To understand the Java event model To install action and mouse event listeners To accept input from buttons, text fields, and the

More information

Topic Notes: Java and Objectdraw Basics

Topic Notes: Java and Objectdraw Basics Computer Science 120 Introduction to Programming Siena College Spring 2011 Topic Notes: Java and Objectdraw Basics Event-Driven Programming in Java A program expresses an algorithm in a form understandable

More information

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread G51PGP Programming Paradigms Lecture 008 Inner classes, anonymous classes, Swing worker thread 1 Reminder subtype polymorphism public class TestAnimals public static void main(string[] args) Animal[] animals

More information

In this lecture we will briefly examine a few new controls, introduce the concept of scope, random numbers, and drawing simple graphics.

In this lecture we will briefly examine a few new controls, introduce the concept of scope, random numbers, and drawing simple graphics. Additional Controls, Scope, Random Numbers, and Graphics CS109 In this lecture we will briefly examine a few new controls, introduce the concept of scope, random numbers, and drawing simple graphics. Combo

More information

ming 3 Resize the Size to [700, 500]. Note that the background containers in the program code: reference the then under () { 153, 255, 0 ) );

ming 3 Resize the Size to [700, 500]. Note that the background containers in the program code: reference the then under () { 153, 255, 0 ) ); ECCS 166 Programm ming 3 Dr. Estell Spring Quarter 20111 Laboratory Assignmen nt 7 Graphics and Polymorphism 15 April 2011 1. The purpose of the next few laboratory assignments is to create a simple drawing

More information

Chapter. We've been using predefined classes. Now we will learn to write our own classes to define objects

Chapter. We've been using predefined classes. Now we will learn to write our own classes to define objects Writing Classes 4 Chapter 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design 2007 Pearson Addison-Wesley. All rights reserved Writing Classes We've been using predefined

More information

Name: Checked: Learn about listeners, events, and simple animation for interactive graphical user interfaces.

Name: Checked: Learn about listeners, events, and simple animation for interactive graphical user interfaces. Lab 15 Name: Checked: Objectives: Learn about listeners, events, and simple animation for interactive graphical user interfaces. Files: http://www.csc.villanova.edu/~map/1051/chap04/smilingface.java http://www.csc.villanova.edu/~map/1051/chap04/smilingfacepanel.java

More information

Chapter 24. Graphical Objects The GraphicalObject Class

Chapter 24. Graphical Objects The GraphicalObject Class 290 Chapter 24 Graphical Objects The simple graphics we saw earlier created screen artifacts. A screen artifact is simply an image drawn on the screen (viewport), just as a picture can be drawn on a whiteboard.

More information

JFrame In Swing, a JFrame is similar to a window in your operating system

JFrame In Swing, a JFrame is similar to a window in your operating system JFrame In Swing, a JFrame is similar to a window in your operating system All components will appear inside the JFrame window Buttons, text labels, text fields, etc. 5 JFrame Your GUI program must inherit

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

PESIT Bangalore South Campus

PESIT Bangalore South Campus INTERNAL ASSESSMENT TEST II Date : 20-09-2016 Max Marks: 50 Subject & Code: JAVA & J2EE (10IS752) Section : A & B Name of faculty: Sreenath M V Time : 8.30-10.00 AM Note: Answer all five questions 1) a)

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

COSC 123 Computer Creativity. Graphics and Events. Dr. Ramon Lawrence University of British Columbia Okanagan

COSC 123 Computer Creativity. Graphics and Events. Dr. Ramon Lawrence University of British Columbia Okanagan COSC 123 Computer Creativity Graphics and Events Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Key Points 1) Draw shapes, text in various fonts, and colors. 2) Build

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

Final Examination Semester 2 / Year 2011

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

More information

Using the API: Introductory Graphics Java Programming 1 Lesson 8

Using the API: Introductory Graphics Java Programming 1 Lesson 8 Using the API: Introductory Graphics Java Programming 1 Lesson 8 Using Java Provided Classes In this lesson we'll focus on using the Graphics class and its capabilities. This will serve two purposes: first

More information

UI Software Organization

UI Software Organization UI Software Organization The user interface From previous class: Generally want to think of the UI as only one component of the system Deals with the user Separate from the functional core (AKA, the app

More information

1.00/1.001 Introduction to Computers and Engineering Problem Solving Fall (total 7 pages)

1.00/1.001 Introduction to Computers and Engineering Problem Solving Fall (total 7 pages) 1.00/1.001 Introduction to Computers and Engineering Problem Solving Fall 2002 (total 7 pages) Name: TA s Name: Tutorial: For Graders Question 1 Question 2 Question 3 Total Problem 1 (20 points) True or

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 CMPE212, FALL TERM, 2012 FINAL EXAMINATION 18 December 2012, 2pm Instructor: Alan McLeod If the instructor is unavailable

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

@Override public void start(stage primarystage) throws Exception { Group root = new Group(); Scene scene = new Scene(root);

@Override public void start(stage primarystage) throws Exception { Group root = new Group(); Scene scene = new Scene(root); Intro to Drawing Graphics To draw some simple graphics, we first need to create a window. The easiest way to do this in the current version of Java is to create a JavaFX application. Previous versions

More information

Programming Language Concepts: Lecture 8

Programming Language Concepts: Lecture 8 Programming Language Concepts: Lecture 8 Madhavan Mukund Chennai Mathematical Institute madhavan@cmi.ac.in http://www.cmi.ac.in/~madhavan/courses/pl2009 PLC 2009, Lecture 8, 11 February 2009 GUIs and event

More information

Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling

Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling Frames, GUI and events Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling Introduction to Swing The Java AWT (Abstract Window Toolkit)

More information