Created
January 5, 2010 01:58
-
-
Save faust45/269071 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.*; | |
import java.awt.geom.*; | |
import java.awt.event.*; | |
import javax.swing.*; | |
public class app { | |
public static void main(String [] args) { | |
Window w = new Window(); | |
w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
w.show(); | |
} | |
public static void out(Object obj) { | |
System.out.println(obj); | |
} | |
} | |
class Window extends JFrame { | |
public Window() { | |
setSize(WIDTH, HEIGHT); | |
Point coord = new Point(50, 50); | |
XRectangle rect = new XRectangle(coord); | |
Container cont = getContentPane(); | |
cont.add(rect); | |
} | |
private static final int WIDTH = 400; | |
private static final int HEIGHT = 400; | |
} | |
class XRectangle extends Component implements MouseMotionListener { | |
public XRectangle(Point coord) { | |
super(); | |
this.coord = coord; | |
rect = new Rectangle2D.Double(); | |
addMouseMotionListener(this); | |
} | |
public void paint(Graphics g) { | |
Graphics2D g2 = (Graphics2D)g; | |
setBounds(coord.x, coord.y, width + 1, height + 1); | |
rect.setRect(rectX, rectY, width, height); | |
g2.draw(rect); | |
app.out("paint rec"); | |
} | |
public void mouseDragged(MouseEvent e) { | |
app.out("Mouse Dragged"); | |
width = e.getX(); | |
height = e.getY(); | |
repaint(); | |
} | |
public void mouseMoved(MouseEvent e) { | |
} | |
private Point coord; | |
private int width = 150, height = 150; | |
private Rectangle2D rect; | |
private int rectX = 0, rectY = 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment