Results 1 to 5 of 5

Thread: paint program

  1. #1
    Join Date
    Mar 2011
    Posts
    1
    Rep Power
    0

    Default paint program

    delete this thread
    Last edited by dewdadamnthang; 03-30-2011 at 03:03 AM. Reason: dont want anyone copying my code

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  3. #3
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    Reason: dont want anyone copying my code
    What do you mean you don't want anyone copying your 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!

  4. #4
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default

    ditto camickr's reply
    delete this thread
    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.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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

  1. Help with paint program
    By michcan in forum Java 2D
    Replies: 1
    Last Post: 02-04-2011, 06:26 AM
  2. Java Paint Program problem (JPanel)
    By KilKidd in forum Advanced Java
    Replies: 6
    Last Post: 11-20-2010, 04:31 AM
  3. Paint Program Help
    By ngiannini in forum AWT / Swing
    Replies: 12
    Last Post: 05-10-2010, 04:24 PM
  4. Simple Paint program question
    By StressaJune in forum New To Java
    Replies: 1
    Last Post: 03-30-2009, 08:46 PM
  5. Replies: 3
    Last Post: 12-31-2008, 05:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •