Java is object-oriented
Java has several standard libraries
Java Application Programmer's Interface (API) Documentation
Compiling and running your first Java applet
Your first look at a different Applet!
Your last look before creating a different Applet!
Variables (objects) declared via:
Class varname = new Constructor;
Button pressme = new Button ("Press here");
Java has if and if...else just like JavaScript
Even more JAVA programming basics...
Yet even more JAVA programming basics...
Still Expressing and operating...
Characters
In Java, array of characters is NOT a character string!
char [] name = {'E','l','w','o','o','d'};
CANNOT!
add(new Label(name));
String class in java.lang
Constructors
init ()
called only when applet first created
start ()
called after init and whenever applet is stopped and re-started
paint (Graphics g)
called after init and start and whenever screen needs to be redrawn
The HTML file can supply one or more parameters to the Applet
HTML...
<PARAM NAME="frog" VALUE="ribbet">
Java...
String getParameter (String);
getParameter ("frog");
returns the string "ribbet"
HTML...
<PARAM NAME="buttonwords" VALUE="Press here">
Java...
Button pushy = new Button (getParameter ("buttonwords"));
And with the use of JavaScript these parameters can even be dynamic!
Applets can contain Panels
All components that can contain other components have a LayoutManager
FlowLayout
default
arranges components in rows left-to-right top-to-bottom
each component is its natural size
Each row is centered
Five pixels between components and between rows
setLayout(new FlowLayout());
setLayout(new FlowLayout(int alignment);
alignment may be FlowLayout.LEFT, FlowLayout.RIGHT, or
FlowLayout.CENTER (default)
setLayout(new FlowLayout(int alignment, int hGap, int vGap);
BorderLayout
divides window into North, South, East, West, Center sections
North, South -- component resized to full window width
East, West -- component resized to full window height
Center -- component resized to take remaining space
setLayout(new BorderLayout());
setLayout(new BorderLayout(int hGap, int vGap));
gap size defaults are zero
add(section, component);
add("South", balButton);
GridLayout
divides window into equal-sized rectangles of rows and columns
arranges components in rectangles left-to-right top-to-bottom
components resized to fit into rectangles
setLayout(new GridLayout(int rows, int cols));
Introduction to Buttons, Layout Managers, and Action Events
All Kinds of AWTful things going on here...
This document was last modified