I got some problems on how to get the freehand Line and such working atleast if i figure out how to do the line then it will be easy to convert it over to work for both the Oval and the Rectangle.
So here is the deal im making a paint program I got everything set out in interfaces and different classes.
Im using the mouse dragged, pressed and released to make the line. I do get the line to work how i want it but it doesnt draw itself on the board. I got the clicked function for the regular drawings. So when you click you can click on a Oval,Rect and line and it will make a static line which you can alter with height and width to make it longer/shorter/bigger/smaller. Thats allright, but we are also implementing a freehand implementation. This is where im stuck. So here is a code snippet:
Init phase;
public class View extends JFrame { Model model = new Model(); TegnePanel tegnePanel = new TegnePanel(); JPanel jp2 = new JPanel(); Color currentFarge = Color.BLUE; boolean current = true; public int currentWidth = 10; public int currentHeight = 10; private FigurType currentFigurType = FigurType.RECTANGLE; public enum FigurType { LINE,RECTANGLE,OVAL,DELETE } int xStart, yStart; int xSlutt, ySlutt; int wDra, hDra;
mouseListenerPhase;
@Override public void mousePressed(MouseEvent e) { e.consume(); xStart = e.getX(); yStart = e.getY(); } @Override public void mouseReleased(MouseEvent e) { xSlutt = e.getX(); ySlutt = e.getY(); repaint(); }
mouseMotionListenerPhase;
public void mouseDragged(MouseEvent event){ if (currentFigurType == FigurType.LINJE){ Graphics g = getGraphics(); xSlutt = event.getX(); ySlutt = event.getY(); Color c = currentFarge; g.drawLine(xStart, yStart, xSlutt, ySlutt); repaint();
Translations: xSlutt = xEnd,