import java.awt.*;
import javax.swing.*;
public class Main
extends JFrame{
//Main Program that represents the GUI
public Main(){
setTitle("DK PaintProgram");
setJMenuBar(mBar);
mBar.add(Filemenu);
tBar.add(line);tBar.addSeparator();tBar.add(rectangle);
tBar.addSeparator();tBar.add(eclipse);tBar.addSeparator();tBar.add(arc);
tBar.setFloatable(false);
g.add(line);g.add(rectangle);g.add(eclipse);g.add(arc);
setSize(900,900);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main
(String[] args
) {
new Main();
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class Painter
extends JPanel {
private Vector Lines =
new Vector();
/* Vector to keep track of all
the lines that are drawn */
private Vector Rectangles =
new Vector();
/* Vector to keep track of
all the rectangles that are drawn*/
private Line newL;
// Instantiate a new Line see Line.java
private Rectangle newR;
// Instantiate a new Rectangle see Rectangle.java
public Painter(){
setBackground
(Color.
WHITE);
addMouseListener(l1);
}
/* draw all the lines in the Vector */
super.paintComponent(g);
((Line) i.
next()).
draw(g
);
}
}
newL =
new Line(e.
getPoint(),e.
getPoint());
/*
start a new Line and get the point where you
pressed the mouseButton*/
}
newL.p2 = e.getPoint();/* get the point where
you released the mouse*/
Lines.add(newL);/*add the new line to the
vector so that it can keep track of it*/
repaint();/*repaint, draw all the lines again */
}
};
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class RectanglePainter
extends JPanel {
private Vector Rectangles =
new Vector();
/* Vector to keep track of
all the rectangles that are drawn*/
private Rectangle newR;
// Instantiate a new Rectangle see Rectangle.java
public RectanglePainter(){
setBackground
(Color.
WHITE);
addMouseListener(l1);
}
/* draw all the rectangles on the screen */
super.paintComponent(g);
}
}
newR =
new Rectangle(e.
getPoint(),e.
getPoint());
/*
start a new Rectangle and get the point where you
pressed the mouseButton*/
}
newR.p2 = e.getPoint();/* get the point where
you released the mouse*/
Rectangles.add(newR);/*add the new Rectangle to the
vector so that it can keep track of it*/
repaint();/*repaint, draw all the lines again */
}
};
}
import java.awt.*;
import java.io.*;
public Point p1, p2;
/* new Points, the points where you pressed and
released the mouse*/
}
}
//draw the line
g.drawLine(p1.x, p1.y, p2.x, p2.y);
}
}
import java.awt.*;
import java.io.*;
public Point p1, p2;
/* new Points, the points where you pressed and
released the mouse*/
}
}
//draw the rectangle
g.drawRect(p1.x,p1.y,p2.x-p1.x,p2.y-p1.y);
}
}