Point |
---|
int x int y int numCreated |
Point() Point(int z) Point(int a, int b) int getX() int getY() void setX(int a) void setY(int b) int numCreated() |
public class Point { private static int numCreated = 0; private int x; private int y; }
public class Point { private static int numCreated = 0; private int x; private int y; /** * Initialize the values of both x and y to 0 and * increases in one the number of instances created */ public Point() { } /** * Initialize the values of both x and y to initValue and * increases in one the number of instances created * * @param initValue the initial value of x and y */ public Point(int initValue) { } /** * Initialize the values of x and y to xInit and yInit, * respectively, and increases in one the number of instances * created * * @param xInit the initial value of x * @param yInit the initial value of y */ public Point(int xInit, int yInit) { } /** * Obtains the number of Points created * * @return the number of Points created */ public static int numCreated() { } /** * Obtains the x-coordinate * * @return the x-coordinate */ public int getX() { } /** * Obtains the y-coordinate * * @return the y-coordinate */ public int getY() { } /** * sets the x-coordinate of this Point to newValue * * @param newValue the new x-coordinate */ public void setX(int newValue) { } /** * sets the y-coordinate of this Point to newValue * * @param newValue the new y-coordinate */ public void setY(int newValue) { } }
import java.awt.*; import java.awt.event.*; import java.applet.*; public class PointDemoApplet extends Applet implements MouseListener { private Image imageDisp; private Point lineStart = new Point(0, 0); // Line start point private Graphics g; // Create a Graphics object for drawing public void init() { setBackground(Color.white); imageDisp = getImage(getCodeBase(), "UMLClassPoint.gif"); addMouseMotionListener( new MouseMotionAdapter() { public void mouseDragged( MouseEvent e ) { g = getGraphics(); // Get graphics context g.setColor(Color.red); g.drawLine(lineStart.x, lineStart.y, e.getX(), e.getY()); lineStart.move(e.getX(), e.getY()); // Dispose this graphics context g.dispose(); } } ); addMouseListener(this); } public void paint(Graphics g) { g.drawImage(imageDisp, 2, 2,this); } public void mousePressed(MouseEvent e) { lineStart.move(e.getX(), e.getY()); } public void mouseReleased(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mouseClicked(MouseEvent e) { } }
Previou page | Next page |