Download GUI Topics - Faculty Pages

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
CIS 111 - Basic GUI Topics
Applets and Drawing Basic Shapes (2.10 – 2.11)
2.10 – Applets
● Java applets are Java programs that are meant to be run within a web browser.
● Java applets can be run as a stand alone application using Sun's appletviewer.
● Bytecode is downloaded and run by the web browser or appletviewer.
● Applets have no “main” method, but we can think of the “paint” method as being a
required component to make our program run. The paint method runs when the applet is
first loaded or anytime the applet needs to be redrawn to the screen.
● All applets extend or inherit from the java Applet class (be sure to import
java.applet.Applet)
● Applets are placed into HTML pages using the <applet> tag.
2.11 – Drawing Shapes
● We can get basic graphical methods from the java.awt class (drawing basic shapes).
● Graphical components are placed on the screen using a coordinate system where the
upper left most corner is 0,0.
Lab Item
● p. 125, exercise 2.21. Your picture doesn't need to be as detailed as the exercise states.
Drawing Using Conditionals & Loops (3.10)
1.
2.
We can use loops and conditionals to help us draw graphics. A good example is found on
the web. If you are drawing a large table of information you may want to alternate the
color of each row using an if statement and the modulus operator. You could then make
odd rows one color and even rows another.
We can also imitate some of the screen savers you have seen where shapes are randomly
drawn all over the screen in random colors. A sample of this is provided on page 191 of
the book.
Applet Methods & Graphical Objects (4.6 – 4.7)
Applet Methods – 4.6
● The paint method helps us to draw things to the screen in an applet but there are other
methods that help us control the actual applet.
● The init method is called right after the applet is loaded into the browser and can be used
to set up the applet by initializing variables and defining other aspects of the program's
environment.
● The start and stop methods are self explanatory. The start method is called after the init
method.
Graphical Objects – 4.7
● If we were to actually write Space Invaders we would probably define each alien as an
object so we could use methods to manipulate them.
● Pages 256-260 give us an idea of how we might approach this.