Bitte um Hilfe bei einem kleinem Zeichenprogramm

beatnut420

Grünschnabel
Hallo Leutz
.....hoffe sehr ihr könnt mir da helfen, bin am verzweifeln, für viele wahrscheinlich eine leichte Aufgabe ;-)

...habe das .txt File drangehängt wo alles weitere drinsteht
danke für eure Mühen...
 

Anhänge

  • Zeichenprogi.txt
    4,1 KB · Aufrufe: 68
Hallo,

Schau mal hier:
Code:
/*
 * Created on 19.05.2005@12:32:11 by Darimont
 *
 * TODO Licence info
 */
package de.tutorials;

import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;

import javax.swing.JFrame;

/**
 * @author Darimont
 * 
 * TODO Explain me
 */
public class RectanglePaintingExample extends JFrame {

	private Point startPoint;

	public RectanglePaintingExample() {
		super("RectanglePaintingExample");
		setDefaultCloseOperation(EXIT_ON_CLOSE);

		addMouseListener(new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				startPoint = e.getPoint();
			}

			public void mouseReleased(MouseEvent e) {
				startPoint = null;
			}
		});

		addMouseMotionListener(new MouseMotionAdapter() {
			public void mouseDragged(MouseEvent e) {
				Point p = e.getPoint();

				if (startPoint != null) {
					Graphics g = getGraphics();
					g.clearRect(0, 0, 640, 480);

					int w = p.x - startPoint.x;
					int h = p.y - startPoint.y;

					int x = startPoint.x;
					int y = startPoint.y;

					if (h < 0) {
						y += h;
					}
					if (w < 0) {
						x += w;
					}

					g.drawRect(x, y, Math.abs(w), Math.abs(h));

				}
			}
		});

		setSize(640, 480);

		setVisible(true);
	}

	public static void main(String[] args) {
		new RectanglePaintingExample();
	}
}

Gruß Tom
 
Zurück