Results 1 to 5 of 5
Thread: paint program
- 03-29-2011, 10:10 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 1
- Rep Power
- 0
-
I think that the easiest way to implement this is to create a BufferedImage and do all of your drawing in the BufferedImage. Then all the paintComponent method has to do, besides call its super method is draw the BufferedImage.
- 03-30-2011, 03:49 AM #3
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
What do you mean you don't want anyone copying your code?Reason: dont want anyone copying my code
First of all the code didn't work, which is why you posted your question. Secondly, the forum is about sharing. If you aren't willing to share code so others can learn, then why do you expect us to help you? You get what you give!
- 03-30-2011, 04:31 AM #4
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,606
- Rep Power
- 5
ditto camickr's reply
Why delete? Forums like this are here to help - not just you but others as well. Remove the post and you remove the chance of others to learn, which will in turn effect your chance to ever receive help again.delete this thread
-
I think that his code was something like this:
Java Code:import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.util.*; import java.io.*; import javax.swing.*; import javax.imageio.*; import javax.swing.JOptionPane; public class CanvasPanel extends JPanel implements MouseListener, MouseMotionListener, Serializable { protected final static int LINE = 1, RECTANGLE = 2, OVAL = 3, POLYGON = 4, SOLID_SQUARE = 5, SOLID_OVAL = 6, SOLID_POLYGON = 7, TEXT = 8; private Color foreGroundColor; private int x1, y1, x2, y2, linex1, linex2, liney1, liney2, txtX, txtY, drawMode = 0; private boolean solidMode; private ArrayList<Shape> shapes = new ArrayList<Shape>(); private Shape mouseOverShape = null; public CanvasPanel() { addMouseListener(this); addMouseMotionListener(this); solidMode = false; foreGroundColor = Color.BLACK; setBackground(Color.white); repaint(); } public void mousePressed(MouseEvent event) { x1 = linex1 = linex2 = event.getX(); y1 = liney1 = liney2 = event.getY(); } public void mouseClicked(MouseEvent event) { txtX = event.getX(); txtY = event.getY(); repaint(); } public void mouseMoved(MouseEvent event) { } public void mouseReleased(MouseEvent event) { } public void mouseEntered(MouseEvent event) { } public void mouseExited(MouseEvent event) { } public void mouseDragged(MouseEvent event) { x2 = event.getX(); y2 = event.getY(); repaint(); } public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setColor(foreGroundColor); if (drawMode == LINE) g2.drawLine(x1, y1, x2, y2); if (drawMode == RECTANGLE) { if (solidMode) g2.fillRect(x1, y1, x2 - x1, y2 - y1); else g2.drawRect(x1, y1, x2 - x1, y2 - y1); } if (drawMode == OVAL) { if (solidMode) g2.fillOval(x1, y1, x2 - x1, y2 - y1); else g2.drawOval(x1, y1, x2 - x1, y2 - y1); } if (drawMode == TEXT) g2.drawString("TEST", x1, y1); } public void setDrawMode(int mode) { drawMode = mode; } public int getDrawMode() { return drawMode; } public void setSolidMode(Boolean inSolidMode) { solidMode = inSolidMode.booleanValue(); } public Boolean getSolidMode() { return Boolean.valueOf(solidMode); } public void setForeGroundColor(Color inputColor) { foreGroundColor = inputColor; } public Color getForeGroundColor() { return foreGroundColor; } private class Coordinate implements Serializable { private int x1, y1, x2, y2; private Color foreColor; private Vector xPoly, yPoly; private RenderedImage myCreateImage() { BufferedImage bufferedImage = new BufferedImage(600, 390, BufferedImage.TYPE_INT_RGB); Graphics g = bufferedImage.createGraphics(); return bufferedImage; } } }
But I agree -- no one in their right mind would want to copy this dreck.
Similar Threads
-
Help with paint program
By michcan in forum Java 2DReplies: 1Last Post: 02-04-2011, 06:26 AM -
Java Paint Program problem (JPanel)
By KilKidd in forum Advanced JavaReplies: 6Last Post: 11-20-2010, 04:31 AM -
Paint Program Help
By ngiannini in forum AWT / SwingReplies: 12Last Post: 05-10-2010, 04:24 PM -
Simple Paint program question
By StressaJune in forum New To JavaReplies: 1Last Post: 03-30-2009, 08:46 PM -
just started paint program. am i going the right direction?
By diggitydoggz in forum New To JavaReplies: 3Last Post: 12-31-2008, 05:57 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks