56
More about GUIs COMP163

More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

More aboutGUIs

COMP163

Page 2: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

“Learning is not attained by chance,

it must be sought for with ardor and

attended to with diligence.”

Abigail Adams

2nd First Lady of the United States

Page 3: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

Teaching Evaluation

• The official University teaching evaluation survey is on Blackboard

• Complete the survey for ALL classes

• 19% of the students in COMP163 have completed the evaluation

Page 4: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

COMP163 Schedule

Mon, Nov 12

More on GUIsWed, Nov 14

Secure ProgrammingFri, Nov 16

review

Mon, Nov 19

Exam 3Wed, Nov 21

Thanksgiving Holiday(no classes)

Fri, Nov 23

Thanksgiving Holiday(no classes)

Mon, Nov 26

Software engineeringWed, Nov 28

final reviewThursday, Nov 29

Lab Final

Tuesday, Dec 4

Final10:30 – 12:30

Exam

Page 5: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,
Page 6: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,
Page 7: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

Interesting Objects

Many GUI program can be created with a few simple components

• JLabel – Displays text in the GUI

• JButton – Creates a button you can press

• JTextField – Creates an input text box

• All of these objects are from the package javax.swing

Page 8: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

How do you make an array of 5 buttons for a GUI?

A. JButton[5] gazelle = new JButton[];

B. JButton gazelle = new JButton(5);

C. JButton[] gazelle = new JButton[5];

D. JButton[] gazelle = { JButton(), JButton(),JButton(), JButton(), JButton() };

E. You cannot make an array of GUI objects

Page 9: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

Array of Objects

• If you create an array of objects, you need to create the objects in the array

for (int cow = 0; cow < 5; cow++) {

gazelle[cow] = new JButton("Go");

pane.add( gazelle[cow] );

gazelle[cow].addActionListener( this );

}

Page 10: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

Implementing ActionListener

• Implementing the ActionListener interface makes the program respond to GUI input

• Programs implementing ActionListener must have an actionPerformed method

