cs 110 -- October 5 -- Review Session
Java, HTML and the WEB
- Java is a programming language
- good general purpose but gained popularity for being able to
write program that could run on oher people's computers
- such programs sit inside HTML (hyper text markup language)
pages accessable via URL(uniform resource locators) and are
called applets
- HTML pages consist of text, images, and applets with formatting
by TAGS.
- <H1> <applet> <BODY> <img>
- An <applet> tag tells the browser to run a program (a
java applet) within the browser
- <body> <applet code=MyCody.class width=400
height=500></applet></body>
- code, height, width mean!!
- Java is Object Oriented programming
- class definition { everything inside }
- idea is that you can use an object unchanged or modify it to
suit your needs while easily using those parts that you do nt want to
change
- Java -- object is called class
- classes have methods and class variables
- classes start with a definition line
- public class ClassName extends Applet implements
ActionListener, AdjustmentListener
- methods start with a definition line
- public void methodName(param list)
- names are always at your choice in definition line
- methods are small subprograms
- methods may have their own internal variables
- predifined methods that you want to change the action of
- overwrite
- e.g., paint, init, adjustmentValueChanged, actionPerformed
- new methods
- you choose everything
- params in "call" match up by position
- public void a(int a, int b, int c) { }
- a(10, 20, 30);
- class variables have only a definiton line
- private int variableName = 14;
- =14 is optional
- public/private/nothing in definition lines
- describes who can access
- public -- anyone can -- classes are almost always public
- private -- no one outside the class can acceess --
classVariables are usually private but may be public or nothing
- nothing -- somewhere in between public and private
- int and float data types
- int x = 5;
- x = x / 3;
- float y=5.0f;
- y = y / 3;
- Writing programs to be run inside of browsers
- simple public class MyClass extends Applet
- by "extending" Applet you mean that the program is intended
to be run inside a browser
- paint method
- controls what will appear in applet
- g.drawOval, g.fillOval, g.drawLine, g.drawString, g.drawRect,
g.fillRect, g.drawArc, g.fillArc, g.setBackground
- Widgets
- init method
- layout managers
- widgets can talk but must also tell program to listen.
- Scrollbar -- addAdjustmentListener, implements
AdjustmentListener, public void adjustmentValueChanged(AdjustmentEvent
ae)
- Scrollbar s; s.getValue();
- Button, TextField -- addActionListener,
implementsActionListener, public void actionPerformed(ActionEvent ae)
- TextField tt; tt.getText();
- Label -- like drawString -- label l; l.setText();
- boolean variables
- like info or float, but can only be "true" or "false"
- boolean goingUp = true;
- relational operators: >, <, <=, <=, ==
- combination operators: &&, ||
- if-then-else
- if (condition) { then stuff } [else { else stuff }]
- loops
- while (condition) {repeat until condition false }
- for (int i=0; i<5; i++) { do 5 times }