geog178/258 week7 - mikejohnson51.github.io · week7: polygons, guis, draw** mike johnson....
TRANSCRIPT
![Page 1: GEOG178/258 Week7 - mikejohnson51.github.io · Week7: Polygons, GUIs, draw** mike johnson. Polygons: *Surface Interface *Inherits from Triangle. If we use the extends keyword We are](https://reader034.vdocuments.net/reader034/viewer/2022052019/6032a5c8c492187aea67eeaf/html5/thumbnails/1.jpg)
GEOG 178/258Week 7:
Polygons, GUIs, draw**
mike johnson
![Page 2: GEOG178/258 Week7 - mikejohnson51.github.io · Week7: Polygons, GUIs, draw** mike johnson. Polygons: *Surface Interface *Inherits from Triangle. If we use the extends keyword We are](https://reader034.vdocuments.net/reader034/viewer/2022052019/6032a5c8c492187aea67eeaf/html5/thumbnails/2.jpg)
![Page 3: GEOG178/258 Week7 - mikejohnson51.github.io · Week7: Polygons, GUIs, draw** mike johnson. Polygons: *Surface Interface *Inherits from Triangle. If we use the extends keyword We are](https://reader034.vdocuments.net/reader034/viewer/2022052019/6032a5c8c492187aea67eeaf/html5/thumbnails/3.jpg)
Polygons:
![Page 4: GEOG178/258 Week7 - mikejohnson51.github.io · Week7: Polygons, GUIs, draw** mike johnson. Polygons: *Surface Interface *Inherits from Triangle. If we use the extends keyword We are](https://reader034.vdocuments.net/reader034/viewer/2022052019/6032a5c8c492187aea67eeaf/html5/thumbnails/4.jpg)
![Page 5: GEOG178/258 Week7 - mikejohnson51.github.io · Week7: Polygons, GUIs, draw** mike johnson. Polygons: *Surface Interface *Inherits from Triangle. If we use the extends keyword We are](https://reader034.vdocuments.net/reader034/viewer/2022052019/6032a5c8c492187aea67eeaf/html5/thumbnails/5.jpg)
*Surface Interface* Inherits from Triangle
![Page 6: GEOG178/258 Week7 - mikejohnson51.github.io · Week7: Polygons, GUIs, draw** mike johnson. Polygons: *Surface Interface *Inherits from Triangle. If we use the extends keyword We are](https://reader034.vdocuments.net/reader034/viewer/2022052019/6032a5c8c492187aea67eeaf/html5/thumbnails/6.jpg)
![Page 7: GEOG178/258 Week7 - mikejohnson51.github.io · Week7: Polygons, GUIs, draw** mike johnson. Polygons: *Surface Interface *Inherits from Triangle. If we use the extends keyword We are](https://reader034.vdocuments.net/reader034/viewer/2022052019/6032a5c8c492187aea67eeaf/html5/thumbnails/7.jpg)
If we use the extendskeyword
We are inheriting (like genes) the classes and methods from a parent class
![Page 8: GEOG178/258 Week7 - mikejohnson51.github.io · Week7: Polygons, GUIs, draw** mike johnson. Polygons: *Surface Interface *Inherits from Triangle. If we use the extends keyword We are](https://reader034.vdocuments.net/reader034/viewer/2022052019/6032a5c8c492187aea67eeaf/html5/thumbnails/8.jpg)
If we use the implements keyword
We are defining a contract that must be meet
![Page 9: GEOG178/258 Week7 - mikejohnson51.github.io · Week7: Polygons, GUIs, draw** mike johnson. Polygons: *Surface Interface *Inherits from Triangle. If we use the extends keyword We are](https://reader034.vdocuments.net/reader034/viewer/2022052019/6032a5c8c492187aea67eeaf/html5/thumbnails/9.jpg)
Classes and Objects Define Pieces of Code that we can useWhen java compiles we can build instances of classes:
Main methods tell Java how to compile elements into something
that runs, prints, executes, ect
![Page 10: GEOG178/258 Week7 - mikejohnson51.github.io · Week7: Polygons, GUIs, draw** mike johnson. Polygons: *Surface Interface *Inherits from Triangle. If we use the extends keyword We are](https://reader034.vdocuments.net/reader034/viewer/2022052019/6032a5c8c492187aea67eeaf/html5/thumbnails/10.jpg)
Up until now we have been piping all of our output – as text - to the console using System.out.print*
instead, we want to direct our output to a new graphic window using Java swing components
![Page 11: GEOG178/258 Week7 - mikejohnson51.github.io · Week7: Polygons, GUIs, draw** mike johnson. Polygons: *Surface Interface *Inherits from Triangle. If we use the extends keyword We are](https://reader034.vdocuments.net/reader034/viewer/2022052019/6032a5c8c492187aea67eeaf/html5/thumbnails/11.jpg)
Here is a nice picture
It is static
It is an arrangement of parts including:
A) A racoonB) Text
![Page 12: GEOG178/258 Week7 - mikejohnson51.github.io · Week7: Polygons, GUIs, draw** mike johnson. Polygons: *Surface Interface *Inherits from Triangle. If we use the extends keyword We are](https://reader034.vdocuments.net/reader034/viewer/2022052019/6032a5c8c492187aea67eeaf/html5/thumbnails/12.jpg)
This is a button
It is part of the picture WRT to whatwe want to see
To function as a button:
It must also listen to the picture (clicks)
What happens when we click thebutton must also be define!
Actions are a common entity in Java GUIs. Therefore to ensure consistency. listeners are added by implementing The actionListener interface
![Page 13: GEOG178/258 Week7 - mikejohnson51.github.io · Week7: Polygons, GUIs, draw** mike johnson. Polygons: *Surface Interface *Inherits from Triangle. If we use the extends keyword We are](https://reader034.vdocuments.net/reader034/viewer/2022052019/6032a5c8c492187aea67eeaf/html5/thumbnails/13.jpg)
A picture without a home can not be displayed.
If we want to display a picture on the computerwe need a frame to hold it
Just like a real frame,
We need to ”pack” our picture in the frame,
And
Mount it on the wall (make visible)
![Page 14: GEOG178/258 Week7 - mikejohnson51.github.io · Week7: Polygons, GUIs, draw** mike johnson. Polygons: *Surface Interface *Inherits from Triangle. If we use the extends keyword We are](https://reader034.vdocuments.net/reader034/viewer/2022052019/6032a5c8c492187aea67eeaf/html5/thumbnails/14.jpg)
If a change is instigated in the picture,
We don’t need to take down the frame, unpack the elements, and re-draw...
We simply need to repaint!
![Page 15: GEOG178/258 Week7 - mikejohnson51.github.io · Week7: Polygons, GUIs, draw** mike johnson. Polygons: *Surface Interface *Inherits from Triangle. If we use the extends keyword We are](https://reader034.vdocuments.net/reader034/viewer/2022052019/6032a5c8c492187aea67eeaf/html5/thumbnails/15.jpg)
So lets think about the whole system
• We need a panel (class with member variables!)• We need to define how the panel is painted• We need to add buttons (or any Jcomponent) to the panel with
appropriate listeners• We need to define what the buttons do by syncing Boolean
conditions (more on that in examples)• We need to load an instance of our panel into a frame within a main
method.
![Page 16: GEOG178/258 Week7 - mikejohnson51.github.io · Week7: Polygons, GUIs, draw** mike johnson. Polygons: *Surface Interface *Inherits from Triangle. If we use the extends keyword We are](https://reader034.vdocuments.net/reader034/viewer/2022052019/6032a5c8c492187aea67eeaf/html5/thumbnails/16.jpg)
ButtonsListeners
Panel paintComponent
FramePacked panels, visibility option
Buttons are both part of panels AND listen to panelsPanels are painted (or repainted) and go in framesFrames pack panel objects, have visibility, and need to be able to close
![Page 17: GEOG178/258 Week7 - mikejohnson51.github.io · Week7: Polygons, GUIs, draw** mike johnson. Polygons: *Surface Interface *Inherits from Triangle. If we use the extends keyword We are](https://reader034.vdocuments.net/reader034/viewer/2022052019/6032a5c8c492187aea67eeaf/html5/thumbnails/17.jpg)
Now how do we paint a Panel?We rely on the draw* methods of the Swing
Lets look at one here:
Unfortunately this is pretty obnoxious compared to our geometry objects, so lets look at a trick to make our lives easier through examples!!
![Page 18: GEOG178/258 Week7 - mikejohnson51.github.io · Week7: Polygons, GUIs, draw** mike johnson. Polygons: *Surface Interface *Inherits from Triangle. If we use the extends keyword We are](https://reader034.vdocuments.net/reader034/viewer/2022052019/6032a5c8c492187aea67eeaf/html5/thumbnails/18.jpg)
Example 2
Example 3
Example 1
Remember we saw this in our points!!