public class MyAppletextends javax.swing.JFrameimplements java.awt.event.ActionListener {

Page 11: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

Interfaces

• A Java interface has a list of method headers that a program must implement

• ActionListener is an interface that requires a program to include an actionPerformed method

• Programmers can create their own interfaces

– This is a topic for COMP167

Page 12: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

Possible Interface for Bouncing Circles

public interface Bouncable {public double getX();public void setX( double horz );public double getY();public void setY( double vert );public boolean touches( Circle other );

}

The Circle class could bepublic class Circle implements Bouncable { … }

Page 13: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

Other Interfaces

• There are many interfaces in the standard Java libraries

• The Comparable interface requires implementing classes to have a compareTomethod

public int compareTo( MyClass other )

• Returns a negative, zero, or positive integer as this object is less than, equal to, or greater than the other object

Page 14: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

The Comparable interface is implemented by which class?

A. Math

B. Scanner

C. String

D. Only classes that you write

Page 15: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

Generics

• Sometime when you create an object or interface in Java, you must specify the class it will work with

• When you used a HashTable you had to specify the type of the key and data

Hashtable<String, WordData> dict =

new Hashtable<>(18000);

• You must specify the type for Comparablepublic class Mine implements Comparable<Mine>

Page 16: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

Adding a Listener

• The method addActionListener should be called on each GUI component that can do something

• Do not call addActionListener on components that do not do anything, like JLabels

javax.swing.JButton frog = newjavax.swing.JButton("Go");

frog.addActionListener( this );

Page 17: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

Taking Action

• When a user clicks an object with an ActionListener, Java calls the method

public void actionPerformed(java.awt.event.ActionEvent rabbit) {

// do something here

}

• This method should do what the user expects to happen when the button is pressed

Page 18: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

Getting the Text

• You can get the text from a GUI component with the getText() method

• This is useful to get the text a person entered in the JTextField

javax.swing.JTextField llama = newjavax.swing.JTextField();

// in the actionPerformed method

String answer = llama.getText();

Page 19: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

Changing a Component’s Text

• A useful method is setText It can be used to change the text of any object that has text, such as JButtons, JLabels and JTextfields

javax.swing.JLabel msg =new javax.swing.JLabel("Do something");

msg.setText("Don’t do something");

Page 20: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

Who Dunit?

• Many GUIs have more than one active object

• You can determine where the action was taken by using the getSource() method of the event

• The result of getSource() should be compared to each GUI object

public void actionPerformed( java.awt.event.ActionEvent frog ) {

if ( frog.getSource() == GUIobject ) {

Page 21: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

Example Use of getSource()

JButton delete = new JButton(“kill”);

JButton save = new JButton(“allow”);

- - - - - - - - - - - - - - - - - - - - - - - - - - - -

public void actionPerformed( java.awt.event.ActionEvent toad) {

if (toad.getSource() == delete ) {

// delete something

} else {

// don’t delete anything

}

Page 22: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

Looping in GUI Programs

• When you want a user to enter multiple

values in a GUI program, you probably do notneed a for loop or a while loop

• Each time the user enters a name, it will call actionPerformed

Page 23: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

What will select the pressed button?

A. if( bear == deer )

B. if( bear.getSource() == JButton )

C. if( bear.getSource() == deer )

D. if( deer == JButton.getSource() )

E. if( this == bear.getSource() )

JButton deer = new JButton();public void actionPerformed(

java.awt.event.ActionEvent bear)

Page 24: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

setVisible

• Most GUI components have a setVisiblemethod

setVisible( boolean )

• If the boolean parameter is true, the object shows, if false it does not show

• Calling setVisible(true) makes the frame appear onscreen

Page 25: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

Disabling GUI Components

• Individual GUI components (i.e. JButtons) can be made invisible or disabled

• A disabled component is gray and cannot be selected

JButton myButton = new JButton("OK");

myButton.setEnabled(false);

• This will make the button gray and unusable

Page 26: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

setTitle

• The setTitle method of a JFrame sets the text in the upper border of the window

setTitle("My GUI program");

Page 27: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

pack

• The pack method sizes the frame so that all its contents are at their preferred sizes

• When you use the pack method, you do not have to call setSize for the frame

• If you use absolute positioning of components instead of a layout manager, you do not need to call pack

Page 28: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

pack() Issues

• Using setSize and not pack()

• Using pack()

• Using pack() with spaces in JTextfields

Page 29: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

Sample GUI ConstructorJTextField inStuff = new JTextField( 8 ); // space for 8 letters

JButton theButton = new JButton("OK");

public MyGUI( ) {

java.awt.Container pane = getContentPane();

BoxLayout where = new BoxLayout(pane, BoxLayout.Y_AXIS);

setLayout(where);

pane.add(inStuff);

pane.add(theButton);

theButton.addActionListener(this);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setVisible(true);

pack();

}

Page 30: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

Method Review

• Follow the flow of execution. Execution starts in the main method

• Constructors can be used to initialize objects

Page 31: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

What is displayed?public class Colors {

static void aqua(int fish) {

grass(fish + 2);System.out.println("Blue "+ fish);

}static void grass(int snake){

System.out.println(“Green "+ snake);}public static void main(String[] args) {

System.out.println("Gray");aqua( 1 );

}static void rouge(int bird) {

System.out.println("Scarlet"+ bird);}

}

A. Blue 2Green 1Gray Scarlet 3

B. GrayBlue 3

C. GrayGreen 1Blue 3

D. GrayGreen 3Blue 1

E. none of the above

Page 32: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

Creating Arrays of Objects

• Often you will create an array and put the objects in the array as you create them

• Consider a program that will create an array of WordData objects using data from a file

WordData[] centaur = new WordData[1000];

• The array can hold 1000 objects, but it is initially empty with all elements equal to null

Page 33: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

Example Classpublic class WordData {

private String sphinx;private int count = 1;public WordData( String aWord ) {

sphinx = aWord;}public String getWord() {

return sphinx;}

public boolean match( String mermaid ) {

return sphinx.equals( mermaid );

}

}

Page 34: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

Putting Data in the Array

WordData[] centaur = new WordData[1000];

int numObj = 0;

java.io.File griffin = new java.io.File("stuff.txt");

Scanner dragon = new Scanner( griffin );

while ( dragon.hasNext() ) {

String unicorn = dragon.next();

centaur[numObj] = new WordData(unicorn);

numObj++;

}

Page 35: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

Incrementing in an Index

WordData[] centaur = new WordData[1000];

int numObj = 0;

java.io.File griffin = new java.io.File("stuff.txt");

Scanner dragon = new Scanner( griffin );

while ( dragon.hasNext() ) {

String unicorn = dragon.next();

centaur[numObj++] = new WordData(unicorn);

}

Page 36: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

How can you call the chew()method on all objects??

Assume you have an array cow that contains 12 objects of the class Bovin which has a method called chew()

for (int i = 0; i < 12; i++) {

A. cow.chew(i);

B. cow.chew[i];

C. cow[i].chew();

D. cow.chew()[i]

E. Bovine.chew(i)

Page 37: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

Multiple Methods

names[3].trim().length()

array

elementString

returned valueString

returned value

int

Page 38: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

Finding Things in an Array

• Programs may need to search an array of objects for one that matches an instance variable

• If the data in the object is private, you will have to use a method to access it

Page 39: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

Search Objects with Get

String target = "special";

for (int roc = 0; roc < numObj; roc++) {

if (target.equals(centaur[roc].getWord()) {

System.out.println("found it");

break;

}

}

Page 40: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

Search Objects with match()

String target = "special";

for (int roc = 0; roc < numObj; roc++) {

if (centaur[roc].match( target )) {

System.out.println("found it");

break;

}

}

Page 41: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

Graphics Coordinates

• The screen has a coordinate system with the origin in the upper left corner

• Coordinates are given in pixels (Picture Elements)

• An X coordinate specifies the distance from the left edge

• A Y coordinate specified the distance from the top edge

• The screen size depends on the device

Page 42: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

drawLine• The drawLine method of java.awt.Graphics

objects draws a line from x1,y1 to x2,y2

bird.drawLine(5, 3, 17, 23);

• The line is drawn using the current color

53

17

23

Page 43: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

Location 0,0 is

D. center

A. upper left corner

B. lower left corner

C. upper right corner

Page 44: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

drawRect• The drawRect method of java.awt.Graphics

objects draws a rectangle of width and height whose upper left corner is x,y

bird.drawRect( x, y, width, height);

bird.drawRect( 5, 3, 10, 15 );

53

10

15

Page 45: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

fillRect• The fillRect method of java.awt.Graphics

objects draws a rectangle of width and height whose upper left corner is x,y and fills it with the current color

bird.fillRect( 5, 3, 10, 15 );

53

10

15

Page 46: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

Outside and Overlapping• It is permissible to have a graphics object

(such as a rectangle) extend outside the visible window

• The portion outside the window will not be visible

• An object can overlap one another

bird.fillRect( 5, 3, 10, 15 );

bird.setColor( Color.GREEN );

bird.fillRect( 8, 15, 10, 15 );

Page 47: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

drawOval• The drawOval method of java.awt.Graphics

objects draws a circle or oval to fit in a box of width and height whose upper left is x,y

bird.drawOval( x, y, width, height );

bird.drawOval( 5, 3, 10, 15 );

53

10

15

Page 48: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

fillOval

• fillOval is just like drawOval, but it colors in the circle with the current color

bird.fillOval( 5, 3, 10, 15 );

53

10

15

Page 49: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

What is the output?public void paint(java.awt.Graphics parrot) {

parrot.setColor(java.awt.Color.BLACK);

parrot.drawRect( 0, 0, 100, 100);

parrot.fillRect( 50, 0, 50, 50 );

}

A. B. C. D.

Page 50: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

drawPolygon

• The drawPolygon draws lines between the points specified by an array

drawPolygon(int[] xPoints,

int[] yPoints, int nPoints)

• where there are nPoints values in both arrays

• Lines are drawn from (xPoints[0], yPoints[0]) to (xPoints[1], yPoints[1]) and from there to (xPoints[2], yPoints[2]) and so forth

• A line is drawn between the last point and the first point

Page 51: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

drawPolygon Example

int[] xs = { 5, 12, 5};

int[] ys = { 7, 20, 20};

bird.drawPolygon( xs, ys, 3 );

5, 7

12, 205, 20

Page 52: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

fillPolygon Example

int[] xs = { 5, 12, 5};

int[] ys = { 7, 20, 20};

bird.fillPolygon( xs, ys, 3 );

5, 7

12, 205, 20

Page 53: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

Teaching Evaluation

• The official University teaching evaluation survey is on Blackboard

• Complete the survey for ALL classes

• 19% of the students in COMP163 have completed the evaluation

Page 54: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,

COMP163 Schedule

Mon, Nov 12

More on GUIsWed, Nov 14

Secure ProgrammingFri, Nov 16

review

Mon, Nov 19

Exam 3Wed, Nov 21

Thanksgiving Holiday(no classes)

Fri, Nov 23

Thanksgiving Holiday(no classes)

Mon, Nov 26

Software engineeringWed, Nov 28

final reviewThursday, Nov 29

Lab Final

Tuesday, Dec 4

Final10:30 – 12:30

Exam

Page 55: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,
Page 56: More about GUIswilliams.comp.ncat.edu/COMP163/GUIreview.pdf · COMP163 Schedule Mon, Nov 12 More on GUIs Wed, Nov 14 Secure Programming Fri, Nov 16 review Mon, Nov 19 Exam 3 Wed,