Page 2 of 2 FirstFirst 12
Results 21 to 28 of 28
Like Tree7Likes

Thread: A simple paint program

  1. #21
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,784
    Blog Entries
    7
    Rep Power
    21

    Default Re: A simple paint program

    Quote Originally Posted by fatima25 View Post
    I saw this link Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing) but our teacher wanted us this program in other way.
    What other way? (just curious); we either all learn something new here, or you misunderstood what your professor told you or your professor is a complete bonehead.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  2. #22
    fatima25 is offline Member
    Join Date
    Jul 2013
    Posts
    9
    Rep Power
    0

    Default Re: A simple paint program

    thanks I added u on skype!
    Quote Originally Posted by UJJAL DHAR View Post
    Dear Fatima25,
    please do somework.Then we will be able to help you.
    Start from here..
    1. Create a class file named box.java in which there will be code of drawing box
    2. Create a class file named circle.java in which there will be code of drawing circle
    3. Create a class file named line.java in which there will be code of drawing line
    4. Study about Swing and Paint method
    5. Implement your target code.too much simple.


    You can ask anything which you dont understand.

  3. #23
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: A simple paint program

    Quote Originally Posted by JosAH View Post
    What other way?
    (Pretty sure that the "other way" is using the visual editor mentioned earlier).

  4. #24
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default Re: A simple paint program

    On Erase button, you can just reset the JPanel. thats simple.
    Don't Forget to try yourself before asking others help.....
    Press REP, if you find their advices/solutions effective.

  5. #25
    fatima25 is offline Member
    Join Date
    Jul 2013
    Posts
    9
    Rep Power
    0

    Default Re: A simple paint program

    I did it in this way:

    public class NewJFrame extends javax.swing.JFrame {


    Point p1 = new Point();
    int level = 0;

    private String chosenShape ;


    public NewJFrame() {
    initComponents();
    }

    @Override
    public void paint(Graphics g) {
    super.paint(g);

    }
    private void jButtonlineActionPerformed(java.awt.event.ActionEv ent evt) {

    chosenShape = "line";

    }

    private void jpanel1MouseClicked(java.awt.event.MouseEvent evt) {

    if ( chosenShape.equals("line") ) {
    Graphics g = jpanel1.getGraphics();
    p1 = evt.getPoint();
    g.drawLine(p1.x, p1.y, 100, 100);
    }
    if ( chosenShape.equals("Box") ) {
    Graphics g = jpanel1.getGraphics();
    p1 = evt.getPoint();
    g.drawRect(p1.x, p1.y, 100, 100);
    }
    if ( chosenShape.equals("Circle") ) {
    Graphics g = jpanel1.getGraphics();
    p1 = evt.getPoint();
    g.drawOval(p1.x, p1.y, 100, 100);
    }
    }

    private void jButtonBoxActionPerformed(java.awt.event.ActionEve nt evt) {
    chosenShape = "Box";



    }

    private void jButtonCircleActionPerformed(java.awt.event.Action Event evt) {
    chosenShape = "Circle";
    }

    private void jButtonEreaseActionPerformed(java.awt.event.Action Event evt) {


    jpanel1.repaint();

    }
    A simple paint program-capture1.jpg

  6. #26
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: A simple paint program

    Quote Originally Posted by fatima25 View Post
    I did it in this way:
    ...
    @Override
    public void paint(Graphics g) {
    super.paint(g);

    }
    ...
    Graphics g = jpanel1.getGraphics();
    ...
    Graphics g = jpanel1.getGraphics();
    ...
    Graphics g = jpanel1.getGraphics();
    ...
    You're incapable of learning. You couldn't even learn to use the code tags after the links were given to you at #4 and you were reminded at #8.

    To others reading this thread, this is not the way to go. An override of paint(...) or indeed any other method that does nothing but invoke the super implementation is useless.

    And short of a very advanced requirement and an intimate understanding of the Swing painting mechanism, never invoke getGraphics() of a Component.

    db
    Last edited by DarrylBurke; 07-05-2013 at 03:11 PM.
    gimbal2, SurfMan and JosAH like this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #27
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: A simple paint program

    Give it time though. Eventually even the people that are most persistent about not wanting to learn and just blundering on their own rocky path actually learn SOMETHING. And when that happens... its a thing of beauty.

  8. #28
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,036
    Rep Power
    6

    Default Re: A simple paint program

    He's also subclassing JFrame. Makes you wonder if this is really what is being taught.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Trying to create a simple Paint application
    By driiper in forum Java 2D
    Replies: 2
    Last Post: 05-02-2012, 08:27 PM
  2. paint error, with a simple boolean
    By PRW56 in forum New To Java
    Replies: 16
    Last Post: 04-05-2012, 10:08 AM
  3. Paint program
    By aarti in forum AWT / Swing
    Replies: 14
    Last Post: 05-06-2011, 07:55 AM
  4. Help with paint program
    By michcan in forum Java 2D
    Replies: 1
    Last Post: 02-04-2011, 07:26 AM
  5. Simple Paint program question
    By StressaJune in forum New To Java
    Replies: 1
    Last Post: 03-30-2009, 09:46 PM

Posting Permissions

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