first commit
This commit is contained in:
BIN
Semester 1/Programming 1/Java/Chapter01/Figures/Canvas$1.class
Normal file
BIN
Semester 1/Programming 1/Java/Chapter01/Figures/Canvas$1.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Semester 1/Programming 1/Java/Chapter01/Figures/Canvas.class
Normal file
BIN
Semester 1/Programming 1/Java/Chapter01/Figures/Canvas.class
Normal file
Binary file not shown.
26
Semester 1/Programming 1/Java/Chapter01/Figures/Canvas.ctxt
Normal file
26
Semester 1/Programming 1/Java/Chapter01/Figures/Canvas.ctxt
Normal file
@@ -0,0 +1,26 @@
|
||||
#BlueJ class context
|
||||
comment0.target=Canvas\ getCanvas()
|
||||
comment0.text=\nFactory\ method\ to\ get\ the\ canvas\ singleton\ object.\n\n
|
||||
comment1.params=title\ width\ height\ bgColour
|
||||
comment1.target=Canvas(String,\ int,\ int,\ Color)
|
||||
comment1.text=\nCreate\ a\ Canvas.\n@param\ title\ \ title\ to\ appear\ in\ Canvas\ Frame\n@param\ width\ \ the\ desired\ width\ for\ the\ canvas\n@param\ height\ \ the\ desired\ height\ for\ the\ canvas\n@param\ bgClour\ \ the\ desired\ background\ colour\ of\ the\ canvas\n\n
|
||||
comment2.params=visible
|
||||
comment2.target=void\ setVisible(boolean)
|
||||
comment2.text=\nSet\ the\ canvas\ visibility\ and\ brings\ canvas\ to\ the\ front\ of\ screen\nwhen\ made\ visible.\ This\ method\ can\ also\ be\ used\ to\ bring\ an\ already\nvisible\ canvas\ to\ the\ front\ of\ other\ windows.\n@param\ visible\ \ boolean\ value\ representing\ the\ desired\ visibility\ of\nthe\ canvas\ (true\ or\ false)\ \n\n
|
||||
comment3.params=referenceObject\ color\ shape
|
||||
comment3.target=void\ draw(Object,\ String,\ Shape)
|
||||
comment3.text=\nDraw\ a\ given\ shape\ onto\ the\ canvas.\n@param\ \ referenceObject\ \ an\ object\ to\ define\ identity\ for\ this\ shape\n@param\ \ color\ \ \ \ \ \ \ \ \ \ \ \ the\ color\ of\ the\ shape\n@param\ \ shape\ \ \ \ \ \ \ \ \ \ \ \ the\ shape\ object\ to\ be\ drawn\ on\ the\ canvas\n\n
|
||||
comment4.params=referenceObject
|
||||
comment4.target=void\ erase(Object)
|
||||
comment4.text=\nErase\ a\ given\ shape's\ from\ the\ screen.\n@param\ \ referenceObject\ \ the\ shape\ object\ to\ be\ erased\ \n\n
|
||||
comment5.params=colorString
|
||||
comment5.target=void\ setForegroundColor(String)
|
||||
comment5.text=\nSet\ the\ foreground\ colour\ of\ the\ Canvas.\n@param\ \ newColour\ \ \ the\ new\ colour\ for\ the\ foreground\ of\ the\ Canvas\ \n\n
|
||||
comment6.params=milliseconds
|
||||
comment6.target=void\ wait(int)
|
||||
comment6.text=\nWait\ for\ a\ specified\ number\ of\ milliseconds\ before\ finishing.\nThis\ provides\ an\ easy\ way\ to\ specify\ a\ small\ delay\ which\ can\ be\nused\ when\ producing\ animations.\n@param\ \ milliseconds\ \ the\ number\ \n\n
|
||||
comment7.target=void\ redraw()
|
||||
comment7.text=\nRedraw\ ell\ shapes\ currently\ on\ the\ Canvas.\n\n
|
||||
comment8.target=void\ erase()
|
||||
comment8.text=\nErase\ the\ whole\ canvas.\ (Does\ not\ repaint.)\n\n
|
||||
numComments=9
|
221
Semester 1/Programming 1/Java/Chapter01/Figures/Canvas.java
Normal file
221
Semester 1/Programming 1/Java/Chapter01/Figures/Canvas.java
Normal file
@@ -0,0 +1,221 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Canvas is a class to allow for simple graphical drawing on a canvas.
|
||||
* This is a modification of the general purpose Canvas, specially made for
|
||||
* the BlueJ "shapes" example.
|
||||
*
|
||||
* @author: Bruce Quig
|
||||
* @author: Michael Kolling (mik)
|
||||
*
|
||||
* @version: 1.6 (shapes)
|
||||
*/
|
||||
public class Canvas
|
||||
{
|
||||
// Note: The implementation of this class (specifically the handling of
|
||||
// shape identity and colors) is slightly more complex than necessary. This
|
||||
// is done on purpose to keep the interface and instance fields of the
|
||||
// shape objects in this project clean and simple for educational purposes.
|
||||
|
||||
private static Canvas canvasSingleton;
|
||||
|
||||
/**
|
||||
* Factory method to get the canvas singleton object.
|
||||
*/
|
||||
public static Canvas getCanvas()
|
||||
{
|
||||
if(canvasSingleton == null) {
|
||||
canvasSingleton = new Canvas("BlueJ Shapes Demo", 300, 300,
|
||||
Color.white);
|
||||
}
|
||||
canvasSingleton.setVisible(true);
|
||||
return canvasSingleton;
|
||||
}
|
||||
|
||||
// ----- instance part -----
|
||||
|
||||
private JFrame frame;
|
||||
private CanvasPane canvas;
|
||||
private Graphics2D graphic;
|
||||
private Color backgroundColour;
|
||||
private Image canvasImage;
|
||||
private List objects;
|
||||
private HashMap shapes;
|
||||
|
||||
/**
|
||||
* Create a Canvas.
|
||||
* @param title title to appear in Canvas Frame
|
||||
* @param width the desired width for the canvas
|
||||
* @param height the desired height for the canvas
|
||||
* @param bgClour the desired background colour of the canvas
|
||||
*/
|
||||
private Canvas(String title, int width, int height, Color bgColour)
|
||||
{
|
||||
frame = new JFrame();
|
||||
canvas = new CanvasPane();
|
||||
frame.setContentPane(canvas);
|
||||
frame.setTitle(title);
|
||||
canvas.setPreferredSize(new Dimension(width, height));
|
||||
backgroundColour = bgColour;
|
||||
frame.pack();
|
||||
objects = new ArrayList();
|
||||
shapes = new HashMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the canvas visibility and brings canvas to the front of screen
|
||||
* when made visible. This method can also be used to bring an already
|
||||
* visible canvas to the front of other windows.
|
||||
* @param visible boolean value representing the desired visibility of
|
||||
* the canvas (true or false)
|
||||
*/
|
||||
public void setVisible(boolean visible)
|
||||
{
|
||||
if(graphic == null) {
|
||||
// first time: instantiate the offscreen image and fill it with
|
||||
// the background colour
|
||||
Dimension size = canvas.getSize();
|
||||
canvasImage = canvas.createImage(size.width, size.height);
|
||||
graphic = (Graphics2D)canvasImage.getGraphics();
|
||||
graphic.setColor(backgroundColour);
|
||||
graphic.fillRect(0, 0, size.width, size.height);
|
||||
graphic.setColor(Color.black);
|
||||
}
|
||||
frame.setVisible(visible);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a given shape onto the canvas.
|
||||
* @param referenceObject an object to define identity for this shape
|
||||
* @param color the color of the shape
|
||||
* @param shape the shape object to be drawn on the canvas
|
||||
*/
|
||||
// Note: this is a slightly backwards way of maintaining the shape
|
||||
// objects. It is carefully designed to keep the visible shape interfaces
|
||||
// in this project clean and simple for educational purposes.
|
||||
public void draw(Object referenceObject, String color, Shape shape)
|
||||
{
|
||||
objects.remove(referenceObject); // just in case it was already there
|
||||
objects.add(referenceObject); // add at the end
|
||||
shapes.put(referenceObject, new ShapeDescription(shape, color));
|
||||
redraw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Erase a given shape's from the screen.
|
||||
* @param referenceObject the shape object to be erased
|
||||
*/
|
||||
public void erase(Object referenceObject)
|
||||
{
|
||||
objects.remove(referenceObject); // just in case it was already there
|
||||
shapes.remove(referenceObject);
|
||||
redraw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the foreground colour of the Canvas.
|
||||
* @param newColour the new colour for the foreground of the Canvas
|
||||
*/
|
||||
public void setForegroundColor(String colorString)
|
||||
{
|
||||
if(colorString.equals("red"))
|
||||
graphic.setColor(Color.red);
|
||||
else if(colorString.equals("black"))
|
||||
graphic.setColor(Color.black);
|
||||
else if(colorString.equals("blue"))
|
||||
graphic.setColor(Color.blue);
|
||||
else if(colorString.equals("yellow"))
|
||||
graphic.setColor(Color.yellow);
|
||||
else if(colorString.equals("green"))
|
||||
graphic.setColor(Color.green);
|
||||
else if(colorString.equals("magenta"))
|
||||
graphic.setColor(Color.magenta);
|
||||
else if(colorString.equals("white"))
|
||||
graphic.setColor(Color.white);
|
||||
else
|
||||
graphic.setColor(Color.black);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for a specified number of milliseconds before finishing.
|
||||
* This provides an easy way to specify a small delay which can be
|
||||
* used when producing animations.
|
||||
* @param milliseconds the number
|
||||
*/
|
||||
public void wait(int milliseconds)
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(milliseconds);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// ignoring exception at the moment
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Redraw ell shapes currently on the Canvas.
|
||||
*/
|
||||
private void redraw()
|
||||
{
|
||||
erase();
|
||||
for(Iterator i=objects.iterator(); i.hasNext(); ) {
|
||||
((ShapeDescription)shapes.get(i.next())).draw(graphic);
|
||||
}
|
||||
canvas.repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Erase the whole canvas. (Does not repaint.)
|
||||
*/
|
||||
private void erase()
|
||||
{
|
||||
Color original = graphic.getColor();
|
||||
graphic.setColor(backgroundColour);
|
||||
Dimension size = canvas.getSize();
|
||||
graphic.fill(new Rectangle(0, 0, size.width, size.height));
|
||||
graphic.setColor(original);
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************
|
||||
* Inner class CanvasPane - the actual canvas component contained in the
|
||||
* Canvas frame. This is essentially a JPanel with added capability to
|
||||
* refresh the image drawn on it.
|
||||
*/
|
||||
private class CanvasPane extends JPanel
|
||||
{
|
||||
public void paint(Graphics g)
|
||||
{
|
||||
g.drawImage(canvasImage, 0, 0, null);
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Inner class CanvasPane - the actual canvas component contained in the
|
||||
* Canvas frame. This is essentially a JPanel with added capability to
|
||||
* refresh the image drawn on it.
|
||||
*/
|
||||
private class ShapeDescription
|
||||
{
|
||||
private Shape shape;
|
||||
private String colorString;
|
||||
|
||||
public ShapeDescription(Shape shape, String color)
|
||||
{
|
||||
this.shape = shape;
|
||||
colorString = color;
|
||||
}
|
||||
|
||||
public void draw(Graphics2D graphic)
|
||||
{
|
||||
setForegroundColor(colorString);
|
||||
graphic.fill(shape);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
BIN
Semester 1/Programming 1/Java/Chapter01/Figures/Circle.class
Normal file
BIN
Semester 1/Programming 1/Java/Chapter01/Figures/Circle.class
Normal file
Binary file not shown.
53
Semester 1/Programming 1/Java/Chapter01/Figures/Circle.ctxt
Normal file
53
Semester 1/Programming 1/Java/Chapter01/Figures/Circle.ctxt
Normal file
@@ -0,0 +1,53 @@
|
||||
#BlueJ class context
|
||||
comment0.params=
|
||||
comment0.target=Circle()
|
||||
comment0.text=\n\ Create\ a\ new\ circle\ at\ default\ position\ with\ default\ color.\n
|
||||
comment1.params=x\ y
|
||||
comment1.target=Circle(int,\ int)
|
||||
comment10.params=distance
|
||||
comment10.target=void\ moveHorizontal(int)
|
||||
comment10.text=\n\ Move\ the\ circle\ horizontally\ by\ 'distance'\ pixels.\n
|
||||
comment11.params=distance
|
||||
comment11.target=void\ moveVertical(int)
|
||||
comment11.text=\n\ Move\ the\ circle\ vertically\ by\ 'distance'\ pixels.\n
|
||||
comment12.params=distance
|
||||
comment12.target=void\ slowMoveHorizontal(int)
|
||||
comment12.text=\n\ Slowly\ move\ the\ circle\ horizontally\ by\ 'distance'\ pixels.\n
|
||||
comment13.params=distance
|
||||
comment13.target=void\ slowMoveVertical(int)
|
||||
comment13.text=\n\ Slowly\ move\ the\ circle\ vertically\ by\ 'distance'\ pixels.\n
|
||||
comment14.params=newDiameter
|
||||
comment14.target=void\ changeSize(int)
|
||||
comment14.text=\n\ Change\ the\ size\ to\ the\ new\ size\ (in\ pixels).\ Size\ must\ be\ >\=\ 0.\n
|
||||
comment15.params=newColor
|
||||
comment15.target=void\ changeColor(java.lang.String)
|
||||
comment15.text=\n\ Change\ the\ color.\ Valid\ colors\ are\ "red",\ "yellow",\ "blue",\ "green",\n\ "magenta"\ and\ "black".\n
|
||||
comment16.params=
|
||||
comment16.target=void\ draw()
|
||||
comment16.text=\n\ Draw\ the\ circle\ with\ current\ specifications\ on\ screen.\n
|
||||
comment17.params=
|
||||
comment17.target=void\ erase()
|
||||
comment17.text=\n\ Erase\ the\ circle\ on\ screen.\n
|
||||
comment2.params=x\ y\ col
|
||||
comment2.target=Circle(int,\ int,\ java.lang.String)
|
||||
comment3.params=x\ y\ col\ d
|
||||
comment3.target=Circle(int,\ int,\ java.lang.String,\ int)
|
||||
comment4.params=
|
||||
comment4.target=void\ makeVisible()
|
||||
comment4.text=\n\ Make\ this\ circle\ visible.\ If\ it\ was\ already\ visible,\ do\ nothing.\n
|
||||
comment5.params=
|
||||
comment5.target=void\ makeInvisible()
|
||||
comment5.text=\n\ Make\ this\ circle\ invisible.\ If\ it\ was\ already\ invisible,\ do\ nothing.\n
|
||||
comment6.params=
|
||||
comment6.target=void\ moveRight()
|
||||
comment6.text=\n\ Move\ the\ circle\ a\ few\ pixels\ to\ the\ right.\n
|
||||
comment7.params=
|
||||
comment7.target=void\ moveLeft()
|
||||
comment7.text=\n\ Move\ the\ circle\ a\ few\ pixels\ to\ the\ left.\n
|
||||
comment8.params=
|
||||
comment8.target=void\ moveUp()
|
||||
comment8.text=\n\ Move\ the\ circle\ a\ few\ pixels\ up.\n
|
||||
comment9.params=
|
||||
comment9.target=void\ moveDown()
|
||||
comment9.text=\n\ Move\ the\ circle\ a\ few\ pixels\ down.\n
|
||||
numComments=18
|
211
Semester 1/Programming 1/Java/Chapter01/Figures/Circle.java
Normal file
211
Semester 1/Programming 1/Java/Chapter01/Figures/Circle.java
Normal file
@@ -0,0 +1,211 @@
|
||||
import java.awt.*;
|
||||
import java.awt.geom.*;
|
||||
|
||||
/**
|
||||
* A circle that can be manipulated and that draws itself on a canvas.
|
||||
*
|
||||
* @author Michael Kolling and David J. Barnes
|
||||
* @version 1.0 (15 July 2000)
|
||||
*/
|
||||
|
||||
public class Circle
|
||||
{
|
||||
private int diameter;
|
||||
private int xPosition;
|
||||
private int yPosition;
|
||||
private String color;
|
||||
private boolean isVisible;
|
||||
|
||||
/**
|
||||
* Create a new circle at default position with default color.
|
||||
*/
|
||||
public Circle()
|
||||
{
|
||||
diameter = 30;
|
||||
xPosition = 20;
|
||||
yPosition = 60;
|
||||
color = "blue";
|
||||
isVisible = false;
|
||||
}
|
||||
|
||||
public Circle(int x, int y){
|
||||
diameter = 30;
|
||||
xPosition = x;
|
||||
yPosition = y;
|
||||
color = "blue";
|
||||
}
|
||||
|
||||
public Circle(int x, int y, String col){
|
||||
this(x,y,col,20);
|
||||
}
|
||||
public Circle(int x, int y, String col, int d){
|
||||
diameter = d;
|
||||
xPosition = x;
|
||||
yPosition = y;
|
||||
color = "blue";
|
||||
makeVisible();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make this circle visible. If it was already visible, do nothing.
|
||||
*/
|
||||
public void makeVisible()
|
||||
{
|
||||
isVisible = true;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make this circle invisible. If it was already invisible, do nothing.
|
||||
*/
|
||||
public void makeInvisible()
|
||||
{
|
||||
erase();
|
||||
isVisible = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the circle a few pixels to the right.
|
||||
*/
|
||||
public void moveRight()
|
||||
{
|
||||
moveHorizontal(20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the circle a few pixels to the left.
|
||||
*/
|
||||
public void moveLeft()
|
||||
{
|
||||
moveHorizontal(-20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the circle a few pixels up.
|
||||
*/
|
||||
public void moveUp()
|
||||
{
|
||||
moveVertical(-20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the circle a few pixels down.
|
||||
*/
|
||||
public void moveDown()
|
||||
{
|
||||
moveVertical(20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the circle horizontally by 'distance' pixels.
|
||||
*/
|
||||
public void moveHorizontal(int distance)
|
||||
{
|
||||
erase();
|
||||
xPosition += distance;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the circle vertically by 'distance' pixels.
|
||||
*/
|
||||
public void moveVertical(int distance)
|
||||
{
|
||||
erase();
|
||||
yPosition += distance;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Slowly move the circle horizontally by 'distance' pixels.
|
||||
*/
|
||||
public void slowMoveHorizontal(int distance)
|
||||
{
|
||||
int delta;
|
||||
|
||||
if(distance < 0)
|
||||
{
|
||||
delta = -1;
|
||||
distance = -distance;
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = 1;
|
||||
}
|
||||
|
||||
for(int i = 0; i < distance; i++)
|
||||
{
|
||||
xPosition += delta;
|
||||
draw();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Slowly move the circle vertically by 'distance' pixels.
|
||||
*/
|
||||
public void slowMoveVertical(int distance)
|
||||
{
|
||||
int delta;
|
||||
|
||||
if(distance < 0)
|
||||
{
|
||||
delta = -1;
|
||||
distance = -distance;
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = 1;
|
||||
}
|
||||
|
||||
for(int i = 0; i < distance; i++)
|
||||
{
|
||||
yPosition += delta;
|
||||
draw();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the size to the new size (in pixels). Size must be >= 0.
|
||||
*/
|
||||
public void changeSize(int newDiameter)
|
||||
{
|
||||
erase();
|
||||
diameter = newDiameter;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the color. Valid colors are "red", "yellow", "blue", "green",
|
||||
* "magenta" and "black".
|
||||
*/
|
||||
public void changeColor(String newColor)
|
||||
{
|
||||
color = newColor;
|
||||
draw();
|
||||
}
|
||||
|
||||
/*
|
||||
* Draw the circle with current specifications on screen.
|
||||
*/
|
||||
private void draw()
|
||||
{
|
||||
if(isVisible) {
|
||||
Canvas canvas = Canvas.getCanvas();
|
||||
canvas.draw(this, color, new Ellipse2D.Double(xPosition, yPosition,
|
||||
diameter, diameter));
|
||||
canvas.wait(10);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Erase the circle on screen.
|
||||
*/
|
||||
private void erase()
|
||||
{
|
||||
if(isVisible) {
|
||||
Canvas canvas = Canvas.getCanvas();
|
||||
canvas.erase(this);
|
||||
}
|
||||
}
|
||||
}
|
44
Semester 1/Programming 1/Java/Chapter01/Figures/README.TXT
Normal file
44
Semester 1/Programming 1/Java/Chapter01/Figures/README.TXT
Normal file
@@ -0,0 +1,44 @@
|
||||
Project "shapes"
|
||||
Authors: Michael Kolling and David J. Barnes
|
||||
|
||||
This project is part of the material for the book
|
||||
|
||||
Objects First with Java - A Practical Introduction using BlueJ
|
||||
David J. Barnes and Michael Kolling
|
||||
Pearson Education, 2002
|
||||
|
||||
It is discussed in chapter 1.
|
||||
|
||||
This is a very simple project to demonstrate some characteristics of
|
||||
objects.
|
||||
|
||||
You can create various shapes, and you will see, if you do, that those
|
||||
shapes are drawn on screen (in a window that we call the "canvas").
|
||||
|
||||
You can then manipulate these objects: change their position, size and
|
||||
colour. Try it out: create a few different squares, triangles and circles.
|
||||
|
||||
This project is designed as a first example of object-oriented programming.
|
||||
It illustrates a number of concepts:
|
||||
|
||||
- a Java project (application) is a collection of classes
|
||||
- objects can be created from classes
|
||||
- from any one class, many objects may be created
|
||||
- objects have operations (methods)
|
||||
- operations can have parameters
|
||||
- parameters have types (at least String and int)
|
||||
- objects hold data (fields)
|
||||
- the operations and fields are common to all objects
|
||||
- the values stored in the fields can be different for each object
|
||||
|
||||
The project also demonstrates
|
||||
|
||||
- BlueJ object creation
|
||||
- interactive method invocation
|
||||
- parameter passing
|
||||
|
||||
A good second project to look at after this is "picture", which adds a class
|
||||
to those ones in this project. That class (named "Picture") uses the shapes
|
||||
to draw a picture. It can be used to experiment with coding.
|
||||
|
||||
Michael Kolling, July 2000
|
BIN
Semester 1/Programming 1/Java/Chapter01/Figures/Square.class
Normal file
BIN
Semester 1/Programming 1/Java/Chapter01/Figures/Square.class
Normal file
Binary file not shown.
47
Semester 1/Programming 1/Java/Chapter01/Figures/Square.ctxt
Normal file
47
Semester 1/Programming 1/Java/Chapter01/Figures/Square.ctxt
Normal file
@@ -0,0 +1,47 @@
|
||||
#BlueJ class context
|
||||
comment0.params=
|
||||
comment0.target=Square()
|
||||
comment0.text=\n\ Create\ a\ new\ square\ at\ default\ position\ with\ default\ color.\n
|
||||
comment1.params=
|
||||
comment1.target=void\ makeVisible()
|
||||
comment1.text=\n\ Make\ this\ square\ visible.\ If\ it\ was\ already\ visible,\ do\ nothing.\n
|
||||
comment10.params=distance
|
||||
comment10.target=void\ slowMoveVertical(int)
|
||||
comment10.text=\n\ Slowly\ move\ the\ square\ vertically\ by\ 'distance'\ pixels.\n
|
||||
comment11.params=newSize
|
||||
comment11.target=void\ changeSize(int)
|
||||
comment11.text=\n\ Change\ the\ size\ to\ the\ new\ size\ (in\ pixels).\ Size\ must\ be\ >\=\ 0.\n
|
||||
comment12.params=newColor
|
||||
comment12.target=void\ changeColor(java.lang.String)
|
||||
comment12.text=\n\ Change\ the\ color.\ Valid\ colors\ are\ "red",\ "yellow",\ "blue",\ "green",\n\ "magenta"\ and\ "black".\n
|
||||
comment13.params=
|
||||
comment13.target=void\ draw()
|
||||
comment13.text=\n\ Draw\ the\ square\ with\ current\ specifications\ on\ screen.\n
|
||||
comment14.params=
|
||||
comment14.target=void\ erase()
|
||||
comment14.text=\n\ Erase\ the\ square\ on\ screen.\n
|
||||
comment2.params=
|
||||
comment2.target=void\ makeInvisible()
|
||||
comment2.text=\n\ Make\ this\ square\ invisible.\ If\ it\ was\ already\ invisible,\ do\ nothing.\n
|
||||
comment3.params=
|
||||
comment3.target=void\ moveRight()
|
||||
comment3.text=\n\ Move\ the\ square\ a\ few\ pixels\ to\ the\ right.\n
|
||||
comment4.params=
|
||||
comment4.target=void\ moveLeft()
|
||||
comment4.text=\n\ Move\ the\ square\ a\ few\ pixels\ to\ the\ left.\n
|
||||
comment5.params=
|
||||
comment5.target=void\ moveUp()
|
||||
comment5.text=\n\ Move\ the\ square\ a\ few\ pixels\ up.\n
|
||||
comment6.params=
|
||||
comment6.target=void\ moveDown()
|
||||
comment6.text=\n\ Move\ the\ square\ a\ few\ pixels\ down.\n
|
||||
comment7.params=distance
|
||||
comment7.target=void\ moveHorizontal(int)
|
||||
comment7.text=\n\ Move\ the\ square\ horizontally\ by\ 'distance'\ pixels.\n
|
||||
comment8.params=distance
|
||||
comment8.target=void\ moveVertical(int)
|
||||
comment8.text=\n\ Move\ the\ square\ vertically\ by\ 'distance'\ pixels.\n
|
||||
comment9.params=distance
|
||||
comment9.target=void\ slowMoveHorizontal(int)
|
||||
comment9.text=\n\ Slowly\ move\ the\ square\ horizontally\ by\ 'distance'\ pixels.\n
|
||||
numComments=15
|
191
Semester 1/Programming 1/Java/Chapter01/Figures/Square.java
Normal file
191
Semester 1/Programming 1/Java/Chapter01/Figures/Square.java
Normal file
@@ -0,0 +1,191 @@
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* A square that can be manipulated and that draws itself on a canvas.
|
||||
*
|
||||
* @author Michael Kolling and David J. Barnes
|
||||
* @version 1.0 (15 July 2000)
|
||||
*/
|
||||
|
||||
public class Square
|
||||
{
|
||||
private int size;
|
||||
private int xPosition;
|
||||
private int yPosition;
|
||||
private String color;
|
||||
private boolean isVisible;
|
||||
|
||||
/**
|
||||
* Create a new square at default position with default color.
|
||||
*/
|
||||
public Square()
|
||||
{
|
||||
size = 30;
|
||||
xPosition = 60;
|
||||
yPosition = 50;
|
||||
color = "red";
|
||||
isVisible = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make this square visible. If it was already visible, do nothing.
|
||||
*/
|
||||
public void makeVisible()
|
||||
{
|
||||
isVisible = true;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make this square invisible. If it was already invisible, do nothing.
|
||||
*/
|
||||
public void makeInvisible()
|
||||
{
|
||||
erase();
|
||||
isVisible = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the square a few pixels to the right.
|
||||
*/
|
||||
public void moveRight()
|
||||
{
|
||||
moveHorizontal(20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the square a few pixels to the left.
|
||||
*/
|
||||
public void moveLeft()
|
||||
{
|
||||
moveHorizontal(-20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the square a few pixels up.
|
||||
*/
|
||||
public void moveUp()
|
||||
{
|
||||
moveVertical(-20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the square a few pixels down.
|
||||
*/
|
||||
public void moveDown()
|
||||
{
|
||||
moveVertical(20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the square horizontally by 'distance' pixels.
|
||||
*/
|
||||
public void moveHorizontal(int distance)
|
||||
{
|
||||
erase();
|
||||
xPosition += distance;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the square vertically by 'distance' pixels.
|
||||
*/
|
||||
public void moveVertical(int distance)
|
||||
{
|
||||
erase();
|
||||
yPosition += distance;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Slowly move the square horizontally by 'distance' pixels.
|
||||
*/
|
||||
public void slowMoveHorizontal(int distance)
|
||||
{
|
||||
int delta;
|
||||
|
||||
if(distance < 0)
|
||||
{
|
||||
delta = -1;
|
||||
distance = -distance;
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = 1;
|
||||
}
|
||||
|
||||
for(int i = 0; i < distance; i++)
|
||||
{
|
||||
xPosition += delta;
|
||||
draw();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Slowly move the square vertically by 'distance' pixels.
|
||||
*/
|
||||
public void slowMoveVertical(int distance)
|
||||
{
|
||||
int delta;
|
||||
|
||||
if(distance < 0)
|
||||
{
|
||||
delta = -1;
|
||||
distance = -distance;
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = 1;
|
||||
}
|
||||
|
||||
for(int i = 0; i < distance; i++)
|
||||
{
|
||||
yPosition += delta;
|
||||
draw();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the size to the new size (in pixels). Size must be >= 0.
|
||||
*/
|
||||
public void changeSize(int newSize)
|
||||
{
|
||||
erase();
|
||||
size = newSize;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the color. Valid colors are "red", "yellow", "blue", "green",
|
||||
* "magenta" and "black".
|
||||
*/
|
||||
public void changeColor(String newColor)
|
||||
{
|
||||
color = newColor;
|
||||
draw();
|
||||
}
|
||||
|
||||
/*
|
||||
* Draw the square with current specifications on screen.
|
||||
*/
|
||||
private void draw()
|
||||
{
|
||||
if(isVisible) {
|
||||
Canvas canvas = Canvas.getCanvas();
|
||||
canvas.draw(this, color,
|
||||
new Rectangle(xPosition, yPosition, size, size));
|
||||
canvas.wait(10);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Erase the square on screen.
|
||||
*/
|
||||
private void erase()
|
||||
{
|
||||
if(isVisible) {
|
||||
Canvas canvas = Canvas.getCanvas();
|
||||
canvas.erase(this);
|
||||
}
|
||||
}
|
||||
}
|
BIN
Semester 1/Programming 1/Java/Chapter01/Figures/Triangle.class
Normal file
BIN
Semester 1/Programming 1/Java/Chapter01/Figures/Triangle.class
Normal file
Binary file not shown.
@@ -0,0 +1,38 @@
|
||||
#BlueJ class context
|
||||
comment0.target=Triangle()
|
||||
comment0.text=\nCreate\ a\ new\ triangle\ at\ default\ position\ with\ default\ color.\n\n
|
||||
comment1.target=void\ makeVisible()
|
||||
comment1.text=\nMake\ this\ triangle\ visible.\ If\ it\ was\ already\ visible,\ do\ nothing.\n\n
|
||||
comment10.params=distance
|
||||
comment10.target=void\ slowMoveVertical(int)
|
||||
comment10.text=\nSlowly\ move\ the\ triangle\ vertically\ by\ 'distance'\ pixels.\n\n
|
||||
comment11.params=newHeight\ newWidth
|
||||
comment11.target=void\ changeSize(int,\ int)
|
||||
comment11.text=\nChange\ the\ size\ to\ the\ new\ size\ (in\ pixels).\ Size\ must\ be\ >\=\ 0.\n\n
|
||||
comment12.params=newColor
|
||||
comment12.target=void\ changeColor(String)
|
||||
comment12.text=\nChange\ the\ color.\ Valid\ colors\ are\ "red",\ "yellow",\ "blue",\ "green",\n"magenta"\ and\ "black".\n\n
|
||||
comment13.target=void\ draw()
|
||||
comment13.text=Draw\ the\ triangle\ with\ current\ specifications\ on\ screen.\n\n
|
||||
comment14.target=void\ erase()
|
||||
comment14.text=Erase\ the\ triangle\ on\ screen.\n\n
|
||||
comment2.target=void\ makeInvisible()
|
||||
comment2.text=\nMake\ this\ triangle\ invisible.\ If\ it\ was\ already\ invisible,\ do\ nothing.\n\n
|
||||
comment3.target=void\ moveRight()
|
||||
comment3.text=\nMove\ the\ triangle\ a\ few\ pixels\ to\ the\ right.\n\n
|
||||
comment4.target=void\ moveLeft()
|
||||
comment4.text=\nMove\ the\ triangle\ a\ few\ pixels\ to\ the\ left.\n\n
|
||||
comment5.target=void\ moveUp()
|
||||
comment5.text=\nMove\ the\ triangle\ a\ few\ pixels\ up.\n\n
|
||||
comment6.target=void\ moveDown()
|
||||
comment6.text=\nMove\ the\ triangle\ a\ few\ pixels\ down.\n\n
|
||||
comment7.params=distance
|
||||
comment7.target=void\ moveHorizontal(int)
|
||||
comment7.text=\nMove\ the\ triangle\ horizontally\ by\ 'distance'\ pixels.\n\n
|
||||
comment8.params=distance
|
||||
comment8.target=void\ moveVertical(int)
|
||||
comment8.text=\nMove\ the\ triangle\ vertically\ by\ 'distance'\ pixels.\n\n
|
||||
comment9.params=distance
|
||||
comment9.target=void\ slowMoveHorizontal(int)
|
||||
comment9.text=\nSlowly\ move\ the\ triangle\ horizontally\ by\ 'distance'\ pixels.\n\n
|
||||
numComments=15
|
195
Semester 1/Programming 1/Java/Chapter01/Figures/Triangle.java
Normal file
195
Semester 1/Programming 1/Java/Chapter01/Figures/Triangle.java
Normal file
@@ -0,0 +1,195 @@
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* A triangle that can be manipulated and that draws itself on a canvas.
|
||||
*
|
||||
* @author Michael Kolling and David J. Barnes
|
||||
* @version 1.0 (15 July 2000)
|
||||
*/
|
||||
|
||||
public class Triangle
|
||||
{
|
||||
private int height;
|
||||
private int width;
|
||||
private int xPosition;
|
||||
private int yPosition;
|
||||
private String color;
|
||||
private boolean isVisible;
|
||||
|
||||
/**
|
||||
* Create a new triangle at default position with default color.
|
||||
*/
|
||||
public Triangle()
|
||||
{
|
||||
height = 30;
|
||||
width = 40;
|
||||
xPosition = 50;
|
||||
yPosition = 15;
|
||||
color = "green";
|
||||
isVisible = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make this triangle visible. If it was already visible, do nothing.
|
||||
*/
|
||||
public void makeVisible()
|
||||
{
|
||||
isVisible = true;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make this triangle invisible. If it was already invisible, do nothing.
|
||||
*/
|
||||
public void makeInvisible()
|
||||
{
|
||||
erase();
|
||||
isVisible = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the triangle a few pixels to the right.
|
||||
*/
|
||||
public void moveRight()
|
||||
{
|
||||
moveHorizontal(20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the triangle a few pixels to the left.
|
||||
*/
|
||||
public void moveLeft()
|
||||
{
|
||||
moveHorizontal(-20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the triangle a few pixels up.
|
||||
*/
|
||||
public void moveUp()
|
||||
{
|
||||
moveVertical(-20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the triangle a few pixels down.
|
||||
*/
|
||||
public void moveDown()
|
||||
{
|
||||
moveVertical(20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the triangle horizontally by 'distance' pixels.
|
||||
*/
|
||||
public void moveHorizontal(int distance)
|
||||
{
|
||||
erase();
|
||||
xPosition += distance;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the triangle vertically by 'distance' pixels.
|
||||
*/
|
||||
public void moveVertical(int distance)
|
||||
{
|
||||
erase();
|
||||
yPosition += distance;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Slowly move the triangle horizontally by 'distance' pixels.
|
||||
*/
|
||||
public void slowMoveHorizontal(int distance)
|
||||
{
|
||||
int delta;
|
||||
|
||||
if(distance < 0)
|
||||
{
|
||||
delta = -1;
|
||||
distance = -distance;
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = 1;
|
||||
}
|
||||
|
||||
for(int i = 0; i < distance; i++)
|
||||
{
|
||||
xPosition += delta;
|
||||
draw();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Slowly move the triangle vertically by 'distance' pixels.
|
||||
*/
|
||||
public void slowMoveVertical(int distance)
|
||||
{
|
||||
int delta;
|
||||
|
||||
if(distance < 0)
|
||||
{
|
||||
delta = -1;
|
||||
distance = -distance;
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = 1;
|
||||
}
|
||||
|
||||
for(int i = 0; i < distance; i++)
|
||||
{
|
||||
yPosition += delta;
|
||||
draw();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the size to the new size (in pixels). Size must be >= 0.
|
||||
*/
|
||||
public void changeSize(int newHeight, int newWidth)
|
||||
{
|
||||
erase();
|
||||
height = newHeight;
|
||||
width = newWidth;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the color. Valid colors are "red", "yellow", "blue", "green",
|
||||
* "magenta" and "black".
|
||||
*/
|
||||
public void changeColor(String newColor)
|
||||
{
|
||||
color = newColor;
|
||||
draw();
|
||||
}
|
||||
|
||||
/*
|
||||
* Draw the triangle with current specifications on screen.
|
||||
*/
|
||||
private void draw()
|
||||
{
|
||||
if(isVisible) {
|
||||
Canvas canvas = Canvas.getCanvas();
|
||||
int[] xpoints = { xPosition, xPosition + (width/2), xPosition - (width/2) };
|
||||
int[] ypoints = { yPosition, yPosition + height, yPosition + height };
|
||||
canvas.draw(this, color, new Polygon(xpoints, ypoints, 3));
|
||||
canvas.wait(10);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Erase the triangle on screen.
|
||||
*/
|
||||
private void erase()
|
||||
{
|
||||
if(isVisible) {
|
||||
Canvas canvas = Canvas.getCanvas();
|
||||
canvas.erase(this);
|
||||
}
|
||||
}
|
||||
}
|
62
Semester 1/Programming 1/Java/Chapter01/Figures/bluej.pkg
Normal file
62
Semester 1/Programming 1/Java/Chapter01/Figures/bluej.pkg
Normal file
@@ -0,0 +1,62 @@
|
||||
#BlueJ package file
|
||||
dependency1.from=Triangle
|
||||
dependency1.to=Canvas
|
||||
dependency1.type=UsesDependency
|
||||
dependency2.from=Square
|
||||
dependency2.to=Canvas
|
||||
dependency2.type=UsesDependency
|
||||
dependency3.from=Circle
|
||||
dependency3.to=Canvas
|
||||
dependency3.type=UsesDependency
|
||||
objectbench.height=76
|
||||
objectbench.width=940
|
||||
package.editor.height=874
|
||||
package.editor.width=814
|
||||
package.editor.x=0
|
||||
package.editor.y=31
|
||||
package.numDependencies=3
|
||||
package.numTargets=4
|
||||
package.showExtends=true
|
||||
package.showUses=true
|
||||
project.charset=UTF-8
|
||||
target1.editor.height=867
|
||||
target1.editor.width=1100
|
||||
target1.editor.x=0
|
||||
target1.editor.y=31
|
||||
target1.height=40
|
||||
target1.name=Circle
|
||||
target1.naviview.expanded=true
|
||||
target1.showInterface=false
|
||||
target1.type=ClassTarget
|
||||
target1.typeParameters=
|
||||
target1.width=70
|
||||
target1.x=100
|
||||
target1.y=120
|
||||
target2.editor.height=521
|
||||
target2.editor.width=626
|
||||
target2.editor.x=0
|
||||
target2.editor.y=0
|
||||
target2.height=40
|
||||
target2.name=Canvas
|
||||
target2.showInterface=false
|
||||
target2.type=ClassTarget
|
||||
target2.typeParameters=
|
||||
target2.width=70
|
||||
target2.x=20
|
||||
target2.y=180
|
||||
target3.height=40
|
||||
target3.name=Triangle
|
||||
target3.showInterface=false
|
||||
target3.type=ClassTarget
|
||||
target3.typeParameters=
|
||||
target3.width=70
|
||||
target3.x=260
|
||||
target3.y=60
|
||||
target4.height=40
|
||||
target4.name=Square
|
||||
target4.showInterface=false
|
||||
target4.type=ClassTarget
|
||||
target4.typeParameters=
|
||||
target4.width=70
|
||||
target4.x=180
|
||||
target4.y=90
|
@@ -0,0 +1,62 @@
|
||||
#BlueJ package file
|
||||
dependency1.from=Triangle
|
||||
dependency1.to=Canvas
|
||||
dependency1.type=UsesDependency
|
||||
dependency2.from=Square
|
||||
dependency2.to=Canvas
|
||||
dependency2.type=UsesDependency
|
||||
dependency3.from=Circle
|
||||
dependency3.to=Canvas
|
||||
dependency3.type=UsesDependency
|
||||
objectbench.height=76
|
||||
objectbench.width=940
|
||||
package.editor.height=874
|
||||
package.editor.width=814
|
||||
package.editor.x=0
|
||||
package.editor.y=31
|
||||
package.numDependencies=3
|
||||
package.numTargets=4
|
||||
package.showExtends=true
|
||||
package.showUses=true
|
||||
project.charset=UTF-8
|
||||
target1.editor.height=867
|
||||
target1.editor.width=1100
|
||||
target1.editor.x=0
|
||||
target1.editor.y=31
|
||||
target1.height=40
|
||||
target1.name=Circle
|
||||
target1.naviview.expanded=true
|
||||
target1.showInterface=false
|
||||
target1.type=ClassTarget
|
||||
target1.typeParameters=
|
||||
target1.width=70
|
||||
target1.x=100
|
||||
target1.y=120
|
||||
target2.editor.height=521
|
||||
target2.editor.width=626
|
||||
target2.editor.x=0
|
||||
target2.editor.y=0
|
||||
target2.height=40
|
||||
target2.name=Canvas
|
||||
target2.showInterface=false
|
||||
target2.type=ClassTarget
|
||||
target2.typeParameters=
|
||||
target2.width=70
|
||||
target2.x=20
|
||||
target2.y=180
|
||||
target3.height=40
|
||||
target3.name=Triangle
|
||||
target3.showInterface=false
|
||||
target3.type=ClassTarget
|
||||
target3.typeParameters=
|
||||
target3.width=70
|
||||
target3.x=260
|
||||
target3.y=60
|
||||
target4.height=40
|
||||
target4.name=Square
|
||||
target4.showInterface=false
|
||||
target4.type=ClassTarget
|
||||
target4.typeParameters=
|
||||
target4.width=70
|
||||
target4.x=180
|
||||
target4.y=90
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,29 @@
|
||||
#BlueJ class context
|
||||
comment0.params=
|
||||
comment0.target=Canvas\ getCanvas()
|
||||
comment0.text=\n\ Factory\ method\ to\ get\ the\ canvas\ singleton\ object.\n
|
||||
comment1.params=title\ width\ height\ bgColor
|
||||
comment1.target=Canvas(java.lang.String,\ int,\ int,\ java.awt.Color)
|
||||
comment1.text=\n\ Create\ a\ Canvas.\n\ @param\ title\ \ \ \ title\ to\ appear\ in\ Canvas\ Frame\n\ @param\ width\ \ \ \ the\ desired\ width\ for\ the\ canvas\n\ @param\ height\ \ \ the\ desired\ height\ for\ the\ canvas\n\ @param\ bgColor\ the\ desired\ background\ color\ of\ the\ canvas\n
|
||||
comment2.params=visible
|
||||
comment2.target=void\ setVisible(boolean)
|
||||
comment2.text=\n\ Set\ the\ canvas\ visibility\ and\ brings\ canvas\ to\ the\ front\ of\ screen\n\ when\ made\ visible.\ This\ method\ can\ also\ be\ used\ to\ bring\ an\ already\n\ visible\ canvas\ to\ the\ front\ of\ other\ windows.\n\ @param\ visible\ \ boolean\ value\ representing\ the\ desired\ visibility\ of\n\ the\ canvas\ (true\ or\ false)\ \n
|
||||
comment3.params=referenceObject\ color\ shape
|
||||
comment3.target=void\ draw(java.lang.Object,\ java.lang.String,\ java.awt.Shape)
|
||||
comment3.text=\n\ Draw\ a\ given\ shape\ onto\ the\ canvas.\n\ @param\ \ referenceObject\ \ an\ object\ to\ define\ identity\ for\ this\ shape\n\ @param\ \ color\ \ \ \ \ \ \ \ \ \ \ \ the\ color\ of\ the\ shape\n\ @param\ \ shape\ \ \ \ \ \ \ \ \ \ \ \ the\ shape\ object\ to\ be\ drawn\ on\ the\ canvas\n
|
||||
comment4.params=referenceObject
|
||||
comment4.target=void\ erase(java.lang.Object)
|
||||
comment4.text=\n\ Erase\ a\ given\ shape's\ from\ the\ screen.\n\ @param\ \ referenceObject\ \ the\ shape\ object\ to\ be\ erased\ \n
|
||||
comment5.params=colorString
|
||||
comment5.target=void\ setForegroundColor(java.lang.String)
|
||||
comment5.text=\n\ Set\ the\ foreground\ color\ of\ the\ Canvas.\n\ @param\ \ newColor\ \ \ the\ new\ color\ for\ the\ foreground\ of\ the\ Canvas\ \n
|
||||
comment6.params=milliseconds
|
||||
comment6.target=void\ wait(int)
|
||||
comment6.text=\n\ Wait\ for\ a\ specified\ number\ of\ milliseconds\ before\ finishing.\n\ This\ provides\ an\ easy\ way\ to\ specify\ a\ small\ delay\ which\ can\ be\n\ used\ when\ producing\ animations.\n\ @param\ \ milliseconds\ \ the\ number\ \n
|
||||
comment7.params=
|
||||
comment7.target=void\ redraw()
|
||||
comment7.text=\n\ Redraw\ ell\ shapes\ currently\ on\ the\ Canvas.\n
|
||||
comment8.params=
|
||||
comment8.target=void\ erase()
|
||||
comment8.text=\n\ Erase\ the\ whole\ canvas.\ (Does\ not\ repaint.)\n
|
||||
numComments=9
|
@@ -0,0 +1,230 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Canvas is a class to allow for simple graphical drawing on a canvas.
|
||||
* This is a modification of the general purpose Canvas, specially made for
|
||||
* the BlueJ "shapes" example.
|
||||
*
|
||||
* @author: Bruce Quig
|
||||
* @author: Michael K<>lling (mik)
|
||||
*
|
||||
* @version 2016.02.29
|
||||
*/
|
||||
public class Canvas
|
||||
{
|
||||
// Note: The implementation of this class (specifically the handling of
|
||||
// shape identity and colors) is slightly more complex than necessary. This
|
||||
// is done on purpose to keep the interface and instance fields of the
|
||||
// shape objects in this project clean and simple for educational purposes.
|
||||
|
||||
private static Canvas canvasSingleton;
|
||||
|
||||
/**
|
||||
* Factory method to get the canvas singleton object.
|
||||
*/
|
||||
public static Canvas getCanvas()
|
||||
{
|
||||
if(canvasSingleton == null) {
|
||||
canvasSingleton = new Canvas("BlueJ Picture Demo", 500, 300,
|
||||
Color.white);
|
||||
}
|
||||
canvasSingleton.setVisible(true);
|
||||
return canvasSingleton;
|
||||
}
|
||||
|
||||
// ----- instance part -----
|
||||
|
||||
private JFrame frame;
|
||||
private CanvasPane canvas;
|
||||
private Graphics2D graphic;
|
||||
private Color backgroundColor;
|
||||
private Image canvasImage;
|
||||
private List<Object> objects;
|
||||
private HashMap<Object, ShapeDescription> shapes;
|
||||
|
||||
/**
|
||||
* Create a Canvas.
|
||||
* @param title title to appear in Canvas Frame
|
||||
* @param width the desired width for the canvas
|
||||
* @param height the desired height for the canvas
|
||||
* @param bgColor the desired background color of the canvas
|
||||
*/
|
||||
private Canvas(String title, int width, int height, Color bgColor)
|
||||
{
|
||||
frame = new JFrame();
|
||||
canvas = new CanvasPane();
|
||||
frame.setContentPane(canvas);
|
||||
frame.setTitle(title);
|
||||
frame.setLocation(30, 30);
|
||||
canvas.setPreferredSize(new Dimension(width, height));
|
||||
backgroundColor = bgColor;
|
||||
frame.pack();
|
||||
objects = new ArrayList<Object>();
|
||||
shapes = new HashMap<Object, ShapeDescription>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the canvas visibility and brings canvas to the front of screen
|
||||
* when made visible. This method can also be used to bring an already
|
||||
* visible canvas to the front of other windows.
|
||||
* @param visible boolean value representing the desired visibility of
|
||||
* the canvas (true or false)
|
||||
*/
|
||||
public void setVisible(boolean visible)
|
||||
{
|
||||
if(graphic == null) {
|
||||
// first time: instantiate the offscreen image and fill it with
|
||||
// the background color
|
||||
Dimension size = canvas.getSize();
|
||||
canvasImage = canvas.createImage(size.width, size.height);
|
||||
graphic = (Graphics2D)canvasImage.getGraphics();
|
||||
graphic.setColor(backgroundColor);
|
||||
graphic.fillRect(0, 0, size.width, size.height);
|
||||
graphic.setColor(Color.black);
|
||||
}
|
||||
frame.setVisible(visible);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a given shape onto the canvas.
|
||||
* @param referenceObject an object to define identity for this shape
|
||||
* @param color the color of the shape
|
||||
* @param shape the shape object to be drawn on the canvas
|
||||
*/
|
||||
// Note: this is a slightly backwards way of maintaining the shape
|
||||
// objects. It is carefully designed to keep the visible shape interfaces
|
||||
// in this project clean and simple for educational purposes.
|
||||
public void draw(Object referenceObject, String color, Shape shape)
|
||||
{
|
||||
objects.remove(referenceObject); // just in case it was already there
|
||||
objects.add(referenceObject); // add at the end
|
||||
shapes.put(referenceObject, new ShapeDescription(shape, color));
|
||||
redraw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Erase a given shape's from the screen.
|
||||
* @param referenceObject the shape object to be erased
|
||||
*/
|
||||
public void erase(Object referenceObject)
|
||||
{
|
||||
objects.remove(referenceObject); // just in case it was already there
|
||||
shapes.remove(referenceObject);
|
||||
redraw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the foreground color of the Canvas.
|
||||
* @param newColor the new color for the foreground of the Canvas
|
||||
*/
|
||||
public void setForegroundColor(String colorString)
|
||||
{
|
||||
if(colorString.equals("red")) {
|
||||
graphic.setColor(new Color(235, 25, 25));
|
||||
}
|
||||
else if(colorString.equals("black")) {
|
||||
graphic.setColor(Color.black);
|
||||
}
|
||||
else if(colorString.equals("blue")) {
|
||||
graphic.setColor(new Color(30, 75, 220));
|
||||
}
|
||||
else if(colorString.equals("yellow")) {
|
||||
graphic.setColor(new Color(255, 230, 0));
|
||||
}
|
||||
else if(colorString.equals("green")) {
|
||||
graphic.setColor(new Color(80, 160, 60));
|
||||
}
|
||||
else if(colorString.equals("magenta")) {
|
||||
graphic.setColor(Color.magenta);
|
||||
}
|
||||
else if(colorString.equals("white")) {
|
||||
graphic.setColor(Color.white);
|
||||
}
|
||||
else {
|
||||
graphic.setColor(Color.black);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for a specified number of milliseconds before finishing.
|
||||
* This provides an easy way to specify a small delay which can be
|
||||
* used when producing animations.
|
||||
* @param milliseconds the number
|
||||
*/
|
||||
public void wait(int milliseconds)
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(milliseconds);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// ignoring exception at the moment
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Redraw ell shapes currently on the Canvas.
|
||||
*/
|
||||
private void redraw()
|
||||
{
|
||||
erase();
|
||||
for(Object shape : objects) {
|
||||
shapes.get(shape).draw(graphic);
|
||||
}
|
||||
canvas.repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Erase the whole canvas. (Does not repaint.)
|
||||
*/
|
||||
private void erase()
|
||||
{
|
||||
Color original = graphic.getColor();
|
||||
graphic.setColor(backgroundColor);
|
||||
Dimension size = canvas.getSize();
|
||||
graphic.fill(new Rectangle(0, 0, size.width, size.height));
|
||||
graphic.setColor(original);
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************
|
||||
* Inner class CanvasPane - the actual canvas component contained in the
|
||||
* Canvas frame. This is essentially a JPanel with added capability to
|
||||
* refresh the image drawn on it.
|
||||
*/
|
||||
private class CanvasPane extends JPanel
|
||||
{
|
||||
public void paint(Graphics g)
|
||||
{
|
||||
g.drawImage(canvasImage, 0, 0, null);
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Inner class CanvasPane - the actual canvas component contained in the
|
||||
* Canvas frame. This is essentially a JPanel with added capability to
|
||||
* refresh the image drawn on it.
|
||||
*/
|
||||
private class ShapeDescription
|
||||
{
|
||||
private Shape shape;
|
||||
private String colorString;
|
||||
|
||||
public ShapeDescription(Shape shape, String color)
|
||||
{
|
||||
this.shape = shape;
|
||||
colorString = color;
|
||||
}
|
||||
|
||||
public void draw(Graphics2D graphic)
|
||||
{
|
||||
setForegroundColor(colorString);
|
||||
graphic.fill(shape);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
@@ -0,0 +1,47 @@
|
||||
#BlueJ class context
|
||||
comment0.params=
|
||||
comment0.target=Circle()
|
||||
comment0.text=\n\ Create\ a\ new\ circle\ at\ default\ position\ with\ default\ color.\n
|
||||
comment1.params=
|
||||
comment1.target=void\ makeVisible()
|
||||
comment1.text=\n\ Make\ this\ circle\ visible.\ If\ it\ was\ already\ visible,\ do\ nothing.\n
|
||||
comment10.params=distance
|
||||
comment10.target=void\ slowMoveVertical(int)
|
||||
comment10.text=\n\ Slowly\ move\ the\ circle\ vertically\ by\ 'distance'\ pixels.\n
|
||||
comment11.params=newDiameter
|
||||
comment11.target=void\ changeSize(int)
|
||||
comment11.text=\n\ Change\ the\ size\ to\ the\ new\ size\ (in\ pixels).\ Size\ must\ be\ >\=\ 0.\n
|
||||
comment12.params=newColor
|
||||
comment12.target=void\ changeColor(java.lang.String)
|
||||
comment12.text=\n\ Change\ the\ color.\ Valid\ colors\ are\ "red",\ "yellow",\ "blue",\ "green",\n\ "magenta"\ and\ "black".\n
|
||||
comment13.params=
|
||||
comment13.target=void\ draw()
|
||||
comment13.text=\n\ Draw\ the\ circle\ with\ current\ specifications\ on\ screen.\n
|
||||
comment14.params=
|
||||
comment14.target=void\ erase()
|
||||
comment14.text=\n\ Erase\ the\ circle\ on\ screen.\n
|
||||
comment2.params=
|
||||
comment2.target=void\ makeInvisible()
|
||||
comment2.text=\n\ Make\ this\ circle\ invisible.\ If\ it\ was\ already\ invisible,\ do\ nothing.\n
|
||||
comment3.params=
|
||||
comment3.target=void\ moveRight()
|
||||
comment3.text=\n\ Move\ the\ circle\ a\ few\ pixels\ to\ the\ right.\n
|
||||
comment4.params=
|
||||
comment4.target=void\ moveLeft()
|
||||
comment4.text=\n\ Move\ the\ circle\ a\ few\ pixels\ to\ the\ left.\n
|
||||
comment5.params=
|
||||
comment5.target=void\ moveUp()
|
||||
comment5.text=\n\ Move\ the\ circle\ a\ few\ pixels\ up.\n
|
||||
comment6.params=
|
||||
comment6.target=void\ moveDown()
|
||||
comment6.text=\n\ Move\ the\ circle\ a\ few\ pixels\ down.\n
|
||||
comment7.params=distance
|
||||
comment7.target=void\ moveHorizontal(int)
|
||||
comment7.text=\n\ Move\ the\ circle\ horizontally\ by\ 'distance'\ pixels.\n
|
||||
comment8.params=distance
|
||||
comment8.target=void\ moveVertical(int)
|
||||
comment8.text=\n\ Move\ the\ circle\ vertically\ by\ 'distance'\ pixels.\n
|
||||
comment9.params=distance
|
||||
comment9.target=void\ slowMoveHorizontal(int)
|
||||
comment9.text=\n\ Slowly\ move\ the\ circle\ horizontally\ by\ 'distance'\ pixels.\n
|
||||
numComments=15
|
@@ -0,0 +1,191 @@
|
||||
import java.awt.*;
|
||||
import java.awt.geom.*;
|
||||
|
||||
/**
|
||||
* A circle that can be manipulated and that draws itself on a canvas.
|
||||
*
|
||||
* @author Michael K<>lling and David J. Barnes
|
||||
* @version 2016.02.29
|
||||
*/
|
||||
|
||||
public class Circle
|
||||
{
|
||||
private int diameter;
|
||||
private int xPosition;
|
||||
private int yPosition;
|
||||
private String color;
|
||||
private boolean isVisible;
|
||||
|
||||
/**
|
||||
* Create a new circle at default position with default color.
|
||||
*/
|
||||
public Circle()
|
||||
{
|
||||
diameter = 68;
|
||||
xPosition = 230;
|
||||
yPosition = 90;
|
||||
color = "blue";
|
||||
}
|
||||
|
||||
/**
|
||||
* Make this circle visible. If it was already visible, do nothing.
|
||||
*/
|
||||
public void makeVisible()
|
||||
{
|
||||
isVisible = true;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make this circle invisible. If it was already invisible, do nothing.
|
||||
*/
|
||||
public void makeInvisible()
|
||||
{
|
||||
erase();
|
||||
isVisible = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the circle a few pixels to the right.
|
||||
*/
|
||||
public void moveRight()
|
||||
{
|
||||
moveHorizontal(20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the circle a few pixels to the left.
|
||||
*/
|
||||
public void moveLeft()
|
||||
{
|
||||
moveHorizontal(-20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the circle a few pixels up.
|
||||
*/
|
||||
public void moveUp()
|
||||
{
|
||||
moveVertical(-20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the circle a few pixels down.
|
||||
*/
|
||||
public void moveDown()
|
||||
{
|
||||
moveVertical(20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the circle horizontally by 'distance' pixels.
|
||||
*/
|
||||
public void moveHorizontal(int distance)
|
||||
{
|
||||
erase();
|
||||
xPosition += distance;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the circle vertically by 'distance' pixels.
|
||||
*/
|
||||
public void moveVertical(int distance)
|
||||
{
|
||||
erase();
|
||||
yPosition += distance;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Slowly move the circle horizontally by 'distance' pixels.
|
||||
*/
|
||||
public void slowMoveHorizontal(int distance)
|
||||
{
|
||||
int delta;
|
||||
|
||||
if(distance < 0)
|
||||
{
|
||||
delta = -1;
|
||||
distance = -distance;
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = 1;
|
||||
}
|
||||
|
||||
for(int i = 0; i < distance; i++)
|
||||
{
|
||||
xPosition += delta;
|
||||
draw();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Slowly move the circle vertically by 'distance' pixels.
|
||||
*/
|
||||
public void slowMoveVertical(int distance)
|
||||
{
|
||||
int delta;
|
||||
|
||||
if(distance < 0)
|
||||
{
|
||||
delta = -1;
|
||||
distance = -distance;
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = 1;
|
||||
}
|
||||
|
||||
for(int i = 0; i < distance; i++)
|
||||
{
|
||||
yPosition += delta;
|
||||
draw();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the size to the new size (in pixels). Size must be >= 0.
|
||||
*/
|
||||
public void changeSize(int newDiameter)
|
||||
{
|
||||
erase();
|
||||
diameter = newDiameter;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the color. Valid colors are "red", "yellow", "blue", "green",
|
||||
* "magenta" and "black".
|
||||
*/
|
||||
public void changeColor(String newColor)
|
||||
{
|
||||
color = newColor;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the circle with current specifications on screen.
|
||||
*/
|
||||
private void draw()
|
||||
{
|
||||
if(isVisible) {
|
||||
Canvas canvas = Canvas.getCanvas();
|
||||
canvas.draw(this, color, new Ellipse2D.Double(xPosition, yPosition,
|
||||
diameter, diameter));
|
||||
canvas.wait(10);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Erase the circle on screen.
|
||||
*/
|
||||
private void erase()
|
||||
{
|
||||
if(isVisible) {
|
||||
Canvas canvas = Canvas.getCanvas();
|
||||
canvas.erase(this);
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
@@ -0,0 +1,47 @@
|
||||
#BlueJ class context
|
||||
comment0.params=
|
||||
comment0.target=Person()
|
||||
comment0.text=\n\ Create\ a\ new\ person\ at\ default\ position\ with\ default\ color.\n
|
||||
comment1.params=
|
||||
comment1.target=void\ makeVisible()
|
||||
comment1.text=\n\ Make\ this\ person\ visible.\ If\ it\ was\ already\ visible,\ do\ nothing.\n
|
||||
comment10.params=distance
|
||||
comment10.target=void\ slowMoveVertical(int)
|
||||
comment10.text=\n\ Slowly\ move\ the\ person\ vertically\ by\ 'distance'\ pixels.\n
|
||||
comment11.params=newHeight\ newWidth
|
||||
comment11.target=void\ changeSize(int,\ int)
|
||||
comment11.text=\n\ Change\ the\ size\ to\ the\ new\ size\ (in\ pixels).\ Size\ must\ be\ >\=\ 0.\n
|
||||
comment12.params=newColor
|
||||
comment12.target=void\ changeColor(java.lang.String)
|
||||
comment12.text=\n\ Change\ the\ color.\ Valid\ colors\ are\ "red",\ "yellow",\ "blue",\ "green",\n\ "magenta"\ and\ "black".\n
|
||||
comment13.params=
|
||||
comment13.target=void\ draw()
|
||||
comment13.text=\n\ Draw\ the\ person\ with\ current\ specifications\ on\ screen.\n
|
||||
comment14.params=
|
||||
comment14.target=void\ erase()
|
||||
comment14.text=\n\ Erase\ the\ person\ on\ screen.\n
|
||||
comment2.params=
|
||||
comment2.target=void\ makeInvisible()
|
||||
comment2.text=\n\ Make\ this\ person\ invisible.\ If\ it\ was\ already\ invisible,\ do\ nothing.\n
|
||||
comment3.params=
|
||||
comment3.target=void\ moveRight()
|
||||
comment3.text=\n\ Move\ the\ person\ a\ few\ pixels\ to\ the\ right.\n
|
||||
comment4.params=
|
||||
comment4.target=void\ moveLeft()
|
||||
comment4.text=\n\ Move\ the\ person\ a\ few\ pixels\ to\ the\ left.\n
|
||||
comment5.params=
|
||||
comment5.target=void\ moveUp()
|
||||
comment5.text=\n\ Move\ the\ person\ a\ few\ pixels\ up.\n
|
||||
comment6.params=
|
||||
comment6.target=void\ moveDown()
|
||||
comment6.text=\n\ Move\ the\ person\ a\ few\ pixels\ down.\n
|
||||
comment7.params=distance
|
||||
comment7.target=void\ moveHorizontal(int)
|
||||
comment7.text=\n\ Move\ the\ person\ horizontally\ by\ 'distance'\ pixels.\n
|
||||
comment8.params=distance
|
||||
comment8.target=void\ moveVertical(int)
|
||||
comment8.text=\n\ Move\ the\ person\ vertically\ by\ 'distance'\ pixels.\n
|
||||
comment9.params=distance
|
||||
comment9.target=void\ slowMoveHorizontal(int)
|
||||
comment9.text=\n\ Slowly\ move\ the\ person\ horizontally\ by\ 'distance'\ pixels.\n
|
||||
numComments=15
|
@@ -0,0 +1,206 @@
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* A person that can be manipulated and that draws itself on a canvas.
|
||||
*
|
||||
* @author Michael K<>lling and David J. Barnes
|
||||
* @version 2016.02.29
|
||||
*/
|
||||
|
||||
public class Person
|
||||
{
|
||||
private int height;
|
||||
private int width;
|
||||
private int xPosition;
|
||||
private int yPosition;
|
||||
private String color;
|
||||
private boolean isVisible;
|
||||
|
||||
/**
|
||||
* Create a new person at default position with default color.
|
||||
*/
|
||||
public Person()
|
||||
{
|
||||
height = 60;
|
||||
width = 30;
|
||||
xPosition = 280;
|
||||
yPosition = 190;
|
||||
color = "black";
|
||||
isVisible = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make this person visible. If it was already visible, do nothing.
|
||||
*/
|
||||
public void makeVisible()
|
||||
{
|
||||
isVisible = true;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make this person invisible. If it was already invisible, do nothing.
|
||||
*/
|
||||
public void makeInvisible()
|
||||
{
|
||||
erase();
|
||||
isVisible = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the person a few pixels to the right.
|
||||
*/
|
||||
public void moveRight()
|
||||
{
|
||||
moveHorizontal(20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the person a few pixels to the left.
|
||||
*/
|
||||
public void moveLeft()
|
||||
{
|
||||
moveHorizontal(-20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the person a few pixels up.
|
||||
*/
|
||||
public void moveUp()
|
||||
{
|
||||
moveVertical(-20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the person a few pixels down.
|
||||
*/
|
||||
public void moveDown()
|
||||
{
|
||||
moveVertical(20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the person horizontally by 'distance' pixels.
|
||||
*/
|
||||
public void moveHorizontal(int distance)
|
||||
{
|
||||
erase();
|
||||
xPosition += distance;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the person vertically by 'distance' pixels.
|
||||
*/
|
||||
public void moveVertical(int distance)
|
||||
{
|
||||
erase();
|
||||
yPosition += distance;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Slowly move the person horizontally by 'distance' pixels.
|
||||
*/
|
||||
public void slowMoveHorizontal(int distance)
|
||||
{
|
||||
int delta;
|
||||
|
||||
if(distance < 0)
|
||||
{
|
||||
delta = -1;
|
||||
distance = -distance;
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = 1;
|
||||
}
|
||||
|
||||
for(int i = 0; i < distance; i++)
|
||||
{
|
||||
xPosition += delta;
|
||||
draw();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Slowly move the person vertically by 'distance' pixels.
|
||||
*/
|
||||
public void slowMoveVertical(int distance)
|
||||
{
|
||||
int delta;
|
||||
|
||||
if(distance < 0)
|
||||
{
|
||||
delta = -1;
|
||||
distance = -distance;
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = 1;
|
||||
}
|
||||
|
||||
for(int i = 0; i < distance; i++)
|
||||
{
|
||||
yPosition += delta;
|
||||
draw();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the size to the new size (in pixels). Size must be >= 0.
|
||||
*/
|
||||
public void changeSize(int newHeight, int newWidth)
|
||||
{
|
||||
erase();
|
||||
height = newHeight;
|
||||
width = newWidth;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the color. Valid colors are "red", "yellow", "blue", "green",
|
||||
* "magenta" and "black".
|
||||
*/
|
||||
public void changeColor(String newColor)
|
||||
{
|
||||
color = newColor;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the person with current specifications on screen.
|
||||
*/
|
||||
private void draw()
|
||||
{
|
||||
int bh = (int)(height * 0.7); // body height
|
||||
int hh = (height - bh) / 2; // half head height
|
||||
int hw = width / 2; // half width
|
||||
int x = xPosition;
|
||||
int y = yPosition;
|
||||
if(isVisible) {
|
||||
Canvas canvas = Canvas.getCanvas();
|
||||
int[] xpoints = { x-3, x-hw, x-hw, x-(int)(hw*0.2)-1, x-(int)(hw*0.2)-1, x-hw,
|
||||
x-hw+(int)(hw*0.4)+1, x, x+hw-(int)(hw*0.4)-1, x+hw, x+(int)(hw*0.2)+1,
|
||||
x+(int)(hw*0.2)+1, x+hw, x+hw, x+3, x+(int)(hw*0.6),
|
||||
x+(int)(hw*0.6), x+3, x-3, x-(int)(hw*0.6), x-(int)(hw*0.6) };
|
||||
int[] ypoints = { y, y+(int)(bh*0.2), y+(int)(bh*0.4), y+(int)(bh*0.2),
|
||||
y+(int)(bh*0.5), y+bh, y+bh, y+(int)(bh*0.65), y+bh, y+bh,
|
||||
y+(int)(bh*0.5), y+(int)(bh*0.2), y+(int)(bh*0.4), y+(int)(bh*0.2),
|
||||
y, y-hh+3, y-hh-3, y-hh-hh, y-hh-hh, y-hh-3, y-hh+3 };
|
||||
canvas.draw(this, color, new Polygon(xpoints, ypoints, 21));
|
||||
canvas.wait(10);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Erase the person on screen.
|
||||
*/
|
||||
private void erase()
|
||||
{
|
||||
if(isVisible) {
|
||||
Canvas canvas = Canvas.getCanvas();
|
||||
canvas.erase(this);
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
@@ -0,0 +1,20 @@
|
||||
#BlueJ class context
|
||||
comment0.params=
|
||||
comment0.target=Picture()
|
||||
comment0.text=\n\ Constructor\ for\ objects\ of\ class\ Picture\n
|
||||
comment1.params=
|
||||
comment1.target=void\ draw()
|
||||
comment1.text=\n\ Draw\ this\ picture.\n
|
||||
comment2.params=
|
||||
comment2.target=void\ setBlackAndWhite()
|
||||
comment2.text=\n\ Change\ this\ picture\ to\ black/white\ display\n
|
||||
comment3.params=
|
||||
comment3.target=void\ setColor()
|
||||
comment3.text=\n\ Change\ this\ picture\ to\ use\ color\ display\n
|
||||
comment4.params=
|
||||
comment4.target=void\ doSunset()
|
||||
comment4.text=\n\ Start\ Sunset\n
|
||||
comment5.params=
|
||||
comment5.target=void\ doSunrise()
|
||||
comment5.text=\n\ Start\ Sunrise\n
|
||||
numComments=6
|
@@ -0,0 +1,113 @@
|
||||
/**
|
||||
* This class represents a simple picture. You can draw the picture using
|
||||
* the draw method. But wait, there's more: being an electronic picture, it
|
||||
* can be changed. You can set it to black-and-white display and back to
|
||||
* colors (only after it's been drawn, of course).
|
||||
*
|
||||
* This class was written as an early example for teaching Java with BlueJ.
|
||||
*
|
||||
* @author Michael K<>lling and David J. Barnes
|
||||
* @version 2016.02.29
|
||||
*/
|
||||
public class Picture
|
||||
{
|
||||
private Square wall;
|
||||
private Square window;
|
||||
private Triangle roof;
|
||||
private Circle sun;
|
||||
private Circle sun2;
|
||||
private Person person;
|
||||
private boolean drawn;
|
||||
|
||||
/**
|
||||
* Constructor for objects of class Picture
|
||||
*/
|
||||
public Picture()
|
||||
{
|
||||
wall = new Square();
|
||||
window = new Square();
|
||||
roof = new Triangle();
|
||||
sun = new Circle();
|
||||
//sun2 = new Circle();
|
||||
person = new Person();
|
||||
drawn = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw this picture.
|
||||
*/
|
||||
public void draw()
|
||||
{
|
||||
if(!drawn) {
|
||||
wall.moveHorizontal(-140);
|
||||
wall.moveVertical(20);
|
||||
wall.changeSize(120);
|
||||
wall.makeVisible();
|
||||
|
||||
window.changeColor("black");
|
||||
window.moveHorizontal(-120);
|
||||
window.moveVertical(40);
|
||||
window.changeSize(40);
|
||||
window.makeVisible();
|
||||
|
||||
roof.changeSize(60, 180);
|
||||
roof.moveHorizontal(20);
|
||||
roof.moveVertical(-60);
|
||||
roof.makeVisible();
|
||||
|
||||
sun.changeColor("blue");
|
||||
sun.moveHorizontal(100);
|
||||
sun.moveVertical(-40);
|
||||
sun.changeSize(80);
|
||||
sun.makeVisible();
|
||||
|
||||
//sun2.changeColor("yellow");
|
||||
//sun2.moveHorizontal(30);
|
||||
//sun2.moveVertical(-35);
|
||||
//sun2.changeSize(50);
|
||||
//sun2.makeVisible();
|
||||
drawn = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change this picture to black/white display
|
||||
*/
|
||||
public void setBlackAndWhite()
|
||||
{
|
||||
wall.changeColor("black");
|
||||
window.changeColor("white");
|
||||
roof.changeColor("black");
|
||||
sun.changeColor("black");
|
||||
//sun2.changeColor("black");
|
||||
}
|
||||
|
||||
/**
|
||||
* Change this picture to use color display
|
||||
*/
|
||||
public void setColor()
|
||||
{
|
||||
wall.changeColor("red");
|
||||
window.changeColor("black");
|
||||
roof.changeColor("green");
|
||||
sun.changeColor("yellow");
|
||||
//sun2.changeColor("green");
|
||||
}
|
||||
|
||||
/**
|
||||
* Start Sunset
|
||||
*/
|
||||
public void doSunset()
|
||||
{
|
||||
sun.slowMoveVertical(250);
|
||||
setBlackAndWhite();
|
||||
}
|
||||
/**
|
||||
* Start Sunrise
|
||||
*/
|
||||
public void doSunrise()
|
||||
{
|
||||
sun.slowMoveVertical(-250);
|
||||
setColor();
|
||||
}
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
Project "house"
|
||||
Authors: Michael K<>lling and David J. Barnes
|
||||
|
||||
This project is part of the material for the book
|
||||
|
||||
Objects First with Java - A Practical Introduction using BlueJ
|
||||
Sixth edition
|
||||
David J. Barnes and Michael K<>lling
|
||||
Pearson Education, 2016
|
||||
|
||||
It is discussed in chapter 1.
|
||||
|
||||
This is a very simple project to demonstrate some characteristics of
|
||||
objects.
|
||||
|
||||
This project is often used after studying the "shapes" project. It
|
||||
adds a class to those ones in "shapes". That class (named "Picture")
|
||||
uses the shapes to draw a picture. It can be used to experiment with
|
||||
modifying source code.
|
Binary file not shown.
@@ -0,0 +1,47 @@
|
||||
#BlueJ class context
|
||||
comment0.params=
|
||||
comment0.target=Square()
|
||||
comment0.text=\n\ Create\ a\ new\ square\ at\ default\ position\ with\ default\ color.\n
|
||||
comment1.params=
|
||||
comment1.target=void\ makeVisible()
|
||||
comment1.text=\n\ Make\ this\ square\ visible.\ If\ it\ was\ already\ visible,\ do\ nothing.\n
|
||||
comment10.params=distance
|
||||
comment10.target=void\ slowMoveVertical(int)
|
||||
comment10.text=\n\ Slowly\ move\ the\ square\ vertically\ by\ 'distance'\ pixels.\n
|
||||
comment11.params=newSize
|
||||
comment11.target=void\ changeSize(int)
|
||||
comment11.text=\n\ Change\ the\ size\ to\ the\ new\ size\ (in\ pixels).\ Size\ must\ be\ >\=\ 0.\n
|
||||
comment12.params=newColor
|
||||
comment12.target=void\ changeColor(java.lang.String)
|
||||
comment12.text=\n\ Change\ the\ color.\ Valid\ colors\ are\ "red",\ "yellow",\ "blue",\ "green",\n\ "magenta"\ and\ "black".\n
|
||||
comment13.params=
|
||||
comment13.target=void\ draw()
|
||||
comment13.text=\n\ Draw\ the\ square\ with\ current\ specifications\ on\ screen.\n
|
||||
comment14.params=
|
||||
comment14.target=void\ erase()
|
||||
comment14.text=\n\ Erase\ the\ square\ on\ screen.\n
|
||||
comment2.params=
|
||||
comment2.target=void\ makeInvisible()
|
||||
comment2.text=\n\ Make\ this\ square\ invisible.\ If\ it\ was\ already\ invisible,\ do\ nothing.\n
|
||||
comment3.params=
|
||||
comment3.target=void\ moveRight()
|
||||
comment3.text=\n\ Move\ the\ square\ a\ few\ pixels\ to\ the\ right.\n
|
||||
comment4.params=
|
||||
comment4.target=void\ moveLeft()
|
||||
comment4.text=\n\ Move\ the\ square\ a\ few\ pixels\ to\ the\ left.\n
|
||||
comment5.params=
|
||||
comment5.target=void\ moveUp()
|
||||
comment5.text=\n\ Move\ the\ square\ a\ few\ pixels\ up.\n
|
||||
comment6.params=
|
||||
comment6.target=void\ moveDown()
|
||||
comment6.text=\n\ Move\ the\ square\ a\ few\ pixels\ down.\n
|
||||
comment7.params=distance
|
||||
comment7.target=void\ moveHorizontal(int)
|
||||
comment7.text=\n\ Move\ the\ square\ horizontally\ by\ 'distance'\ pixels.\n
|
||||
comment8.params=distance
|
||||
comment8.target=void\ moveVertical(int)
|
||||
comment8.text=\n\ Move\ the\ square\ vertically\ by\ 'distance'\ pixels.\n
|
||||
comment9.params=distance
|
||||
comment9.target=void\ slowMoveHorizontal(int)
|
||||
comment9.text=\n\ Slowly\ move\ the\ square\ horizontally\ by\ 'distance'\ pixels.\n
|
||||
numComments=15
|
@@ -0,0 +1,191 @@
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* A square that can be manipulated and that draws itself on a canvas.
|
||||
*
|
||||
* @author Michael K<>lling and David J. Barnes
|
||||
* @version 2016.02.29
|
||||
*/
|
||||
|
||||
public class Square
|
||||
{
|
||||
private int size;
|
||||
private int xPosition;
|
||||
private int yPosition;
|
||||
private String color;
|
||||
private boolean isVisible;
|
||||
|
||||
/**
|
||||
* Create a new square at default position with default color.
|
||||
*/
|
||||
public Square()
|
||||
{
|
||||
size = 60;
|
||||
xPosition = 310;
|
||||
yPosition = 120;
|
||||
color = "red";
|
||||
isVisible = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make this square visible. If it was already visible, do nothing.
|
||||
*/
|
||||
public void makeVisible()
|
||||
{
|
||||
isVisible = true;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make this square invisible. If it was already invisible, do nothing.
|
||||
*/
|
||||
public void makeInvisible()
|
||||
{
|
||||
erase();
|
||||
isVisible = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the square a few pixels to the right.
|
||||
*/
|
||||
public void moveRight()
|
||||
{
|
||||
moveHorizontal(20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the square a few pixels to the left.
|
||||
*/
|
||||
public void moveLeft()
|
||||
{
|
||||
moveHorizontal(-20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the square a few pixels up.
|
||||
*/
|
||||
public void moveUp()
|
||||
{
|
||||
moveVertical(-20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the square a few pixels down.
|
||||
*/
|
||||
public void moveDown()
|
||||
{
|
||||
moveVertical(20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the square horizontally by 'distance' pixels.
|
||||
*/
|
||||
public void moveHorizontal(int distance)
|
||||
{
|
||||
erase();
|
||||
xPosition += distance;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the square vertically by 'distance' pixels.
|
||||
*/
|
||||
public void moveVertical(int distance)
|
||||
{
|
||||
erase();
|
||||
yPosition += distance;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Slowly move the square horizontally by 'distance' pixels.
|
||||
*/
|
||||
public void slowMoveHorizontal(int distance)
|
||||
{
|
||||
int delta;
|
||||
|
||||
if(distance < 0)
|
||||
{
|
||||
delta = -1;
|
||||
distance = -distance;
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = 1;
|
||||
}
|
||||
|
||||
for(int i = 0; i < distance; i++)
|
||||
{
|
||||
xPosition += delta;
|
||||
draw();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Slowly move the square vertically by 'distance' pixels.
|
||||
*/
|
||||
public void slowMoveVertical(int distance)
|
||||
{
|
||||
int delta;
|
||||
|
||||
if(distance < 0)
|
||||
{
|
||||
delta = -1;
|
||||
distance = -distance;
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = 1;
|
||||
}
|
||||
|
||||
for(int i = 0; i < distance; i++)
|
||||
{
|
||||
yPosition += delta;
|
||||
draw();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the size to the new size (in pixels). Size must be >= 0.
|
||||
*/
|
||||
public void changeSize(int newSize)
|
||||
{
|
||||
erase();
|
||||
size = newSize;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the color. Valid colors are "red", "yellow", "blue", "green",
|
||||
* "magenta" and "black".
|
||||
*/
|
||||
public void changeColor(String newColor)
|
||||
{
|
||||
color = newColor;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the square with current specifications on screen.
|
||||
*/
|
||||
private void draw()
|
||||
{
|
||||
if(isVisible) {
|
||||
Canvas canvas = Canvas.getCanvas();
|
||||
canvas.draw(this, color,
|
||||
new Rectangle(xPosition, yPosition, size, size));
|
||||
canvas.wait(10);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Erase the square on screen.
|
||||
*/
|
||||
private void erase()
|
||||
{
|
||||
if(isVisible) {
|
||||
Canvas canvas = Canvas.getCanvas();
|
||||
canvas.erase(this);
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
@@ -0,0 +1,47 @@
|
||||
#BlueJ class context
|
||||
comment0.params=
|
||||
comment0.target=Triangle()
|
||||
comment0.text=\n\ Create\ a\ new\ triangle\ at\ default\ position\ with\ default\ color.\n
|
||||
comment1.params=
|
||||
comment1.target=void\ makeVisible()
|
||||
comment1.text=\n\ Make\ this\ triangle\ visible.\ If\ it\ was\ already\ visible,\ do\ nothing.\n
|
||||
comment10.params=distance
|
||||
comment10.target=void\ slowMoveVertical(int)
|
||||
comment10.text=\n\ Slowly\ move\ the\ triangle\ vertically\ by\ 'distance'\ pixels.\n
|
||||
comment11.params=newHeight\ newWidth
|
||||
comment11.target=void\ changeSize(int,\ int)
|
||||
comment11.text=\n\ Change\ the\ size\ to\ the\ new\ size\ (in\ pixels).\ Size\ must\ be\ >\=\ 0.\n
|
||||
comment12.params=newColor
|
||||
comment12.target=void\ changeColor(java.lang.String)
|
||||
comment12.text=\n\ Change\ the\ color.\ Valid\ colors\ are\ "red",\ "yellow",\ "blue",\ "green",\n\ "magenta"\ and\ "black".\n
|
||||
comment13.params=
|
||||
comment13.target=void\ draw()
|
||||
comment13.text=\n\ Draw\ the\ triangle\ with\ current\ specifications\ on\ screen.\n
|
||||
comment14.params=
|
||||
comment14.target=void\ erase()
|
||||
comment14.text=\n\ Erase\ the\ triangle\ on\ screen.\n
|
||||
comment2.params=
|
||||
comment2.target=void\ makeInvisible()
|
||||
comment2.text=\n\ Make\ this\ triangle\ invisible.\ If\ it\ was\ already\ invisible,\ do\ nothing.\n
|
||||
comment3.params=
|
||||
comment3.target=void\ moveRight()
|
||||
comment3.text=\n\ Move\ the\ triangle\ a\ few\ pixels\ to\ the\ right.\n
|
||||
comment4.params=
|
||||
comment4.target=void\ moveLeft()
|
||||
comment4.text=\n\ Move\ the\ triangle\ a\ few\ pixels\ to\ the\ left.\n
|
||||
comment5.params=
|
||||
comment5.target=void\ moveUp()
|
||||
comment5.text=\n\ Move\ the\ triangle\ a\ few\ pixels\ up.\n
|
||||
comment6.params=
|
||||
comment6.target=void\ moveDown()
|
||||
comment6.text=\n\ Move\ the\ triangle\ a\ few\ pixels\ down.\n
|
||||
comment7.params=distance
|
||||
comment7.target=void\ moveHorizontal(int)
|
||||
comment7.text=\n\ Move\ the\ triangle\ horizontally\ by\ 'distance'\ pixels.\n
|
||||
comment8.params=distance
|
||||
comment8.target=void\ moveVertical(int)
|
||||
comment8.text=\n\ Move\ the\ triangle\ vertically\ by\ 'distance'\ pixels.\n
|
||||
comment9.params=distance
|
||||
comment9.target=void\ slowMoveHorizontal(int)
|
||||
comment9.text=\n\ Slowly\ move\ the\ triangle\ horizontally\ by\ 'distance'\ pixels.\n
|
||||
numComments=15
|
@@ -0,0 +1,195 @@
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* A triangle that can be manipulated and that draws itself on a canvas.
|
||||
*
|
||||
* @author Michael K<>lling and David J. Barnes
|
||||
* @version 2016.02.29
|
||||
*/
|
||||
|
||||
public class Triangle
|
||||
{
|
||||
private int height;
|
||||
private int width;
|
||||
private int xPosition;
|
||||
private int yPosition;
|
||||
private String color;
|
||||
private boolean isVisible;
|
||||
|
||||
/**
|
||||
* Create a new triangle at default position with default color.
|
||||
*/
|
||||
public Triangle()
|
||||
{
|
||||
height = 60;
|
||||
width = 70;
|
||||
xPosition = 210;
|
||||
yPosition = 140;
|
||||
color = "green";
|
||||
isVisible = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make this triangle visible. If it was already visible, do nothing.
|
||||
*/
|
||||
public void makeVisible()
|
||||
{
|
||||
isVisible = true;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make this triangle invisible. If it was already invisible, do nothing.
|
||||
*/
|
||||
public void makeInvisible()
|
||||
{
|
||||
erase();
|
||||
isVisible = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the triangle a few pixels to the right.
|
||||
*/
|
||||
public void moveRight()
|
||||
{
|
||||
moveHorizontal(20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the triangle a few pixels to the left.
|
||||
*/
|
||||
public void moveLeft()
|
||||
{
|
||||
moveHorizontal(-20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the triangle a few pixels up.
|
||||
*/
|
||||
public void moveUp()
|
||||
{
|
||||
moveVertical(-20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the triangle a few pixels down.
|
||||
*/
|
||||
public void moveDown()
|
||||
{
|
||||
moveVertical(20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the triangle horizontally by 'distance' pixels.
|
||||
*/
|
||||
public void moveHorizontal(int distance)
|
||||
{
|
||||
erase();
|
||||
xPosition += distance;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the triangle vertically by 'distance' pixels.
|
||||
*/
|
||||
public void moveVertical(int distance)
|
||||
{
|
||||
erase();
|
||||
yPosition += distance;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Slowly move the triangle horizontally by 'distance' pixels.
|
||||
*/
|
||||
public void slowMoveHorizontal(int distance)
|
||||
{
|
||||
int delta;
|
||||
|
||||
if(distance < 0)
|
||||
{
|
||||
delta = -1;
|
||||
distance = -distance;
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = 1;
|
||||
}
|
||||
|
||||
for(int i = 0; i < distance; i++)
|
||||
{
|
||||
xPosition += delta;
|
||||
draw();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Slowly move the triangle vertically by 'distance' pixels.
|
||||
*/
|
||||
public void slowMoveVertical(int distance)
|
||||
{
|
||||
int delta;
|
||||
|
||||
if(distance < 0)
|
||||
{
|
||||
delta = -1;
|
||||
distance = -distance;
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = 1;
|
||||
}
|
||||
|
||||
for(int i = 0; i < distance; i++)
|
||||
{
|
||||
yPosition += delta;
|
||||
draw();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the size to the new size (in pixels). Size must be >= 0.
|
||||
*/
|
||||
public void changeSize(int newHeight, int newWidth)
|
||||
{
|
||||
erase();
|
||||
height = newHeight;
|
||||
width = newWidth;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the color. Valid colors are "red", "yellow", "blue", "green",
|
||||
* "magenta" and "black".
|
||||
*/
|
||||
public void changeColor(String newColor)
|
||||
{
|
||||
color = newColor;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the triangle with current specifications on screen.
|
||||
*/
|
||||
private void draw()
|
||||
{
|
||||
if(isVisible) {
|
||||
Canvas canvas = Canvas.getCanvas();
|
||||
int[] xpoints = { xPosition, xPosition + (width/2), xPosition - (width/2) };
|
||||
int[] ypoints = { yPosition, yPosition + height, yPosition + height };
|
||||
canvas.draw(this, color, new Polygon(xpoints, ypoints, 3));
|
||||
canvas.wait(10);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Erase the triangle on screen.
|
||||
*/
|
||||
private void erase()
|
||||
{
|
||||
if(isVisible) {
|
||||
Canvas canvas = Canvas.getCanvas();
|
||||
canvas.erase(this);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,118 @@
|
||||
#BlueJ package file
|
||||
dependency1.from=Triangle
|
||||
dependency1.to=Canvas
|
||||
dependency1.type=UsesDependency
|
||||
dependency2.from=Picture
|
||||
dependency2.to=Square
|
||||
dependency2.type=UsesDependency
|
||||
dependency3.from=Picture
|
||||
dependency3.to=Triangle
|
||||
dependency3.type=UsesDependency
|
||||
dependency4.from=Picture
|
||||
dependency4.to=Circle
|
||||
dependency4.type=UsesDependency
|
||||
dependency5.from=Circle
|
||||
dependency5.to=Canvas
|
||||
dependency5.type=UsesDependency
|
||||
dependency6.from=Square
|
||||
dependency6.to=Canvas
|
||||
dependency6.type=UsesDependency
|
||||
dependency7.from=Person
|
||||
dependency7.to=Canvas
|
||||
dependency7.type=UsesDependency
|
||||
dependency8.from=Picture
|
||||
dependency8.to=Person
|
||||
dependency8.type=UsesDependency
|
||||
objectbench.height=76
|
||||
objectbench.width=940
|
||||
package.editor.height=874
|
||||
package.editor.width=814
|
||||
package.editor.x=0
|
||||
package.editor.y=31
|
||||
package.numDependencies=8
|
||||
package.numTargets=6
|
||||
package.showExtends=true
|
||||
package.showUses=true
|
||||
project.charset=x-MacRoman
|
||||
readme.editor.height=557
|
||||
readme.editor.width=826
|
||||
readme.editor.x=53
|
||||
readme.editor.y=23
|
||||
target1.editor.height=717
|
||||
target1.editor.width=900
|
||||
target1.editor.x=53
|
||||
target1.editor.y=60
|
||||
target1.height=50
|
||||
target1.name=Circle
|
||||
target1.naviview.expanded=true
|
||||
target1.showInterface=false
|
||||
target1.type=ClassTarget
|
||||
target1.typeParameters=
|
||||
target1.width=80
|
||||
target1.x=150
|
||||
target1.y=230
|
||||
target2.editor.height=774
|
||||
target2.editor.width=857
|
||||
target2.editor.x=660
|
||||
target2.editor.y=201
|
||||
target2.height=50
|
||||
target2.name=Picture
|
||||
target2.naviview.expanded=true
|
||||
target2.showInterface=false
|
||||
target2.type=ClassTarget
|
||||
target2.typeParameters=
|
||||
target2.width=80
|
||||
target2.x=70
|
||||
target2.y=70
|
||||
target3.editor.height=781
|
||||
target3.editor.width=898
|
||||
target3.editor.x=53
|
||||
target3.editor.y=51
|
||||
target3.height=50
|
||||
target3.name=Canvas
|
||||
target3.naviview.expanded=true
|
||||
target3.showInterface=false
|
||||
target3.type=ClassTarget
|
||||
target3.typeParameters=
|
||||
target3.width=80
|
||||
target3.x=50
|
||||
target3.y=310
|
||||
target4.editor.height=727
|
||||
target4.editor.width=936
|
||||
target4.editor.x=53
|
||||
target4.editor.y=60
|
||||
target4.height=50
|
||||
target4.name=Triangle
|
||||
target4.naviview.expanded=true
|
||||
target4.showInterface=false
|
||||
target4.type=ClassTarget
|
||||
target4.typeParameters=
|
||||
target4.width=80
|
||||
target4.x=350
|
||||
target4.y=150
|
||||
target5.editor.height=722
|
||||
target5.editor.width=879
|
||||
target5.editor.x=53
|
||||
target5.editor.y=60
|
||||
target5.height=50
|
||||
target5.name=Square
|
||||
target5.naviview.expanded=true
|
||||
target5.showInterface=false
|
||||
target5.type=ClassTarget
|
||||
target5.typeParameters=
|
||||
target5.width=80
|
||||
target5.x=250
|
||||
target5.y=190
|
||||
target6.editor.height=697
|
||||
target6.editor.width=988
|
||||
target6.editor.x=53
|
||||
target6.editor.y=90
|
||||
target6.height=50
|
||||
target6.name=Person
|
||||
target6.naviview.expanded=true
|
||||
target6.showInterface=false
|
||||
target6.type=ClassTarget
|
||||
target6.typeParameters=
|
||||
target6.width=80
|
||||
target6.x=450
|
||||
target6.y=120
|
@@ -0,0 +1,104 @@
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* Class CaseConverter - A simple applet that takes input from a text field
|
||||
* and converts to upper or lower case in response to user button selection.
|
||||
* Works well with a width of 300 and height of 120.
|
||||
*
|
||||
* Aug 2004: Updated from Applet to JApplet (mik)
|
||||
*
|
||||
* @author Bruce Quig
|
||||
* @author Michael Kolling
|
||||
*
|
||||
* @version 2004-08-04
|
||||
*/
|
||||
public class CaseConverter extends JApplet
|
||||
implements ActionListener
|
||||
{
|
||||
private JTextField inputField;
|
||||
private final String UPPERCASE = "UPPERCASE";
|
||||
private final String LOWERCASE = "lowercase";
|
||||
private final String CLEAR = "Clear";
|
||||
|
||||
/**
|
||||
* Called by the browser or applet viewer to inform this JApplet that it
|
||||
* has been loaded into the system. It is always called before the first
|
||||
* time that the start method is called.
|
||||
*/
|
||||
public void init()
|
||||
{
|
||||
// GUI elements are added to the applet's content pane, so get it for us.
|
||||
Container contentPane = getContentPane();
|
||||
|
||||
// set a layout with some spacing
|
||||
contentPane.setLayout(new BorderLayout(12,12));
|
||||
|
||||
// add the title label
|
||||
JLabel title = new JLabel("Case Converter - A BlueJ demo applet");
|
||||
contentPane.add(title, BorderLayout.NORTH);
|
||||
|
||||
// create the center part with prompt and text field and add it
|
||||
JPanel centerPanel = new JPanel();
|
||||
JLabel prompt = new JLabel("Enter a string:");
|
||||
centerPanel.add(prompt);
|
||||
inputField = new JTextField(16);
|
||||
centerPanel.add(inputField);
|
||||
|
||||
contentPane.add(centerPanel, BorderLayout.CENTER);
|
||||
|
||||
// make a panel for the buttons
|
||||
JPanel buttonPanel = new JPanel();
|
||||
|
||||
// add the buttons to the button panel
|
||||
JButton uppercase = new JButton(UPPERCASE);
|
||||
uppercase.addActionListener(this);
|
||||
buttonPanel.add(uppercase);
|
||||
|
||||
JButton lowercase = new JButton(LOWERCASE);
|
||||
lowercase.addActionListener(this);
|
||||
buttonPanel.add(lowercase);
|
||||
|
||||
JButton clear = new JButton(CLEAR);
|
||||
clear.addActionListener(this);
|
||||
buttonPanel.add(clear);
|
||||
|
||||
// add the buttons panel to the content pane
|
||||
contentPane.add(buttonPanel, BorderLayout.SOUTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information about this applet.
|
||||
* An applet should override this method to return a String containing
|
||||
* information about the author, version, and copyright of the JApplet.
|
||||
*
|
||||
* @return a String representation of information about this JApplet
|
||||
*/
|
||||
public String getAppletInfo()
|
||||
{
|
||||
return "Title: Case Converter \n" +
|
||||
"Author: Bruce Quig \n" +
|
||||
"A simple applet that converts text to upper or lower case. ";
|
||||
}
|
||||
|
||||
/**
|
||||
* ActionListener Interface method.
|
||||
* Called when action events occur with registered components that
|
||||
* can fire action events.
|
||||
* @param ae the ActionEvent object created by the event
|
||||
*/
|
||||
public void actionPerformed(ActionEvent evt)
|
||||
{
|
||||
String command = evt.getActionCommand();
|
||||
// if clear button pressed
|
||||
if(CLEAR.equals(command))
|
||||
inputField.setText("");
|
||||
// uppercase button pressed
|
||||
else if(UPPERCASE.equals(command))
|
||||
inputField.setText(inputField.getText().toUpperCase());
|
||||
// lowercase button pressed
|
||||
else if(LOWERCASE.equals(command))
|
||||
inputField.setText(inputField.getText().toLowerCase());
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
BlueJ example project "appletdemo"
|
||||
|
||||
Copyright (c) Bruce Quig, Michael K<>lling, Monash University, 1999-2000
|
||||
|
||||
This project is distributed with the BlueJ distribution as an example of an
|
||||
applet.
|
||||
|
||||
To start this applet, choose "Run Applet" from the class's popup menu and
|
||||
click OK in the following dialogue.
|
17
Semester 1/Programming 1/Java/examples/appletdemo/bluej.pkg
Normal file
17
Semester 1/Programming 1/Java/examples/appletdemo/bluej.pkg
Normal file
@@ -0,0 +1,17 @@
|
||||
#BlueJ package file
|
||||
package.editor.height=234
|
||||
package.editor.width=358
|
||||
package.editor.x=20
|
||||
package.editor.y=42
|
||||
package.numDependencies=0
|
||||
package.numTargets=1
|
||||
target1.appletHeight=250
|
||||
target1.appletWidth=250
|
||||
target1.height=60
|
||||
target1.modifiers=0
|
||||
target1.name=CaseConverter
|
||||
target1.numberAppletParameters=0
|
||||
target1.type=AppletTarget
|
||||
target1.width=110
|
||||
target1.x=90
|
||||
target1.y=80
|
33
Semester 1/Programming 1/Java/examples/debugdemo/Car.java
Normal file
33
Semester 1/Programming 1/Java/examples/debugdemo/Car.java
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Class Car - nonsense class for debugger demo
|
||||
*
|
||||
* @author Michael Kolling
|
||||
* @version 13 August 1999
|
||||
*/
|
||||
public class Car
|
||||
{
|
||||
private int numberOfFrontSeats;
|
||||
private int numberOfBackSeats;
|
||||
|
||||
/**
|
||||
* Create a car with seat numbers
|
||||
*/
|
||||
public Car(int frontSeats, int backSeats)
|
||||
{
|
||||
numberOfFrontSeats = frontSeats;
|
||||
numberOfBackSeats = backSeats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of seats in the car.
|
||||
*/
|
||||
public int seats()
|
||||
{
|
||||
int totalSeats;
|
||||
|
||||
totalSeats = numberOfFrontSeats;
|
||||
totalSeats += numberOfBackSeats;
|
||||
|
||||
return totalSeats;
|
||||
}
|
||||
}
|
61
Semester 1/Programming 1/Java/examples/debugdemo/Demo.java
Normal file
61
Semester 1/Programming 1/Java/examples/debugdemo/Demo.java
Normal file
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Class Demo - this class is used in the BlueJ tutorial for demonstrating
|
||||
* the BlueJ debug functionality. It contains loops and nested method calls
|
||||
* that make interesting examples to set breakpoints.
|
||||
*
|
||||
* @author M. Kolling
|
||||
* @version 13 August 1999
|
||||
*/
|
||||
public class Demo
|
||||
{
|
||||
private String name;
|
||||
private int answer;
|
||||
|
||||
/**
|
||||
* Constructor for objects of class Demo
|
||||
*/
|
||||
public Demo()
|
||||
{
|
||||
name = "Marvin";
|
||||
answer = 42;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loop for a while and do some meaningless computations.
|
||||
*/
|
||||
public int loop(int count)
|
||||
{
|
||||
int sum = 17;
|
||||
|
||||
for (int i=0; i<count; i++) {
|
||||
sum = sum + i;
|
||||
sum = sum - 2;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for demonstrating single stepping with nested method call.
|
||||
*/
|
||||
public int carTest()
|
||||
{
|
||||
int places;
|
||||
Car myCar = new Car(2, 3);
|
||||
|
||||
places = myCar.seats();
|
||||
return places;
|
||||
}
|
||||
|
||||
public int longloop()
|
||||
{
|
||||
int sum = 0;
|
||||
|
||||
for (int i=0; i<20000000; i++) {
|
||||
sum = sum + i;
|
||||
sum = sum -200;
|
||||
}
|
||||
return 42;
|
||||
}
|
||||
|
||||
|
||||
}
|
12
Semester 1/Programming 1/Java/examples/debugdemo/README.TXT
Normal file
12
Semester 1/Programming 1/Java/examples/debugdemo/README.TXT
Normal file
@@ -0,0 +1,12 @@
|
||||
BlueJ example project "debugdemo"
|
||||
|
||||
Copyright (c) Michael Kolling, Monash University, 1999-2000
|
||||
|
||||
This project is distributed with the BlueJ system to provide an example
|
||||
for testing the debugger. The project does not make any sense at all. Its
|
||||
purpose is to provide some loops and method calls to practice setting
|
||||
breakpoints and sigle-stepping through the code.
|
||||
|
||||
This project is referred to in the BlueJ tutorial.
|
||||
|
||||
To start this project, create a "Demo" object and select any of its methods.
|
24
Semester 1/Programming 1/Java/examples/debugdemo/bluej.pkg
Normal file
24
Semester 1/Programming 1/Java/examples/debugdemo/bluej.pkg
Normal file
@@ -0,0 +1,24 @@
|
||||
#BlueJ package file
|
||||
dependency1.from=Demo
|
||||
dependency1.to=Car
|
||||
dependency1.type=UsesDependency
|
||||
package.editor.height=250
|
||||
package.editor.width=468
|
||||
package.editor.x=40
|
||||
package.editor.y=62
|
||||
package.numDependencies=1
|
||||
package.numTargets=2
|
||||
target1.height=50
|
||||
target1.modifiers=0
|
||||
target1.name=Demo
|
||||
target1.type=ClassTarget
|
||||
target1.width=80
|
||||
target1.x=70
|
||||
target1.y=40
|
||||
target2.height=50
|
||||
target2.modifiers=0
|
||||
target2.name=Car
|
||||
target2.type=ClassTarget
|
||||
target2.width=80
|
||||
target2.x=220
|
||||
target2.y=100
|
@@ -0,0 +1,89 @@
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* This is a little demo showing how to read text files. It will find files
|
||||
* that are situated anywhere in the classpath.
|
||||
*
|
||||
* Currently, two demo methods are available. Both simply print a text file to the
|
||||
* terminal. One returns exceptions in case of a problem, the other prints out
|
||||
* error messages.
|
||||
*
|
||||
* @author Michael K<>lling
|
||||
* @version 1.0 (19. Feb 2002)
|
||||
*/
|
||||
public class FileReader
|
||||
{
|
||||
/**
|
||||
* Create a file reader
|
||||
*/
|
||||
public FileReader()
|
||||
{
|
||||
// nothing to do...
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the contents of the file 'fileName' on standard out (the text terminal).
|
||||
*
|
||||
* @param fileName The name of the file to show
|
||||
* @throws IOException if the file could not be opened
|
||||
*/
|
||||
public void showFile(String fileName)
|
||||
throws IOException
|
||||
{
|
||||
InputStream fstream = openFile(fileName);
|
||||
|
||||
// wrap the stream into an InputStreamReader, so that we read characters
|
||||
// rather than bytes (important for non-ascii characters); then wrap it into
|
||||
// a BufferedReader, so that we can read lines, rather than single characters
|
||||
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(fstream));
|
||||
|
||||
// okay, we're ready to go...
|
||||
|
||||
System.out.println("File: " + fileName);
|
||||
String line = in.readLine();
|
||||
while(line != null) {
|
||||
System.out.println(line);
|
||||
line = in.readLine();
|
||||
}
|
||||
System.out.println("<end of file>");
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as 'showfile', but don't throw exceptions. If an error occurs,
|
||||
* write an error message to the terminal.
|
||||
*
|
||||
* @param fileName The name of the file to show
|
||||
*/
|
||||
public void checkedShowFile(String fileName)
|
||||
{
|
||||
try {
|
||||
showFile(fileName);
|
||||
}
|
||||
catch(IOException exc) {
|
||||
System.out.println("There was a problem showing this file.");
|
||||
System.out.println("The error encountered is:");
|
||||
System.out.println(exc);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a text file and return a stream to read from that file.
|
||||
* The file can reside anywhere in the classpath.
|
||||
*
|
||||
* @param fileName The name of the file to open
|
||||
* @return An open stream to read from the file
|
||||
* @throws IOException if the file could not be opened
|
||||
*/
|
||||
public InputStream openFile(String fileName)
|
||||
throws IOException
|
||||
{
|
||||
if(fileName == null)
|
||||
throw new IOException("Cannot open file - filename was null.");
|
||||
URL url = getClass().getClassLoader().getResource(fileName);
|
||||
if(url == null)
|
||||
throw new IOException("File not found: " + fileName);
|
||||
return url.openStream();
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
This is a small demo showing how to access a file in a safe way.
|
||||
Especially: access to the file does not depend on the current directory,
|
||||
but files will be found anywhere in the classpath. So text files placed
|
||||
inside the project directory wll be found.
|
||||
|
||||
A file for testing is include in this project. It is called "test.txt".
|
||||
(You can also access this file - "README.TXT".)
|
||||
|
||||
-mik-, Feb 2002
|
14
Semester 1/Programming 1/Java/examples/file-reader/bluej.pkg
Normal file
14
Semester 1/Programming 1/Java/examples/file-reader/bluej.pkg
Normal file
@@ -0,0 +1,14 @@
|
||||
#BlueJ package file
|
||||
package.editor.height=300
|
||||
package.editor.width=420
|
||||
package.editor.x=40
|
||||
package.editor.y=62
|
||||
package.numDependencies=0
|
||||
package.numTargets=1
|
||||
target1.height=50
|
||||
target1.modifiers=0
|
||||
target1.name=FileReader
|
||||
target1.type=ClassTarget
|
||||
target1.width=90
|
||||
target1.x=140
|
||||
target1.y=70
|
@@ -0,0 +1 @@
|
||||
This is a plain text file.
|
24
Semester 1/Programming 1/Java/examples/hello/Hello.java
Normal file
24
Semester 1/Programming 1/Java/examples/hello/Hello.java
Normal file
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Class Hello:
|
||||
*
|
||||
* Hello-world program to demonstrate BlueJ.
|
||||
*/
|
||||
class Hello
|
||||
{
|
||||
/**
|
||||
* Method that does the work
|
||||
*/
|
||||
public void go()
|
||||
{
|
||||
System.out.println("Hello, world");
|
||||
}
|
||||
|
||||
/**
|
||||
* main method for testing outside BlueJ
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
Hello hi = new Hello();
|
||||
hi.go();
|
||||
}
|
||||
}
|
20
Semester 1/Programming 1/Java/examples/hello/README.TXT
Normal file
20
Semester 1/Programming 1/Java/examples/hello/README.TXT
Normal file
@@ -0,0 +1,20 @@
|
||||
BlueJ example project "hello"
|
||||
|
||||
Copyright (c) Michael K<>lling, Monash University, 1999-2000
|
||||
|
||||
This is "Hello world".
|
||||
|
||||
This project is distributed with the BlueJ system to make all those people
|
||||
happy who want to look at "Hello World" before anything else.
|
||||
|
||||
Please note that I think that this project is totally unsuitable to learn
|
||||
or teach anything about object-orientation. There is no sensible use of
|
||||
objects in this problem, and I do not recommend using it for teaching OO.
|
||||
|
||||
You can start this project in two ways:
|
||||
|
||||
- create a "Hello" object and run its "go" method, or
|
||||
- execute the static "main" method of the "Hello" class
|
||||
|
||||
|
||||
Michael K<>lling, August 2000
|
14
Semester 1/Programming 1/Java/examples/hello/bluej.pkg
Normal file
14
Semester 1/Programming 1/Java/examples/hello/bluej.pkg
Normal file
@@ -0,0 +1,14 @@
|
||||
#BlueJ package file
|
||||
package.editor.height=239
|
||||
package.editor.width=352
|
||||
package.editor.x=60
|
||||
package.editor.y=82
|
||||
package.numDependencies=0
|
||||
package.numTargets=1
|
||||
target1.height=50
|
||||
target1.modifiers=1
|
||||
target1.name=Hello
|
||||
target1.type=ClassTarget
|
||||
target1.width=80
|
||||
target1.x=90
|
||||
target1.y=60
|
BIN
Semester 1/Programming 1/Java/examples/people/Database.class
Normal file
BIN
Semester 1/Programming 1/Java/examples/people/Database.class
Normal file
Binary file not shown.
@@ -0,0 +1,9 @@
|
||||
#BlueJ class context
|
||||
comment0.target=Database()
|
||||
comment0.text=\nCreate\ a\ new,\ empty\ person\ database.\n\n
|
||||
comment1.params=p
|
||||
comment1.target=void\ addPerson(Person)
|
||||
comment1.text=\nAdd\ a\ person\ to\ the\ database.\n\n
|
||||
comment2.target=void\ listAll()
|
||||
comment2.text=\nList\ all\ the\ persons\ currently\ in\ the\ database\ on\ standard\ out.\n\n
|
||||
numComments=3
|
43
Semester 1/Programming 1/Java/examples/people/Database.java
Normal file
43
Semester 1/Programming 1/Java/examples/people/Database.java
Normal file
@@ -0,0 +1,43 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* A very simple database of people in a university. This class simply stores
|
||||
* persons and, at request, lists them on standard output.
|
||||
*
|
||||
* Written as a first demo program for BlueJ.
|
||||
*
|
||||
* @author Michael Kolling
|
||||
* @version 1.1, March 2002
|
||||
*/
|
||||
|
||||
public class Database {
|
||||
|
||||
private ArrayList persons;
|
||||
|
||||
/**
|
||||
* Create a new, empty person database.
|
||||
*/
|
||||
public Database()
|
||||
{
|
||||
persons = new ArrayList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a person to the database.
|
||||
*/
|
||||
public void addPerson(Person p)
|
||||
{
|
||||
persons.add(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* List all the persons currently in the database on standard out.
|
||||
*/
|
||||
public void listAll ()
|
||||
{
|
||||
for (Iterator i = persons.iterator(); i.hasNext();) {
|
||||
System.out.println(i.next());
|
||||
}
|
||||
}
|
||||
}
|
BIN
Semester 1/Programming 1/Java/examples/people/Person.class
Normal file
BIN
Semester 1/Programming 1/Java/examples/people/Person.class
Normal file
Binary file not shown.
17
Semester 1/Programming 1/Java/examples/people/Person.ctxt
Normal file
17
Semester 1/Programming 1/Java/examples/people/Person.ctxt
Normal file
@@ -0,0 +1,17 @@
|
||||
#BlueJ class context
|
||||
comment0.params=name\ yearOfBirth
|
||||
comment0.target=Person(String,\ int)
|
||||
comment0.text=\nCreate\ a\ person\ with\ given\ name\ and\ age.\n\n
|
||||
comment1.params=newName
|
||||
comment1.target=void\ setName(String)
|
||||
comment1.text=\nSet\ a\ new\ name\ for\ this\ person.\n\n
|
||||
comment2.target=String\ getName()
|
||||
comment2.text=\nReturn\ the\ name\ of\ this\ person.\n\n
|
||||
comment3.params=newYearOofBirth
|
||||
comment3.target=void\ setYearOfBirth(int)
|
||||
comment3.text=\nSet\ a\ new\ birth\ year\ for\ this\ person.\n\n
|
||||
comment4.target=int\ getYearOfBirth()
|
||||
comment4.text=\nReturn\ the\ birth\ year\ of\ this\ person.\n\n
|
||||
comment5.target=String\ toString()
|
||||
comment5.text=\nReturn\ a\ string\ representation\ of\ this\ object.\n\n
|
||||
numComments=6
|
63
Semester 1/Programming 1/Java/examples/people/Person.java
Normal file
63
Semester 1/Programming 1/Java/examples/people/Person.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* A person class for a simple BlueJ demo program. Person is used as
|
||||
* an abstract superclass of more specific person classes.
|
||||
*
|
||||
* @author Michael Kolling
|
||||
* @version 1.0, January 1999
|
||||
*/
|
||||
|
||||
abstract class Person
|
||||
{
|
||||
private String name;
|
||||
private int yearOfBirth;
|
||||
|
||||
/**
|
||||
* Create a person with given name and age.
|
||||
*/
|
||||
Person(String name, int yearOfBirth)
|
||||
{
|
||||
this.name = name;
|
||||
this.yearOfBirth = yearOfBirth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a new name for this person.
|
||||
*/
|
||||
public void setName(String newName)
|
||||
{
|
||||
name = newName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of this person.
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a new birth year for this person.
|
||||
*/
|
||||
public void setYearOfBirth(int newYearOofBirth)
|
||||
{
|
||||
yearOfBirth = newYearOofBirth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the birth year of this person.
|
||||
*/
|
||||
public int getYearOfBirth()
|
||||
{
|
||||
return yearOfBirth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string representation of this object.
|
||||
*/
|
||||
public String toString() // redefined from "Object"
|
||||
{
|
||||
return "Name: " + name + "\n" +
|
||||
"Year of birth: " + yearOfBirth + "\n";
|
||||
}
|
||||
}
|
29
Semester 1/Programming 1/Java/examples/people/README.TXT
Normal file
29
Semester 1/Programming 1/Java/examples/people/README.TXT
Normal file
@@ -0,0 +1,29 @@
|
||||
BlueJ example project "people"
|
||||
|
||||
Copyright (c) Michael K<>lling, Monash University, 1999-2000
|
||||
|
||||
This is a very simple BlueJ demo project. It illustrates some aspects of
|
||||
object-orientation as well as aspects of BlueJ.
|
||||
|
||||
This project is distributed with the BlueJ system to serve as an introductory
|
||||
practice example. It is referred to in the BlueJ tutorial. Please read the
|
||||
tutorial (which you can get by selecting "BlueJ Tutorial..." from the Help
|
||||
menu ion the BlueJ main window) for more detailed information.
|
||||
|
||||
You can use this project as follows:
|
||||
|
||||
- create a few Staff or Student obejcts
|
||||
- create a Database object
|
||||
- use "addPerson" in Database to add the persons you have created previously
|
||||
from the object bench to the database
|
||||
- use the "listAll" from the database object to list the contents of the
|
||||
database.
|
||||
|
||||
This project illustrates:
|
||||
|
||||
- object creation
|
||||
- relationship class-object (create _more then one_ object!)
|
||||
- instance data (use "Inspect" on the objects)
|
||||
- methods, parameters
|
||||
- composition
|
||||
- ...
|
BIN
Semester 1/Programming 1/Java/examples/people/Staff.class
Normal file
BIN
Semester 1/Programming 1/Java/examples/people/Staff.class
Normal file
Binary file not shown.
14
Semester 1/Programming 1/Java/examples/people/Staff.ctxt
Normal file
14
Semester 1/Programming 1/Java/examples/people/Staff.ctxt
Normal file
@@ -0,0 +1,14 @@
|
||||
#BlueJ class context
|
||||
comment0.target=Staff()
|
||||
comment0.text=\nCreate\ a\ staff\ member\ with\ default\ settings\ for\ detail\ information.\n\n
|
||||
comment1.params=name\ yearOfBirth\ roomNumber
|
||||
comment1.target=Staff(String,\ int,\ String)
|
||||
comment1.text=\nCreate\ a\ staff\ member\ with\ given\ name,\ year\ of\ birth\ and\ room\nnumber.\n\n
|
||||
comment2.params=newRoom
|
||||
comment2.target=void\ setRoom(String)
|
||||
comment2.text=\nSet\ a\ new\ room\ number\ for\ this\ person.\n\n
|
||||
comment3.target=String\ getRoom()
|
||||
comment3.text=\nReturn\ the\ room\ number\ of\ this\ person.\n\n
|
||||
comment4.target=String\ toString()
|
||||
comment4.text=\nReturn\ a\ string\ representation\ of\ this\ object.\n\n
|
||||
numComments=5
|
56
Semester 1/Programming 1/Java/examples/people/Staff.java
Normal file
56
Semester 1/Programming 1/Java/examples/people/Staff.java
Normal file
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* A class representing staff members for a simple BlueJ demo program.
|
||||
*
|
||||
* @author Michael Kolling
|
||||
* @version 1.0, January 1999
|
||||
*/
|
||||
class Staff extends Person
|
||||
{
|
||||
private String room;
|
||||
|
||||
/**
|
||||
* Create a staff member with default settings for detail information.
|
||||
*/
|
||||
Staff()
|
||||
{
|
||||
super("(unknown name)", 0000);
|
||||
room = "(unknown room)";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a staff member with given name, year of birth and room
|
||||
* number.
|
||||
*/
|
||||
Staff(String name, int yearOfBirth, String roomNumber)
|
||||
{
|
||||
super(name, yearOfBirth);
|
||||
room = roomNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a new room number for this person.
|
||||
*/
|
||||
public void setRoom(String newRoom)
|
||||
{
|
||||
room = newRoom;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the room number of this person.
|
||||
*/
|
||||
public String getRoom()
|
||||
{
|
||||
return room;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string representation of this object.
|
||||
*/
|
||||
public String toString() // redefined from "Person"
|
||||
{
|
||||
return super.toString() +
|
||||
"Staff member\n" +
|
||||
"Room: " + room + "\n";
|
||||
}
|
||||
}
|
||||
|
BIN
Semester 1/Programming 1/Java/examples/people/Student.class
Normal file
BIN
Semester 1/Programming 1/Java/examples/people/Student.class
Normal file
Binary file not shown.
11
Semester 1/Programming 1/Java/examples/people/Student.ctxt
Normal file
11
Semester 1/Programming 1/Java/examples/people/Student.ctxt
Normal file
@@ -0,0 +1,11 @@
|
||||
#BlueJ class context
|
||||
comment0.target=Student()
|
||||
comment0.text=\nCreate\ a\ student\ with\ default\ settings\ for\ detail\ information.\n\n
|
||||
comment1.params=name\ yearOfBirth\ studentID
|
||||
comment1.target=Student(String,\ int,\ String)
|
||||
comment1.text=\nCreate\ a\ student\ with\ given\ name,\ year\ of\ birth\ and\ student\ ID\n\n
|
||||
comment2.target=String\ getStudentID()
|
||||
comment2.text=\nReturn\ the\ student\ ID\ of\ this\ student.\n\n
|
||||
comment3.target=String\ toString()
|
||||
comment3.text=\nReturn\ a\ string\ representation\ of\ this\ object.\n\n
|
||||
numComments=4
|
52
Semester 1/Programming 1/Java/examples/people/Student.java
Normal file
52
Semester 1/Programming 1/Java/examples/people/Student.java
Normal file
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* A class representing students for a simple BlueJ demo program.
|
||||
*
|
||||
* @author Michael Kolling
|
||||
* @version 1.0, January 1999
|
||||
*/
|
||||
|
||||
class Student extends Person
|
||||
{
|
||||
private String SID; // student ID number
|
||||
|
||||
/**
|
||||
* Create a student with default settings for detail information.
|
||||
*/
|
||||
|
||||
Student()
|
||||
{
|
||||
super("(unknown name)", 0000);
|
||||
SID = "(unknown ID)";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a student with given name, year of birth and student ID
|
||||
*/
|
||||
Student(String name, int yearOfBirth, String studentID)
|
||||
{
|
||||
super(name, yearOfBirth);
|
||||
SID = studentID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the student ID of this student.
|
||||
*/
|
||||
public String getStudentID()
|
||||
{
|
||||
return SID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string representation of this object.
|
||||
*/
|
||||
public String toString() // redefined from "Person"
|
||||
{
|
||||
return super.toString() +
|
||||
"Student\n" +
|
||||
"Student ID: " + SID + "\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
40
Semester 1/Programming 1/Java/examples/people/bluej.pkg
Normal file
40
Semester 1/Programming 1/Java/examples/people/bluej.pkg
Normal file
@@ -0,0 +1,40 @@
|
||||
#BlueJ package file
|
||||
dependency1.from=Database
|
||||
dependency1.to=Person
|
||||
dependency1.type=UsesDependency
|
||||
package.editor.height=292
|
||||
package.editor.width=427
|
||||
package.editor.x=508
|
||||
package.editor.y=119
|
||||
package.numDependencies=1
|
||||
package.numTargets=4
|
||||
package.showExtends=true
|
||||
package.showUses=true
|
||||
target1.height=50
|
||||
target1.name=Student
|
||||
target1.showInterface=false
|
||||
target1.type=ClassTarget
|
||||
target1.width=80
|
||||
target1.x=230
|
||||
target1.y=190
|
||||
target2.height=50
|
||||
target2.name=Staff
|
||||
target2.showInterface=false
|
||||
target2.type=ClassTarget
|
||||
target2.width=80
|
||||
target2.x=110
|
||||
target2.y=190
|
||||
target3.height=50
|
||||
target3.name=Database
|
||||
target3.showInterface=false
|
||||
target3.type=ClassTarget
|
||||
target3.width=80
|
||||
target3.x=70
|
||||
target3.y=20
|
||||
target4.height=50
|
||||
target4.name=Person
|
||||
target4.showInterface=false
|
||||
target4.type=AbstractTarget
|
||||
target4.width=80
|
||||
target4.x=170
|
||||
target4.y=90
|
@@ -0,0 +1,3 @@
|
||||
#Submitter per project properties
|
||||
#Wed Nov 22 13:05:44 EST 2006
|
||||
selectedNode=Submission by email
|
42
Semester 1/Programming 1/Java/examples/people2/Address.java
Normal file
42
Semester 1/Programming 1/Java/examples/people2/Address.java
Normal file
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Class Address - used to store address details for a post address
|
||||
*
|
||||
* @author Michael Kolling
|
||||
* @version 1.0, January 1999
|
||||
*/
|
||||
public class Address
|
||||
{
|
||||
private String street;
|
||||
private String town;
|
||||
private String postCode;
|
||||
private String country;
|
||||
|
||||
/**
|
||||
* Construct an Address without country
|
||||
*/
|
||||
public Address(String street, String town, String postCode)
|
||||
{
|
||||
this(street, town, postCode, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an Address with full details
|
||||
*/
|
||||
public Address(String street, String town, String postCode, String country)
|
||||
{
|
||||
this.street = street;
|
||||
this.town = town;
|
||||
this.postCode = postCode;
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string representation of this object.
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return street + "\n" +
|
||||
town + " " + postCode + "\n" +
|
||||
country + "\n";
|
||||
}
|
||||
}
|
43
Semester 1/Programming 1/Java/examples/people2/Database.java
Normal file
43
Semester 1/Programming 1/Java/examples/people2/Database.java
Normal file
@@ -0,0 +1,43 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* A very simple database of people in a university. This class simply stores
|
||||
* persons and, at request, lists them on standard output.
|
||||
*
|
||||
* Written as a first demo program for BlueJ.
|
||||
*
|
||||
* @author Michael Kolling
|
||||
* @version 1.1, March 2002
|
||||
*/
|
||||
|
||||
public class Database {
|
||||
|
||||
private ArrayList persons;
|
||||
|
||||
/**
|
||||
* Create a new, empty person database.
|
||||
*/
|
||||
public Database()
|
||||
{
|
||||
persons = new ArrayList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a person to the database.
|
||||
*/
|
||||
public void addPerson(Person p)
|
||||
{
|
||||
persons.add(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* List all the persons currently in the database on standard out.
|
||||
*/
|
||||
public void listAll ()
|
||||
{
|
||||
for (Iterator i = persons.iterator(); i.hasNext();) {
|
||||
System.out.println(i.next());
|
||||
}
|
||||
}
|
||||
}
|
80
Semester 1/Programming 1/Java/examples/people2/Person.java
Normal file
80
Semester 1/Programming 1/Java/examples/people2/Person.java
Normal file
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* A person class for a simple BlueJ demo program. Person is used as
|
||||
* an abstract superclass of more specific person classes.
|
||||
*
|
||||
* @author Michael Kolling
|
||||
* @version 1.0, January 1999
|
||||
*/
|
||||
|
||||
abstract class Person
|
||||
{
|
||||
private String name;
|
||||
private int yearOfBirth;
|
||||
private Address address;
|
||||
|
||||
/**
|
||||
* Create a person with given name and age.
|
||||
*/
|
||||
Person(String name, int yearOfBirth)
|
||||
{
|
||||
this.name = name;
|
||||
this.yearOfBirth = yearOfBirth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a new name for this person.
|
||||
*/
|
||||
public void setName(String newName)
|
||||
{
|
||||
name = newName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of this person.
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a new birth year for this person.
|
||||
*/
|
||||
public void setYearOfBirth(int newYearOfBirth)
|
||||
{
|
||||
yearOfBirth = newYearOfBirth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the birth year of this person.
|
||||
*/
|
||||
public int getYearOfBirth()
|
||||
{
|
||||
return yearOfBirth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a new address for this person.
|
||||
*/
|
||||
public void setAddress(String street, String town, String postCode)
|
||||
{
|
||||
address = new Address(street, town, postCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the address of this person.
|
||||
*/
|
||||
public Address getAddress()
|
||||
{
|
||||
return address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string representation of this object.
|
||||
*/
|
||||
public String toString() // redefined from "Object"
|
||||
{
|
||||
return "Name: " + name + "\n" +
|
||||
"Year of birth: " + yearOfBirth + "\n";
|
||||
}
|
||||
}
|
13
Semester 1/Programming 1/Java/examples/people2/README.TXT
Normal file
13
Semester 1/Programming 1/Java/examples/people2/README.TXT
Normal file
@@ -0,0 +1,13 @@
|
||||
BlueJ example project "people2"
|
||||
|
||||
Copyright (c) Michael K<>lling, Monash University, 1999-2000
|
||||
|
||||
This is a very simple BlueJ demo project. It illustrates some aspects of
|
||||
object-orientation as well as aspects of BlueJ.
|
||||
|
||||
This project is an extension of "people". It is identical to "people"
|
||||
except for the addition of an "Address" class and an address attribute
|
||||
in Person.
|
||||
|
||||
This project may be used to study object creation and method calls from
|
||||
within other object (non-interactive).
|
58
Semester 1/Programming 1/Java/examples/people2/Staff.java
Normal file
58
Semester 1/Programming 1/Java/examples/people2/Staff.java
Normal file
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* A class representing staff members for a simple BlueJ demo program.
|
||||
*
|
||||
* @author Michael Kolling
|
||||
* @version 1.0, January 1999
|
||||
*/
|
||||
|
||||
class Staff extends Person
|
||||
{
|
||||
private String room;
|
||||
|
||||
/**
|
||||
* Create a staff member with default settings for detail information.
|
||||
*/
|
||||
Staff()
|
||||
{
|
||||
super("(unknown name)", 0000);
|
||||
room = "(unknown room)";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a staff member with given name, year of birth and room
|
||||
* number.
|
||||
*/
|
||||
Staff(String name, int yearOfBirth, String roomNumber)
|
||||
{
|
||||
super(name, yearOfBirth);
|
||||
room = roomNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a new room number for this person.
|
||||
*/
|
||||
public void setRoom(String newRoom)
|
||||
{
|
||||
room = newRoom;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the room number of this person.
|
||||
*/
|
||||
public String getRoom()
|
||||
{
|
||||
return room;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string representation of this object.
|
||||
*/
|
||||
public String toString() // redefined from "Person"
|
||||
{
|
||||
return super.toString() +
|
||||
"Staff member\n" +
|
||||
"Room: " + room + "\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
47
Semester 1/Programming 1/Java/examples/people2/Student.java
Normal file
47
Semester 1/Programming 1/Java/examples/people2/Student.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* A class representing students for a simple BlueJ demo program.
|
||||
*
|
||||
* @author Michael Kolling
|
||||
* @version 1.0, January 1999
|
||||
*/
|
||||
class Student extends Person
|
||||
{
|
||||
private String SID; // student ID number
|
||||
|
||||
/**
|
||||
* Create a student with default settings for detail information.
|
||||
*/
|
||||
public Student()
|
||||
{
|
||||
super("(unknown name)", 0000);
|
||||
SID = "(unknown ID)";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a student with given name, year of birth and student ID
|
||||
*/
|
||||
public Student(String name, int yearOfBirth, String studentID)
|
||||
{
|
||||
super(name, yearOfBirth);
|
||||
SID = studentID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the stident ID of this student.
|
||||
*/
|
||||
public String getStudentID()
|
||||
{
|
||||
return SID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string representation of this object.
|
||||
*/
|
||||
public String toString() // redefined from "Person"
|
||||
{
|
||||
return super.toString() +
|
||||
"Student\n" +
|
||||
"Student ID: " + SID + "\n";
|
||||
}
|
||||
}
|
||||
|
48
Semester 1/Programming 1/Java/examples/people2/bluej.pkg
Normal file
48
Semester 1/Programming 1/Java/examples/people2/bluej.pkg
Normal file
@@ -0,0 +1,48 @@
|
||||
#BlueJ package file
|
||||
dependency1.from=Person
|
||||
dependency1.to=Address
|
||||
dependency1.type=UsesDependency
|
||||
dependency2.from=Database
|
||||
dependency2.to=Person
|
||||
dependency2.type=UsesDependency
|
||||
package.editor.height=308
|
||||
package.editor.width=445
|
||||
package.editor.x=60
|
||||
package.editor.y=82
|
||||
package.numDependencies=2
|
||||
package.numTargets=5
|
||||
target1.height=50
|
||||
target1.modifiers=0
|
||||
target1.name=Student
|
||||
target1.type=ClassTarget
|
||||
target1.width=80
|
||||
target1.x=260
|
||||
target1.y=220
|
||||
target2.height=50
|
||||
target2.modifiers=400
|
||||
target2.name=Person
|
||||
target2.type=ClassTarget
|
||||
target2.width=80
|
||||
target2.x=190
|
||||
target2.y=110
|
||||
target3.height=50
|
||||
target3.modifiers=0
|
||||
target3.name=Staff
|
||||
target3.type=ClassTarget
|
||||
target3.width=80
|
||||
target3.x=130
|
||||
target3.y=220
|
||||
target4.height=50
|
||||
target4.modifiers=0
|
||||
target4.name=Database
|
||||
target4.type=ClassTarget
|
||||
target4.width=80
|
||||
target4.x=60
|
||||
target4.y=40
|
||||
target5.height=50
|
||||
target5.modifiers=0
|
||||
target5.name=Address
|
||||
target5.type=ClassTarget
|
||||
target5.width=80
|
||||
target5.x=300
|
||||
target5.y=20
|
221
Semester 1/Programming 1/Java/examples/picture/Canvas.java
Normal file
221
Semester 1/Programming 1/Java/examples/picture/Canvas.java
Normal file
@@ -0,0 +1,221 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Canvas is a class to allow for simple graphical drawing on a canvas.
|
||||
* This is a modification of the general purpose Canvas, specially made for
|
||||
* the BlueJ "shapes" example.
|
||||
*
|
||||
* @author: Bruce Quig
|
||||
* @author: Michael Kolling (mik)
|
||||
*
|
||||
* @version: 1.6 (shapes)
|
||||
*/
|
||||
public class Canvas
|
||||
{
|
||||
// Note: The implementation of this class (specifically the handling of
|
||||
// shape identity and colors) is slightly more complex than necessary. This
|
||||
// is done on purpose to keep the interface and instance fields of the
|
||||
// shape objects in this project clean and simple for educational purposes.
|
||||
|
||||
private static Canvas canvasSingleton;
|
||||
|
||||
/**
|
||||
* Factory method to get the canvas singleton object.
|
||||
*/
|
||||
public static Canvas getCanvas()
|
||||
{
|
||||
if(canvasSingleton == null) {
|
||||
canvasSingleton = new Canvas("BlueJ Shapes Demo", 300, 300,
|
||||
Color.white);
|
||||
}
|
||||
canvasSingleton.setVisible(true);
|
||||
return canvasSingleton;
|
||||
}
|
||||
|
||||
// ----- instance part -----
|
||||
|
||||
private JFrame frame;
|
||||
private CanvasPane canvas;
|
||||
private Graphics2D graphic;
|
||||
private Color backgroundColour;
|
||||
private Image canvasImage;
|
||||
private List objects;
|
||||
private HashMap shapes;
|
||||
|
||||
/**
|
||||
* Create a Canvas.
|
||||
* @param title title to appear in Canvas Frame
|
||||
* @param width the desired width for the canvas
|
||||
* @param height the desired height for the canvas
|
||||
* @param bgClour the desired background colour of the canvas
|
||||
*/
|
||||
private Canvas(String title, int width, int height, Color bgColour)
|
||||
{
|
||||
frame = new JFrame();
|
||||
canvas = new CanvasPane();
|
||||
frame.setContentPane(canvas);
|
||||
frame.setTitle(title);
|
||||
canvas.setPreferredSize(new Dimension(width, height));
|
||||
backgroundColour = bgColour;
|
||||
frame.pack();
|
||||
objects = new ArrayList();
|
||||
shapes = new HashMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the canvas visibility and brings canvas to the front of screen
|
||||
* when made visible. This method can also be used to bring an already
|
||||
* visible canvas to the front of other windows.
|
||||
* @param visible boolean value representing the desired visibility of
|
||||
* the canvas (true or false)
|
||||
*/
|
||||
public void setVisible(boolean visible)
|
||||
{
|
||||
if(graphic == null) {
|
||||
// first time: instantiate the offscreen image and fill it with
|
||||
// the background colour
|
||||
Dimension size = canvas.getSize();
|
||||
canvasImage = canvas.createImage(size.width, size.height);
|
||||
graphic = (Graphics2D)canvasImage.getGraphics();
|
||||
graphic.setColor(backgroundColour);
|
||||
graphic.fillRect(0, 0, size.width, size.height);
|
||||
graphic.setColor(Color.black);
|
||||
}
|
||||
frame.setVisible(visible);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a given shape onto the canvas.
|
||||
* @param referenceObject an object to define identity for this shape
|
||||
* @param color the color of the shape
|
||||
* @param shape the shape object to be drawn on the canvas
|
||||
*/
|
||||
// Note: this is a slightly backwards way of maintaining the shape
|
||||
// objects. It is carefully designed to keep the visible shape interfaces
|
||||
// in this project clean and simple for educational purposes.
|
||||
public void draw(Object referenceObject, String color, Shape shape)
|
||||
{
|
||||
objects.remove(referenceObject); // just in case it was already there
|
||||
objects.add(referenceObject); // add at the end
|
||||
shapes.put(referenceObject, new ShapeDescription(shape, color));
|
||||
redraw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Erase a given shape's from the screen.
|
||||
* @param referenceObject the shape object to be erased
|
||||
*/
|
||||
public void erase(Object referenceObject)
|
||||
{
|
||||
objects.remove(referenceObject); // just in case it was already there
|
||||
shapes.remove(referenceObject);
|
||||
redraw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the foreground colour of the Canvas.
|
||||
* @param newColour the new colour for the foreground of the Canvas
|
||||
*/
|
||||
public void setForegroundColor(String colorString)
|
||||
{
|
||||
if(colorString.equals("red"))
|
||||
graphic.setColor(Color.red);
|
||||
else if(colorString.equals("black"))
|
||||
graphic.setColor(Color.black);
|
||||
else if(colorString.equals("blue"))
|
||||
graphic.setColor(Color.blue);
|
||||
else if(colorString.equals("yellow"))
|
||||
graphic.setColor(Color.yellow);
|
||||
else if(colorString.equals("green"))
|
||||
graphic.setColor(Color.green);
|
||||
else if(colorString.equals("magenta"))
|
||||
graphic.setColor(Color.magenta);
|
||||
else if(colorString.equals("white"))
|
||||
graphic.setColor(Color.white);
|
||||
else
|
||||
graphic.setColor(Color.black);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for a specified number of milliseconds before finishing.
|
||||
* This provides an easy way to specify a small delay which can be
|
||||
* used when producing animations.
|
||||
* @param milliseconds the number
|
||||
*/
|
||||
public void wait(int milliseconds)
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(milliseconds);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// ignoring exception at the moment
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Redraw ell shapes currently on the Canvas.
|
||||
*/
|
||||
private void redraw()
|
||||
{
|
||||
erase();
|
||||
for(Iterator i=objects.iterator(); i.hasNext(); ) {
|
||||
((ShapeDescription)shapes.get(i.next())).draw(graphic);
|
||||
}
|
||||
canvas.repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Erase the whole canvas. (Does not repaint.)
|
||||
*/
|
||||
private void erase()
|
||||
{
|
||||
Color original = graphic.getColor();
|
||||
graphic.setColor(backgroundColour);
|
||||
Dimension size = canvas.getSize();
|
||||
graphic.fill(new Rectangle(0, 0, size.width, size.height));
|
||||
graphic.setColor(original);
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************
|
||||
* Inner class CanvasPane - the actual canvas component contained in the
|
||||
* Canvas frame. This is essentially a JPanel with added capability to
|
||||
* refresh the image drawn on it.
|
||||
*/
|
||||
private class CanvasPane extends JPanel
|
||||
{
|
||||
public void paint(Graphics g)
|
||||
{
|
||||
g.drawImage(canvasImage, 0, 0, null);
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Inner class CanvasPane - the actual canvas component contained in the
|
||||
* Canvas frame. This is essentially a JPanel with added capability to
|
||||
* refresh the image drawn on it.
|
||||
*/
|
||||
private class ShapeDescription
|
||||
{
|
||||
private Shape shape;
|
||||
private String colorString;
|
||||
|
||||
public ShapeDescription(Shape shape, String color)
|
||||
{
|
||||
this.shape = shape;
|
||||
colorString = color;
|
||||
}
|
||||
|
||||
public void draw(Graphics2D graphic)
|
||||
{
|
||||
setForegroundColor(colorString);
|
||||
graphic.fill(shape);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
192
Semester 1/Programming 1/Java/examples/picture/Circle.java
Normal file
192
Semester 1/Programming 1/Java/examples/picture/Circle.java
Normal file
@@ -0,0 +1,192 @@
|
||||
import java.awt.*;
|
||||
import java.awt.geom.*;
|
||||
|
||||
/**
|
||||
* A circle that can be manipulated and that draws itself on a canvas.
|
||||
*
|
||||
* @author Michael Kolling and David J. Barnes
|
||||
* @version 1.0 (15 July 2000)
|
||||
*/
|
||||
|
||||
public class Circle
|
||||
{
|
||||
private int diameter;
|
||||
private int xPosition;
|
||||
private int yPosition;
|
||||
private String color;
|
||||
private boolean isVisible;
|
||||
|
||||
/**
|
||||
* Create a new circle at default position with default color.
|
||||
*/
|
||||
public Circle()
|
||||
{
|
||||
diameter = 30;
|
||||
xPosition = 20;
|
||||
yPosition = 60;
|
||||
color = "blue";
|
||||
isVisible = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make this circle visible. If it was already visible, do nothing.
|
||||
*/
|
||||
public void makeVisible()
|
||||
{
|
||||
isVisible = true;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make this circle invisible. If it was already invisible, do nothing.
|
||||
*/
|
||||
public void makeInvisible()
|
||||
{
|
||||
erase();
|
||||
isVisible = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the circle a few pixels to the right.
|
||||
*/
|
||||
public void moveRight()
|
||||
{
|
||||
moveHorizontal(20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the circle a few pixels to the left.
|
||||
*/
|
||||
public void moveLeft()
|
||||
{
|
||||
moveHorizontal(-20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the circle a few pixels up.
|
||||
*/
|
||||
public void moveUp()
|
||||
{
|
||||
moveVertical(-20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the circle a few pixels down.
|
||||
*/
|
||||
public void moveDown()
|
||||
{
|
||||
moveVertical(20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the circle horizontally by 'distance' pixels.
|
||||
*/
|
||||
public void moveHorizontal(int distance)
|
||||
{
|
||||
erase();
|
||||
xPosition += distance;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the circle vertically by 'distance' pixels.
|
||||
*/
|
||||
public void moveVertical(int distance)
|
||||
{
|
||||
erase();
|
||||
yPosition += distance;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Slowly move the circle horizontally by 'distance' pixels.
|
||||
*/
|
||||
public void slowMoveHorizontal(int distance)
|
||||
{
|
||||
int delta;
|
||||
|
||||
if(distance < 0)
|
||||
{
|
||||
delta = -1;
|
||||
distance = -distance;
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = 1;
|
||||
}
|
||||
|
||||
for(int i = 0; i < distance; i++)
|
||||
{
|
||||
xPosition += delta;
|
||||
draw();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Slowly move the circle vertically by 'distance' pixels.
|
||||
*/
|
||||
public void slowMoveVertical(int distance)
|
||||
{
|
||||
int delta;
|
||||
|
||||
if(distance < 0)
|
||||
{
|
||||
delta = -1;
|
||||
distance = -distance;
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = 1;
|
||||
}
|
||||
|
||||
for(int i = 0; i < distance; i++)
|
||||
{
|
||||
yPosition += delta;
|
||||
draw();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the size to the new size (in pixels). Size must be >= 0.
|
||||
*/
|
||||
public void changeSize(int newDiameter)
|
||||
{
|
||||
erase();
|
||||
diameter = newDiameter;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the color. Valid colors are "red", "yellow", "blue", "green",
|
||||
* "magenta" and "black".
|
||||
*/
|
||||
public void changeColor(String newColor)
|
||||
{
|
||||
color = newColor;
|
||||
draw();
|
||||
}
|
||||
|
||||
/*
|
||||
* Draw the circle with current specifications on screen.
|
||||
*/
|
||||
private void draw()
|
||||
{
|
||||
if(isVisible) {
|
||||
Canvas canvas = Canvas.getCanvas();
|
||||
canvas.draw(this, color, new Ellipse2D.Double(xPosition, yPosition,
|
||||
diameter, diameter));
|
||||
canvas.wait(10);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Erase the circle on screen.
|
||||
*/
|
||||
private void erase()
|
||||
{
|
||||
if(isVisible) {
|
||||
Canvas canvas = Canvas.getCanvas();
|
||||
canvas.erase(this);
|
||||
}
|
||||
}
|
||||
}
|
86
Semester 1/Programming 1/Java/examples/picture/Picture.java
Normal file
86
Semester 1/Programming 1/Java/examples/picture/Picture.java
Normal file
@@ -0,0 +1,86 @@
|
||||
|
||||
/**
|
||||
* This class represents a simple picture. You can draw the picture using
|
||||
* the draw method. But wait, there's more: being an electronic picture, it
|
||||
* can be changed. You can set it to black-and-white display and back to
|
||||
* colors (only after it's been drawn, of course).
|
||||
*
|
||||
* This class was written as an early example for teaching Java with BlueJ.
|
||||
*
|
||||
* @author Michael Kolling and David J. Barnes
|
||||
* @version 1.1 (24 May 2001)
|
||||
*/
|
||||
public class Picture
|
||||
{
|
||||
private Square wall;
|
||||
private Square window;
|
||||
private Triangle roof;
|
||||
private Circle sun;
|
||||
|
||||
/**
|
||||
* Constructor for objects of class Picture
|
||||
*/
|
||||
public Picture()
|
||||
{
|
||||
// nothing to do... instance variables are automatically set to null
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw this picture.
|
||||
*/
|
||||
public void draw()
|
||||
{
|
||||
wall = new Square();
|
||||
wall.moveVertical(80);
|
||||
wall.changeSize(100);
|
||||
wall.makeVisible();
|
||||
|
||||
window = new Square();
|
||||
window.changeColor("black");
|
||||
window.moveHorizontal(20);
|
||||
window.moveVertical(100);
|
||||
window.makeVisible();
|
||||
|
||||
roof = new Triangle();
|
||||
roof.changeSize(50, 140);
|
||||
roof.moveHorizontal(60);
|
||||
roof.moveVertical(70);
|
||||
roof.makeVisible();
|
||||
|
||||
sun = new Circle();
|
||||
sun.changeColor("yellow");
|
||||
sun.moveHorizontal(180);
|
||||
sun.moveVertical(-10);
|
||||
sun.changeSize(60);
|
||||
sun.makeVisible();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change this picture to black/white display
|
||||
*/
|
||||
public void setBlackAndWhite()
|
||||
{
|
||||
if(wall != null) // only if it's painted already...
|
||||
{
|
||||
wall.changeColor("black");
|
||||
window.changeColor("white");
|
||||
roof.changeColor("black");
|
||||
sun.changeColor("black");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change this picture to use color display
|
||||
*/
|
||||
public void setColor()
|
||||
{
|
||||
if(wall != null) // only if it's painted already...
|
||||
{
|
||||
wall.changeColor("red");
|
||||
window.changeColor("black");
|
||||
roof.changeColor("green");
|
||||
sun.changeColor("yellow");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
44
Semester 1/Programming 1/Java/examples/picture/README.TXT
Normal file
44
Semester 1/Programming 1/Java/examples/picture/README.TXT
Normal file
@@ -0,0 +1,44 @@
|
||||
Project "picture"
|
||||
Authors: Michael Kolling and David J. Barnes
|
||||
|
||||
This project is part of the material for the book
|
||||
|
||||
Objects First with Java - A Practical Introduction using BlueJ
|
||||
David J. Barnes and Michael Kolling
|
||||
Pearson Education, 2002
|
||||
|
||||
It is discussed in chapter 1.
|
||||
|
||||
This is a very simple project to demonstrate some characteristics of
|
||||
objects.
|
||||
|
||||
You can create various shapes, and you will see, if you do, that those
|
||||
shapes are drawn on screen (in a window that we call the "canvas").
|
||||
|
||||
You can then manipulate these objects: change their position, size and
|
||||
colour. Try it out: create a few different squares, triangles and circles.
|
||||
|
||||
This project is designed as a first example of object-oriented programming.
|
||||
It illustrates a number of concepts:
|
||||
|
||||
- a Java project (application) is a collection of classes
|
||||
- objects can be created from classes
|
||||
- from any one class, many objects may be created
|
||||
- objects have operations (methods)
|
||||
- operations can have parameters
|
||||
- parameters have types (at least String and int)
|
||||
- objects hold data (fields)
|
||||
- the operations and fields are common to all objects
|
||||
- the values stored in the fields can be different for each object
|
||||
|
||||
The project also demonstrates
|
||||
|
||||
- BlueJ object creation
|
||||
- interactive method invocation
|
||||
- parameter passing
|
||||
|
||||
A good second project to look at after this is "picture", which adds a class
|
||||
to those ones in this project. That class (named "Picture") uses the shapes
|
||||
to draw a picture. It can be used to experiment with coding.
|
||||
|
||||
Michael K<>lling, July 2000
|
191
Semester 1/Programming 1/Java/examples/picture/Square.java
Normal file
191
Semester 1/Programming 1/Java/examples/picture/Square.java
Normal file
@@ -0,0 +1,191 @@
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* A square that can be manipulated and that draws itself on a canvas.
|
||||
*
|
||||
* @author Michael Kolling and David J. Barnes
|
||||
* @version 1.0 (15 July 2000)
|
||||
*/
|
||||
|
||||
public class Square
|
||||
{
|
||||
private int size;
|
||||
private int xPosition;
|
||||
private int yPosition;
|
||||
private String color;
|
||||
private boolean isVisible;
|
||||
|
||||
/**
|
||||
* Create a new square at default position with default color.
|
||||
*/
|
||||
public Square()
|
||||
{
|
||||
size = 30;
|
||||
xPosition = 60;
|
||||
yPosition = 50;
|
||||
color = "red";
|
||||
isVisible = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make this square visible. If it was already visible, do nothing.
|
||||
*/
|
||||
public void makeVisible()
|
||||
{
|
||||
isVisible = true;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make this square invisible. If it was already invisible, do nothing.
|
||||
*/
|
||||
public void makeInvisible()
|
||||
{
|
||||
erase();
|
||||
isVisible = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the square a few pixels to the right.
|
||||
*/
|
||||
public void moveRight()
|
||||
{
|
||||
moveHorizontal(20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the square a few pixels to the left.
|
||||
*/
|
||||
public void moveLeft()
|
||||
{
|
||||
moveHorizontal(-20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the square a few pixels up.
|
||||
*/
|
||||
public void moveUp()
|
||||
{
|
||||
moveVertical(-20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the square a few pixels down.
|
||||
*/
|
||||
public void moveDown()
|
||||
{
|
||||
moveVertical(20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the square horizontally by 'distance' pixels.
|
||||
*/
|
||||
public void moveHorizontal(int distance)
|
||||
{
|
||||
erase();
|
||||
xPosition += distance;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the square vertically by 'distance' pixels.
|
||||
*/
|
||||
public void moveVertical(int distance)
|
||||
{
|
||||
erase();
|
||||
yPosition += distance;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Slowly move the square horizontally by 'distance' pixels.
|
||||
*/
|
||||
public void slowMoveHorizontal(int distance)
|
||||
{
|
||||
int delta;
|
||||
|
||||
if(distance < 0)
|
||||
{
|
||||
delta = -1;
|
||||
distance = -distance;
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = 1;
|
||||
}
|
||||
|
||||
for(int i = 0; i < distance; i++)
|
||||
{
|
||||
xPosition += delta;
|
||||
draw();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Slowly move the square vertically by 'distance' pixels.
|
||||
*/
|
||||
public void slowMoveVertical(int distance)
|
||||
{
|
||||
int delta;
|
||||
|
||||
if(distance < 0)
|
||||
{
|
||||
delta = -1;
|
||||
distance = -distance;
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = 1;
|
||||
}
|
||||
|
||||
for(int i = 0; i < distance; i++)
|
||||
{
|
||||
yPosition += delta;
|
||||
draw();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the size to the new size (in pixels). Size must be >= 0.
|
||||
*/
|
||||
public void changeSize(int newSize)
|
||||
{
|
||||
erase();
|
||||
size = newSize;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the color. Valid colors are "red", "yellow", "blue", "green",
|
||||
* "magenta" and "black".
|
||||
*/
|
||||
public void changeColor(String newColor)
|
||||
{
|
||||
color = newColor;
|
||||
draw();
|
||||
}
|
||||
|
||||
/*
|
||||
* Draw the square with current specifications on screen.
|
||||
*/
|
||||
private void draw()
|
||||
{
|
||||
if(isVisible) {
|
||||
Canvas canvas = Canvas.getCanvas();
|
||||
canvas.draw(this, color,
|
||||
new Rectangle(xPosition, yPosition, size, size));
|
||||
canvas.wait(10);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Erase the square on screen.
|
||||
*/
|
||||
private void erase()
|
||||
{
|
||||
if(isVisible) {
|
||||
Canvas canvas = Canvas.getCanvas();
|
||||
canvas.erase(this);
|
||||
}
|
||||
}
|
||||
}
|
195
Semester 1/Programming 1/Java/examples/picture/Triangle.java
Normal file
195
Semester 1/Programming 1/Java/examples/picture/Triangle.java
Normal file
@@ -0,0 +1,195 @@
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* A triangle that can be manipulated and that draws itself on a canvas.
|
||||
*
|
||||
* @author Michael Kolling and David J. Barnes
|
||||
* @version 1.0 (15 July 2000)
|
||||
*/
|
||||
|
||||
public class Triangle
|
||||
{
|
||||
private int height;
|
||||
private int width;
|
||||
private int xPosition;
|
||||
private int yPosition;
|
||||
private String color;
|
||||
private boolean isVisible;
|
||||
|
||||
/**
|
||||
* Create a new triangle at default position with default color.
|
||||
*/
|
||||
public Triangle()
|
||||
{
|
||||
height = 30;
|
||||
width = 40;
|
||||
xPosition = 50;
|
||||
yPosition = 15;
|
||||
color = "green";
|
||||
isVisible = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make this triangle visible. If it was already visible, do nothing.
|
||||
*/
|
||||
public void makeVisible()
|
||||
{
|
||||
isVisible = true;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make this triangle invisible. If it was already invisible, do nothing.
|
||||
*/
|
||||
public void makeInvisible()
|
||||
{
|
||||
erase();
|
||||
isVisible = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the triangle a few pixels to the right.
|
||||
*/
|
||||
public void moveRight()
|
||||
{
|
||||
moveHorizontal(20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the triangle a few pixels to the left.
|
||||
*/
|
||||
public void moveLeft()
|
||||
{
|
||||
moveHorizontal(-20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the triangle a few pixels up.
|
||||
*/
|
||||
public void moveUp()
|
||||
{
|
||||
moveVertical(-20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the triangle a few pixels down.
|
||||
*/
|
||||
public void moveDown()
|
||||
{
|
||||
moveVertical(20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the triangle horizontally by 'distance' pixels.
|
||||
*/
|
||||
public void moveHorizontal(int distance)
|
||||
{
|
||||
erase();
|
||||
xPosition += distance;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the triangle vertically by 'distance' pixels.
|
||||
*/
|
||||
public void moveVertical(int distance)
|
||||
{
|
||||
erase();
|
||||
yPosition += distance;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Slowly move the triangle horizontally by 'distance' pixels.
|
||||
*/
|
||||
public void slowMoveHorizontal(int distance)
|
||||
{
|
||||
int delta;
|
||||
|
||||
if(distance < 0)
|
||||
{
|
||||
delta = -1;
|
||||
distance = -distance;
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = 1;
|
||||
}
|
||||
|
||||
for(int i = 0; i < distance; i++)
|
||||
{
|
||||
xPosition += delta;
|
||||
draw();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Slowly move the triangle vertically by 'distance' pixels.
|
||||
*/
|
||||
public void slowMoveVertical(int distance)
|
||||
{
|
||||
int delta;
|
||||
|
||||
if(distance < 0)
|
||||
{
|
||||
delta = -1;
|
||||
distance = -distance;
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = 1;
|
||||
}
|
||||
|
||||
for(int i = 0; i < distance; i++)
|
||||
{
|
||||
yPosition += delta;
|
||||
draw();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the size to the new size (in pixels). Size must be >= 0.
|
||||
*/
|
||||
public void changeSize(int newHeight, int newWidth)
|
||||
{
|
||||
erase();
|
||||
height = newHeight;
|
||||
width = newWidth;
|
||||
draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the color. Valid colors are "red", "yellow", "blue", "green",
|
||||
* "magenta" and "black".
|
||||
*/
|
||||
public void changeColor(String newColor)
|
||||
{
|
||||
color = newColor;
|
||||
draw();
|
||||
}
|
||||
|
||||
/*
|
||||
* Draw the triangle with current specifications on screen.
|
||||
*/
|
||||
private void draw()
|
||||
{
|
||||
if(isVisible) {
|
||||
Canvas canvas = Canvas.getCanvas();
|
||||
int[] xpoints = { xPosition, xPosition + (width/2), xPosition - (width/2) };
|
||||
int[] ypoints = { yPosition, yPosition + height, yPosition + height };
|
||||
canvas.draw(this, color, new Polygon(xpoints, ypoints, 3));
|
||||
canvas.wait(10);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Erase the triangle on screen.
|
||||
*/
|
||||
private void erase()
|
||||
{
|
||||
if(isVisible) {
|
||||
Canvas canvas = Canvas.getCanvas();
|
||||
canvas.erase(this);
|
||||
}
|
||||
}
|
||||
}
|
70
Semester 1/Programming 1/Java/examples/picture/bluej.pkg
Normal file
70
Semester 1/Programming 1/Java/examples/picture/bluej.pkg
Normal file
@@ -0,0 +1,70 @@
|
||||
#BlueJ package file
|
||||
dependency1.from=Square
|
||||
dependency1.to=Canvas
|
||||
dependency1.type=UsesDependency
|
||||
dependency2.from=Triangle
|
||||
dependency2.to=Canvas
|
||||
dependency2.type=UsesDependency
|
||||
dependency3.from=Circle
|
||||
dependency3.to=Canvas
|
||||
dependency3.type=UsesDependency
|
||||
dependency4.from=Picture
|
||||
dependency4.to=Square
|
||||
dependency4.type=UsesDependency
|
||||
dependency5.from=Picture
|
||||
dependency5.to=Triangle
|
||||
dependency5.type=UsesDependency
|
||||
dependency6.from=Picture
|
||||
dependency6.to=Circle
|
||||
dependency6.type=UsesDependency
|
||||
objectbench.height=76
|
||||
objectbench.width=703
|
||||
package.editor.height=268
|
||||
package.editor.width=577
|
||||
package.editor.x=20
|
||||
package.editor.y=51
|
||||
package.numDependencies=6
|
||||
package.numTargets=5
|
||||
package.showExtends=true
|
||||
package.showUses=true
|
||||
project.charset=UTF-8
|
||||
target1.height=40
|
||||
target1.name=Circle
|
||||
target1.showInterface=false
|
||||
target1.type=ClassTarget
|
||||
target1.typeParameters=
|
||||
target1.width=70
|
||||
target1.x=110
|
||||
target1.y=120
|
||||
target2.height=40
|
||||
target2.name=Picture
|
||||
target2.showInterface=false
|
||||
target2.type=ClassTarget
|
||||
target2.typeParameters=
|
||||
target2.width=70
|
||||
target2.x=60
|
||||
target2.y=20
|
||||
target3.height=40
|
||||
target3.name=Canvas
|
||||
target3.showInterface=false
|
||||
target3.type=ClassTarget
|
||||
target3.typeParameters=
|
||||
target3.width=70
|
||||
target3.x=20
|
||||
target3.y=180
|
||||
target4.height=40
|
||||
target4.name=Triangle
|
||||
target4.showInterface=false
|
||||
target4.type=ClassTarget
|
||||
target4.typeParameters=
|
||||
target4.width=70
|
||||
target4.x=270
|
||||
target4.y=60
|
||||
target5.height=40
|
||||
target5.name=Square
|
||||
target5.showInterface=false
|
||||
target5.type=ClassTarget
|
||||
target5.typeParameters=
|
||||
target5.width=70
|
||||
target5.x=190
|
||||
target5.y=90
|
70
Semester 1/Programming 1/Java/examples/picture/package.bluej
Normal file
70
Semester 1/Programming 1/Java/examples/picture/package.bluej
Normal file
@@ -0,0 +1,70 @@
|
||||
#BlueJ package file
|
||||
dependency1.from=Square
|
||||
dependency1.to=Canvas
|
||||
dependency1.type=UsesDependency
|
||||
dependency2.from=Triangle
|
||||
dependency2.to=Canvas
|
||||
dependency2.type=UsesDependency
|
||||
dependency3.from=Circle
|
||||
dependency3.to=Canvas
|
||||
dependency3.type=UsesDependency
|
||||
dependency4.from=Picture
|
||||
dependency4.to=Square
|
||||
dependency4.type=UsesDependency
|
||||
dependency5.from=Picture
|
||||
dependency5.to=Triangle
|
||||
dependency5.type=UsesDependency
|
||||
dependency6.from=Picture
|
||||
dependency6.to=Circle
|
||||
dependency6.type=UsesDependency
|
||||
objectbench.height=76
|
||||
objectbench.width=703
|
||||
package.editor.height=268
|
||||
package.editor.width=577
|
||||
package.editor.x=20
|
||||
package.editor.y=51
|
||||
package.numDependencies=6
|
||||
package.numTargets=5
|
||||
package.showExtends=true
|
||||
package.showUses=true
|
||||
project.charset=UTF-8
|
||||
target1.height=40
|
||||
target1.name=Circle
|
||||
target1.showInterface=false
|
||||
target1.type=ClassTarget
|
||||
target1.typeParameters=
|
||||
target1.width=70
|
||||
target1.x=110
|
||||
target1.y=120
|
||||
target2.height=40
|
||||
target2.name=Picture
|
||||
target2.showInterface=false
|
||||
target2.type=ClassTarget
|
||||
target2.typeParameters=
|
||||
target2.width=70
|
||||
target2.x=60
|
||||
target2.y=20
|
||||
target3.height=40
|
||||
target3.name=Canvas
|
||||
target3.showInterface=false
|
||||
target3.type=ClassTarget
|
||||
target3.typeParameters=
|
||||
target3.width=70
|
||||
target3.x=20
|
||||
target3.y=180
|
||||
target4.height=40
|
||||
target4.name=Triangle
|
||||
target4.showInterface=false
|
||||
target4.type=ClassTarget
|
||||
target4.typeParameters=
|
||||
target4.width=70
|
||||
target4.x=270
|
||||
target4.y=60
|
||||
target5.height=40
|
||||
target5.name=Square
|
||||
target5.showInterface=false
|
||||
target5.type=ClassTarget
|
||||
target5.typeParameters=
|
||||
target5.width=70
|
||||
target5.x=190
|
||||
target5.y=90
|
122
Semester 1/Programming 1/Java/examples/projects/JLayer1.0.1/CHANGES.txt
Executable file
122
Semester 1/Programming 1/Java/examples/projects/JLayer1.0.1/CHANGES.txt
Executable file
@@ -0,0 +1,122 @@
|
||||
JLayer 1.0.1
|
||||
JavaZOOM 1999-2008
|
||||
|
||||
Project Homepage :
|
||||
http://www.javazoom.net/javalayer/javalayer.html
|
||||
|
||||
JAVA and MP3 online Forums :
|
||||
http://www.javazoom.net/services/forums/index.jsp
|
||||
-----------------------------------------------------
|
||||
|
||||
11/16/2008: JLayer 1.0.1
|
||||
------------------------
|
||||
- Subband allocation bug fix.
|
||||
|
||||
|
||||
11/28/2004: JLayer 1.0
|
||||
----------------------
|
||||
- VBRI frame header (Fraunhofer VBR) support added in Header.java.
|
||||
- Frame controls improved. It fixes the following bugs :
|
||||
+ ArrayIndexOutOfBound Exception in t_43[] array.
|
||||
+ ArrayIndexOutOfBound Exception in huffman_decode() method.
|
||||
- Licensing moved from GPL to LGPL : It means that you can use JLayer in
|
||||
your own application without being restricted by GPL license issues.
|
||||
It's more business friendly.
|
||||
- JavaLayer renamed into JLayer to be compliant to SUN trademark rules.
|
||||
- Tested under JRE 1.5.0. CPU usage < 1%, RAM usage < 12MB under P4/2Ghz.
|
||||
|
||||
|
||||
01/02/2004: JavaLayer 0.4
|
||||
-------------------------
|
||||
- XING VBR header frame support improved in Header.java :
|
||||
+ public boolean vbr() added.
|
||||
+ public int vbr_scale() added.
|
||||
+ public byte[] vbr_toc() added.
|
||||
total_ms(), ms_per_frame(), min_number_of_frames(int), max_number_of_frames(int),
|
||||
bitrate_string(), bitrate() methods check for VBR status.
|
||||
|
||||
- ID3v2 frames support improved :
|
||||
+ public InputStream getRawID3v2() added in Bitstream.java
|
||||
|
||||
- Misc :
|
||||
Bug fixed in the decoder for some +320kbps stream.
|
||||
Bug fixed : SYNC conflict with some ID3v2 frames.
|
||||
+ public int bitrate() added.
|
||||
+ public int bitrate_instant() added.
|
||||
jUnit tests added (see srctest/ folder)
|
||||
|
||||
|
||||
08/04/2003: JavaLayer 0.3.0
|
||||
---------------------------
|
||||
- Advanced threaded player classes added.
|
||||
|
||||
|
||||
04/01/2002: JavaLayer 0.2.0
|
||||
---------------------------
|
||||
- MPEG 2.5 support added.
|
||||
Encoded files with LAME are supported.
|
||||
- Bug fixes for ms time computation with free format.
|
||||
+ Bench notes :
|
||||
+ Heap use range : 1380KB to 1900KB - 370 classes loaded.
|
||||
+ Footprint : ~8MB under WinNT4 + J2SE 1.3 (Hotspot).
|
||||
+ CPU usage : ~12% under PIII 800Mhz/WinNT4+J2SE 1.3 (Hotspot).
|
||||
+ CPU usage : ~11% under PIII 1Ghz/Win2K+J2SE 1.4 (Hotspot).
|
||||
|
||||
|
||||
03/04/2002: JavaLayer 0.1.2
|
||||
---------------------------
|
||||
- API improved to let developers get MP3 bitrate, framelength and total time features.
|
||||
- Additionnal files added (CHANGES.txt and LICENSE.txt).
|
||||
|
||||
|
||||
10/01/2001: JavaLayer 0.1.1
|
||||
---------------------------
|
||||
- Bugs fixes in the decoder (Layer III).
|
||||
|
||||
|
||||
07/02/2001: JavaLayer 0.1.0
|
||||
---------------------------
|
||||
- Streaming support added to the simple player (jlp).
|
||||
- Bugs fixes in the simple player (too fast playback for low rate files).
|
||||
|
||||
|
||||
06/04/2001: JavaLayer 0.0.9
|
||||
---------------------------
|
||||
- Bugs fixes in Layer I and Layer II decoder.
|
||||
- ANT build script added.
|
||||
- HTML page added to play MP3 through PlayerApplet in a JavaSound 1.0 (JDK 1.3)
|
||||
compliant browser.
|
||||
|
||||
|
||||
04/16/2000: JavaLayer 0.0.8
|
||||
---------------------------
|
||||
A simple player have been added and you can now play MP3 in real time with JVM
|
||||
that supports JavaSound 1.0 (i.e JDK 1.3).
|
||||
|
||||
- Bug fixes.
|
||||
- Decoder improvements.
|
||||
- Build Scripts have been added for Win32 and Unix platforms.
|
||||
|
||||
|
||||
12/16/1999: JavaLayer 0.0.7
|
||||
---------------------------
|
||||
JavaLayer 0.0.7 contains significant improvements over version 0.0 :
|
||||
|
||||
- API and documentation added.
|
||||
- The decoder is much more faster. Fast enough for real-time decoding.
|
||||
- Huffman/Layer3 tables serialization added.
|
||||
- New buffers management.
|
||||
- Exceptions + Utils added.
|
||||
- Bugs fixes.
|
||||
|
||||
|
||||
02/28/1999: JavaLayer 0.0
|
||||
-------------------------
|
||||
JavaLayer V0.0 does not play any MP3 but it allows the MP3toWAV conversion.
|
||||
This is the first step in this project. We do it thanks to free mp3 ressources
|
||||
available on the net:
|
||||
|
||||
- MAPlay for the OO MP3 decoder (C++).
|
||||
- WAV format description from Microsoft.
|
||||
|
||||
The MP3 decoder works now but it is too slow to allow real time implementation.
|
504
Semester 1/Programming 1/Java/examples/projects/JLayer1.0.1/LICENSE.txt
Executable file
504
Semester 1/Programming 1/Java/examples/projects/JLayer1.0.1/LICENSE.txt
Executable file
@@ -0,0 +1,504 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
not price. Our General Public Licenses are designed to make sure that
|
||||
you have the freedom to distribute copies of free software (and charge
|
||||
for this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms of the
|
||||
ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library. It is
|
||||
safest to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least the
|
||||
"copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the library's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
||||
|
||||
|
81
Semester 1/Programming 1/Java/examples/projects/JLayer1.0.1/README.txt
Executable file
81
Semester 1/Programming 1/Java/examples/projects/JLayer1.0.1/README.txt
Executable file
@@ -0,0 +1,81 @@
|
||||
JLayer 1.0.1
|
||||
JavaZOOM 1999-2008
|
||||
|
||||
Project Homepage :
|
||||
http://www.javazoom.net/javalayer/javalayer.html
|
||||
|
||||
JAVA and MP3 online Forums :
|
||||
http://www.javazoom.net/services/forums/index.jsp
|
||||
-----------------------------------------------------
|
||||
|
||||
DESCRIPTION :
|
||||
-----------
|
||||
JLayer is a library that decodes/plays/converts MPEG 1/2/2.5 Layer 1/2/3
|
||||
(i.e. MP3) in real time for the JAVA(tm) platform. This is a non-commercial project
|
||||
and anyone can add his contribution. JLayer is licensed under LGPL (see LICENSE.txt).
|
||||
|
||||
|
||||
FAQ :
|
||||
---
|
||||
|
||||
- How to install JLayer ?
|
||||
Before running JLayer you must set PATH and CLASSPATH for JAVA
|
||||
and you must add jl1.0.1.jar to the CLASSPATH.
|
||||
|
||||
- Do I need JMF to run JLayer player ?
|
||||
No, JMF is not required. You just need a JVM JavaSound 1.0 compliant.
|
||||
(i.e. JVM1.3 or higher).
|
||||
|
||||
- How to run the MP3TOWAV converter ?
|
||||
java javazoom.jl.converter.jlc -v -p output.wav yourfile.mp3
|
||||
(Note : MP3TOWAV converter should work under jdk1.1.x or higher)
|
||||
|
||||
- How to run the simple MP3 player ?
|
||||
java javazoom.jl.player.jlp localfile.mp3
|
||||
or
|
||||
java javazoom.jl.player.jlp -url http://www.aserver.com/remotefile.mp3
|
||||
Note : MP3 simple player only works under JVM that supports JavaSound 1.0 (i.e JDK1.3.x+)
|
||||
|
||||
- How to run the advanced (threaded) MP3 player ?
|
||||
java javazoom.jl.player.advanced.jlap localfile.mp3
|
||||
|
||||
- Does simple MP3 player support streaming ?
|
||||
Yes, use the following command to play music from stream :
|
||||
java javazoom.jl.player.jlp -url http://www.shoutcastserver.com:8000
|
||||
(If JLayer returns without playing SHOUTcast stream then it might mean
|
||||
that the server expect a winamp like "User-Agent" in HTTP request).
|
||||
|
||||
- Does JLayer support MPEG 2.5 ?
|
||||
Yes, it works fine for all files generated with LAME.
|
||||
|
||||
- Does JLayer support VBR ?
|
||||
Yes, It supports VBRI and XING VBR header too.
|
||||
|
||||
- How to get ID3v1 or ID3v2 tags from JLayer API ?
|
||||
The API provides a getRawID3v2() method to get an InputStream on ID3v2 frames.
|
||||
|
||||
- How to skip frames to have a seek feature ?
|
||||
See javazoom.jl.player.advanced.jlap source to learn how to skip frames.
|
||||
|
||||
- How much memory/CPU JLayer needs to run ?
|
||||
Here are our benchmark notes :
|
||||
- Heap use range : 1380KB to 1900KB - 370 classes loaded.
|
||||
- Footprint : ~8MB under WinNT4/Win2K + J2SE 1.3 (Hotspot).
|
||||
~10MB under WinNT4/Win2K + J2SE 1.4.1 (Hotspot).
|
||||
- CPU usage : ~12% under PIII 800Mhz/WinNT4+J2SE 1.3 (Hotspot).
|
||||
~8% under PIII 1Ghz/Win2K+J2SE 1.3.1 (Hotspot).
|
||||
~12% under PIII 1Ghz/Win2K+J2SE 1.4.1 (Hotspot).
|
||||
~1% under PIII 1Ghz/Win2K+J2SE 1.5.0 (Hotspot).
|
||||
|
||||
- How to contact JLayer developers ?
|
||||
Try to post a thread on Java&MP3 online forums at :
|
||||
http://www.javazoom.net/services/forums/index.jsp
|
||||
You can also contact us at jlayer@javazoom.net for contributions.
|
||||
|
||||
|
||||
KNOWN PROBLEMS :
|
||||
--------------
|
||||
99% of MP3 plays well with JLayer but some (1%) return an ArrayIndexOutOfBoundsException
|
||||
while playing. It might come from invalid audio frames.
|
||||
Workaround : Just try/catch ArrayIndexOutOfBoundsException in your code to skip
|
||||
non-detected invalid frames.
|
41
Semester 1/Programming 1/Java/examples/projects/JLayer1.0.1/build-unix.sh
Executable file
41
Semester 1/Programming 1/Java/examples/projects/JLayer1.0.1/build-unix.sh
Executable file
@@ -0,0 +1,41 @@
|
||||
#!/bin/sh
|
||||
#######################################################
|
||||
# JLayer 1.0.1 Un*x Build Script
|
||||
#
|
||||
# Project Homepage :
|
||||
# http://www.javazoom.net/javalayer/javalayer.html
|
||||
#
|
||||
# Java and MP3 online Forums :
|
||||
# http://www.javazoom.net/services/forums/index.jsp
|
||||
#
|
||||
#######################################################
|
||||
|
||||
# JAVA_HOME and JL must be set below
|
||||
#JAVA_HOME=/usr/local/java/jdk1.3.1
|
||||
#JL=/home/javazoom/JLayer1.0.1
|
||||
JL=../JLayer1.0.1
|
||||
|
||||
#---------------------------
|
||||
# Do not modify lines below
|
||||
#---------------------------
|
||||
#CLASSPATH=$JAVA_HOME/lib/tools.jar
|
||||
CLASSPATH=
|
||||
#PATH=$PATH:$JAVA_HOME/bin
|
||||
JLDECODERSRC=$JL/src/javazoom/jl/decoder
|
||||
JLCONVERTERSRC=$JL/src/javazoom/jl/converter
|
||||
JLSIMPLEPLAYER=$JL/src/javazoom/jl/player
|
||||
JLADVPLAYER=$JL/src/javazoom/jl/player/advanced
|
||||
echo javac -classpath $CLASSPATH:$JL/classes -d $JL/classes $JLDECODERSRC/*.java
|
||||
javac -Xlint:unchecked -deprecation -classpath $JL/classes -d $JL/classes $JLDECODERSRC/*.java
|
||||
echo javac -classpath $CLASSPATH:$JL/classes -d $JL/classes $JLCONVERTERSRC/*.java
|
||||
javac -Xlint:unchecked -deprecation -classpath $JL/classes -d $JL/classes $JLCONVERTERSRC/*.java
|
||||
(cd $JLDECODERSRC; cp *.ser $JL/classes/javazoom/jl/decoder)
|
||||
|
||||
# MP3 Simple + Advanced Player support :
|
||||
#
|
||||
# Comment both lines below for JDK1.1.x or JDK 1.2.x
|
||||
javac -Xlint:unchecked -deprecation -classpath $JL/classes -d $JL/classes $JLSIMPLEPLAYER/*.java
|
||||
javac -Xlint:unchecked -deprecation -classpath $JL/classes -d $JL/classes $JLADVPLAYER/*.java
|
||||
|
||||
# Jar Generation
|
||||
(cd classes; jar cvf ../jl1.0.1.jar *)
|
42
Semester 1/Programming 1/Java/examples/projects/JLayer1.0.1/build-win32.bat
Executable file
42
Semester 1/Programming 1/Java/examples/projects/JLayer1.0.1/build-win32.bat
Executable file
@@ -0,0 +1,42 @@
|
||||
rem #######################################################
|
||||
rem # JLayer 1.0.1 WIN32 Build Script
|
||||
rem #
|
||||
rem # Project Homepage :
|
||||
rem # http://www.javazoom.net/javalayer/javalayer.html
|
||||
rem #
|
||||
rem # Java and MP3 online Forums :
|
||||
rem # http://www.javazoom.net/services/forums/index.jsp
|
||||
rem #
|
||||
rem #######################################################
|
||||
|
||||
rem # JAVA_HOME and JL must be set below
|
||||
set JAVA_HOME=
|
||||
set JL=../JLayer1.0.1
|
||||
|
||||
rem #---------------------------
|
||||
rem # Do not modify lines below
|
||||
rem #---------------------------
|
||||
set CLASSPATH=.
|
||||
set PATH=%PATH%;%JAVA_HOME%/bin
|
||||
set JLDECODERSRC=%JL%/src/javazoom/jl/decoder
|
||||
set JLCONVERTERSRC=%JL%/src/javazoom/jl/converter
|
||||
set JLSIMPLEPLAYER=%JL%/src/javazoom/jl/player
|
||||
set JLADVPLAYER=%JL%/src/javazoom/jl/player/advanced
|
||||
javac -classpath %CLASSPATH%;%JL%/classes -d %JL%/classes %JLDECODERSRC%/*.java
|
||||
javac -classpath %CLASSPATH%;%JL%/classes -d %JL%/classes %JLCONVERTERSRC%/*.java
|
||||
cd %JLDECODERSRC%
|
||||
copy *.ser %JL%/classes/javazoom/jl/decoder
|
||||
|
||||
rem # MP3 Simple + Advanced Player support :
|
||||
rem #
|
||||
rem # Comment both lines below for JDK1.1.x or JDK 1.2.x
|
||||
cd %JLSIMPLEPLAYER%
|
||||
javac -classpath %JL%/classes -d %JL%/classes *.java
|
||||
|
||||
cd %JLADVPLAYER%
|
||||
javac -classpath %JL%/classes -d %JL%/classes *.java
|
||||
|
||||
rem # JAR Generation
|
||||
cd classes
|
||||
jar cvf ../jl1.0.1.jar *
|
||||
cd %JL%
|
58
Semester 1/Programming 1/Java/examples/projects/JLayer1.0.1/build.xml
Executable file
58
Semester 1/Programming 1/Java/examples/projects/JLayer1.0.1/build.xml
Executable file
@@ -0,0 +1,58 @@
|
||||
<project name="javalayer" default="usage" basedir=".">
|
||||
|
||||
<!-- Initializations -->
|
||||
<target name="init">
|
||||
<echo message="-------------------------------------------------------------"/>
|
||||
<echo message="------------ BUILDING JLAYER PACKAGE ----------"/>
|
||||
<echo message=""/>
|
||||
<property name="year" value="1999-2008"/>
|
||||
<property name="jars" value="${basedir}"/>
|
||||
<property name="sources" value="${basedir}/src"/>
|
||||
<property name="classes" value="${basedir}/classes"/>
|
||||
<property name="api" value="${basedir}/doc"/>
|
||||
</target>
|
||||
|
||||
<!-- Build -->
|
||||
<target name="build" depends="init">
|
||||
<echo message="------ Compiling application"/>
|
||||
<javac srcdir="${sources}" destdir="${classes}" includes="**"/>
|
||||
<copy todir="${classes}">
|
||||
<fileset dir="${sources}" >
|
||||
<include name="javazoom/jl/decoder/*.ser"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<!-- Archive -->
|
||||
<target name="dist" depends="build">
|
||||
<echo message="------ Building Jar file"/>
|
||||
<jar jarfile="${jars}/jl1.0.1.jar" basedir="${classes}" />
|
||||
</target>
|
||||
|
||||
<!-- JavaDoc -->
|
||||
<target name="all" depends="dist">
|
||||
<echo message="------ Running JavaDoc"/>
|
||||
<javadoc packagenames="javazoom.*"
|
||||
sourcepath="${sources}"
|
||||
destdir="${api}"
|
||||
bottom="JavaZOOM ${year}"
|
||||
author="false">
|
||||
<classpath>
|
||||
<pathelement location="${classes}"/>
|
||||
</classpath>
|
||||
</javadoc>
|
||||
</target>
|
||||
|
||||
<!-- Usage -->
|
||||
<target name="usage">
|
||||
<echo message="*** JavaLayer ANT build script ***"/>
|
||||
<echo message="Usage : "/>
|
||||
<echo message=" ant [target]"/>
|
||||
<echo message=""/>
|
||||
<echo message=" target : "/>
|
||||
<echo message=" build : Build Application"/>
|
||||
<echo message=" dist : Build Application + Archive (JAR)"/>
|
||||
<echo message=" all : Build Application + Archive + JavaDoc"/>
|
||||
</target>
|
||||
|
||||
</project>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user