| public void setSize(int width,int height) - used to set the width and height in pixels of the Component public void setBackground(Color c) - used to set the background color of the Component public void setVisible(boolean b) - used to make the Component visible or invisible public void setLocation(int x,int y) - used to set the Location of the upper left-hand corner of the Component public Graphics getGraphics() - used to create a Graphics object associated with that Component public void paint(Graphics g) - used to draw Graphics on a Panel or Applet public void update(Graphics g) - used to clear the drawing area before making a call to paint public void repaint() - used to make a call to update as soon as the controlling environment (browser/appletviewer) can |
| public Component add(Component comp) - used to add a Component to a Container public void setLayout(LayoutManager mgr) - used to set the Layout of the Container |
| Interface | Methods |
| ActionListener | public abstract void actionPerformed(ActionEvent e) |
| ItemListener | public abstract void itemStateChanged(ItemEvent e) |
| MouseListener | public abstract void mouseClicked(MouseEvent e) public abstract void mousePressed(MouseEvent e) public abstract void mouseReleased(MouseEvent e) public abstract void mouseEntered(MouseEvent e) public abstract void mouseExited(MouseEvent e) |
| WindowListener | public abstract void windowActivated(WindowEvent e) public abstract void windowClosed(WindowEvent e) public abstract void windowClosing(WindowEvent e) public abstract void windowDeactivated(WindowEvent e) public abstract void windowDeiconified(WindowEvent e) public abstract void windowIconified(WindowEvent e) public abstract void windowOpened(WindowEvent e) |
| TextListener | public abstract void textValueChanged(TextEvent e) |
| Component | Event Generated |
| Button | ActionEvent |
| Checkbox | ItemEvent |
| Component | Code added |
| Button | addActionListener(ActionListener l) |
| Checkbox | addItemListener(ItemListener l) |
| <applet code=MyApplet width=w height=h> </applet> |
| public abstract void clearRect(int x,int y,int width,int height) clears a rectangular area whose upper left-hand coordinate is (x,y) with the specified width and height public abstract void drawLine(int xl,int yl,int x2,int y2) draws a line from (x1,y1) to (x2,y2) public abstract void drawOval(int x,int y,int width,int length) draws an oval whose bounding box is a rectangle whose upper left-hand corner is (x,y) with the specified width and height public void drawRect(int x,int y,int width,int height) draws a rectangle whose upper left-hand coordinate is (x,y) with specified width and height public abstract void drawString(String str,int x,int y) draws a string on the Panel or Applet at the coordinates (x,y) public abstract void fillOval(int x,int y,int width,int height) draws an oval like drawOval does but fills it with the drawing color public abstract void fillRect(int x,int y,int width,int height) draws a rectangle like drawRect does but fills it with the drawing color public void drawPolygon(int xpoints[],int ypoints[],int points) draws a polygon on the Panel or Applet whose coordinates are specified in the arrays xpoints and ypoints and the number of points in the polygon specified by points public void fillPolygon(int xpoints[],int ypoints[],int points) draws a polygon like drawPolygon does but fills it with the drawing color public abstract void setColor(Color c) sets the color to use for drawing |
push - place an element on to the stack.The interface for the Stack class is the following.
pop - take an element off the top of the stack.
peek - examine the element on the top of the stack without taking it.
empty - determine whether or not the stack is empty.
search - search for the position of a particular element of the stack.
public class Stack extends Vector {
public Stack();
public boolean empty();
public Object peek();
public Object pop();
public Object push(Object item);
public int search(Object o);
}
This class is found in the java.util package.
Vector() - creates an empty vector with initial capacity 10.
Vector(int cap) - creates an empty vector with initial capacity cap.
Vector(int cap,int grow) - creates an empty vector with initial capacity
cap and growth factor grow.
Some methods available to us in the Vector class are:
class Node {
private Object datum;
private Node link;
public Node(Object item,Node pointer) {
datum = item;
link = pointer;
}
}
public void insert(Object datum) {
if (head == null) {
head = new Node(datum,head);
tail = head;
} else {
temporary = new Node(datum,temporary);
tail.link = temporary;
tail = temporary;
temporary = null;
}
}
Notice here that this implementation of the insert method is for a queue.
The important thing to keep in mind when inserting a node into a linked
list is that when we locate the position to place the new node we
public boolean delete(Object scrap) {
Node previous = head;
for (Node current = head;current != null;current = current.link) {
if (current.datum.equals(scrap) && previous == current) {
head = current.link;
if (head == null)
tail = null;
nodeCount--;
return true;
} else if (current.datum.equals(scrap) && current.link != null)) {
previous.link = current.link;
nodeCount--;
return true;
} else if (current.datum.equals(scrap) && (current.link == null)) {
tail = previous;
previous.link = null;
nodeCount--;
return(true);
}
previous = current;
return false;
}
public void traverse() {
for (Node start = head;start != null;start = start.link)
System.out.println(start.datum);
}
public int factorial(int num) {
if (num == 1)
return(1);
else
return(num*factorial(num-1));
}
public int fibonacci(int num) {
if ((num==0) || (num==1))
return(1);
else
return(fibonacci(num-1) + fibonacci(num-2));
}
public int power(int exp) {
if (exp==1)
return(number);
else
return(number*power(exp-1));
}
public void writeBackwards(String s,int index) {
if (index>=0) {
System.out.println(s.charAt(index));
writeBackwards(s,index-1);
}
}
| Big O Class | Another Name | Shape of Graph | Example | Growth with double input size |
| O(1) | Constant Complexity | Horizontal Line | Add first two elements in an array | None! No growth |
| O(log N) | Logarithmic Complexity | Gentle curve up from left to right | Binary Search | Up by 1 - very slow growth! |
| O(N) | Linear Complexity | Non-horizontal line | Linear Search | Doubles |
| O(N log N) | None | Like a very flat parabola | Quick Sort | A little more than doubles |
| O(N2) | Quadratic Complexity | Parabola | Bubble Sort | Quadruples |