Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 22 of 22

Thread: Drawing Rectangles and Lines

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    12
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Drawing Rectangles and Lines

    Hello , I am trying to solve a problem and i dont know how to do it.
    I need to draw 2 kinds of rectangles one normal and lines. Rectangles should be connected with lines , you cant draw lines without being connected with rectangles. This is done.But i need to create another button that , wehn i click in the rectangle creates a text area where you can write code. I created this but when i try to create another tectangle , text area dissapeares and when i try to clear the screen text area remains there. Can You help me?
    another question , of course if u can , i want to see a small implementation of the JTextArea class , basicly i want to have my own class jtextarea , i tried to do it myself , like i did with the rectangles but it didnt work it out. Thank in advance
    Last edited by andreizeus; October 26th, 2010 at 08:51 AM.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,447
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 544 Posts

    Default Re: Drawing Rectangles and Lines

    Code you post should be in the form of an SSCCE. What you posted is way too much for anybody else to go through. Boil it down to the bare minimum.

    You should also always use the code tags to preserve formatting.

  3. The Following User Says Thank You to KevinWorkman For This Useful Post:

    andreizeus (October 27th, 2010)

  4. #3
    Junior Member
    Join Date
    Oct 2010
    Posts
    12
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Drawing Rectangles and Lines

    Actually i cant different because they are all related , so if i give you the main class you will need the rest of the classes...
    Last edited by andreizeus; October 26th, 2010 at 07:41 AM.

  5. #4
    Junior Member
    Join Date
    Oct 2010
    Posts
    12
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Drawing Rectangles and Lines

    anyway , the idea is how you can draw rectangles using mouse events with the option of putting text inside. This is the main task. i am pleased only with that if u cant read what i post.

  6. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,447
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 544 Posts

    Default Re: Drawing Rectangles and Lines

    What you just described is at least 4 or 5 different individual problems, and each should have its own SSCCE. Work on each problem separately, and don't even think of combining them until you have each one working perfectly.

  7. The Following User Says Thank You to KevinWorkman For This Useful Post:

    andreizeus (October 27th, 2010)

  8. #6
    Junior Member
    Join Date
    Oct 2010
    Posts
    12
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Drawing Rectangles and Lines

    let me explain you exactly what is working and not, i have 4 buttons , one for drawing rectangles , other for drawing lines , other for clear all the rectangles and lines and other fro drawing text inside rectangles.I draw first rectangles and lines but when i change the button , drawing text, it draws text but when i change the button to dtraw another rectangle then the textarea dissapear and if i press the clear button to clear all , it still remains there...
    this is the main class from where i call the rest.
    class Rectanglet
    declaration
    import java.awt.BorderLayout;
    import java.awt.Button;
    import java.awt.Color;
    import java.awt.Event;
    import java.awt.FlowLayout;
    import java.awt.Font;
    import java.awt.FontMetrics;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Point;
    import java.awt.Rectangle;
    import java.awt.TextArea;[/QUOTE]
    import java.awt.event.ActionEvent;
    import java.awt.event.MouseEvent;
    import java.util.Vector;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JScrollBar;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea
     
    public class RectangleTest extends FrameSet
     
    {
     
    	//Line s;
     
    	//Oval o;
    	Line l;
    	Rectanglet r;
    	//Rectangle1 r2;
     
    	JTextArea a;
    	Point startpos, endpos; //Declare the start and end positions
    	static int check;
    	Button btnLine, btnRect,btnClear, btnAddText;
    	static Point pct;
    	Vector vt = new Vector(); //Vector for storing the shapes
    	Vector vtLines =  new Vector();
    	Vector vtRect =  new Vector();
    	Vector vtLine =  new Vector();
    	Vector vtText =  new Vector();
    	int i = 0; //Vector index to keep count of elements(i.e.shapes)
    	int j = 0;
    	int m = 0;
    	int n = 0;
    	int nheight1, nwidth1;
     
    	boolean bline = false;  //booleans to know which button was
     
    	boolean bText = false;
    	boolean brect = false;

    Methods
    PHP Code:
    public void RecrangleTest()
        {

            
    //Do nothing in the constructor of the applet

        
    }

        public 
    void init()
        {

            
    setLayout(new FlowLayout());

            
    //Create and Add the buttons

            
    btnLine = new Button("Line");
            
    btnAddText = new Button("AddText");
            
    btnRect = new Button("Rectangle");

            
    btnClear = new Button("Clear");

            
    add(btnLine);
            
    add(btnAddText);
            
    add(btnRect);
            
    add(btnClear);

        }

        public 
    void paint(Graphics g)

        {
            
    Boolean drawBool false;
            
    int count 0;
            
    //To get a shadow effect

            
    g.setColor(Color.black);

            
    g.fillRect(0,0,size().width,size().height);

            
    g.setColor(new Color(255,255,154));
            
    g.fillRect(1,1,size().width-3,size().height-3);

            for (
    int t 0vt.size(); t++)
            {
                
    //Add the shapes to the vector
                
    Rectanglet sh = (Rectanglet)vt.elementAt(t); //elementAt(i);
                
    sh.Draw(g);
                
    //   drawBool=true;
            
    }
            
    /*    for(int a=0;a<vtLine.size();a++)
                  {
                  Line lines = (Line)vtLine.elementAt(a);
                  lines.Draw(g);
                  }
             */

            
    for(int k 0;vtLines.size();k++)
            {
                
    Line lines = (Line)vtLines.elementAt(k);
                
    lines.Draw(g);
            }


            for(
    int k =;vtText.size();k++)
            {
                
    JTextArea jtext= (JTextArea)vtText.elementAt(k);
                
    jtext.setVisible(true);
                
    //   jtext.paint(g);

            
    }


        }

        public 
    void repaint2(){
            
    repaint();
            for(
    int k =;vtText.size();k++)
            {
                
    JTextArea jtext= (JTextArea)vtText.elementAt(k);
                
    jtext.setVisible(true);

                
    //   jtext.paint(g);

            
    }
        }

        @
    Override
        
    public boolean action(Event eObject o)
        {

            
    //See which button was clicked and

            //set flags accordingly
            
    if(e.target.equals(btnAddText))
            {
                
    bline false;

                
    brect false;
                
    bText true;
                
    //!!!!!


            
    }
            if (
    e.target.equals(btnLine))

            {
                
    bline true;
                
    brect false;
                
    bText false;
            }
            if (
    e.target.equals(btnRect))
            {
                
    bline false;
                
    bText false;
                
    brect true;
            }
            if (
    e.target.equals(btnClear))
            {
                
    //Clear the entire drawing screen
                //First remove all elements
                
    vt.removeAllElements();
                
    vtLines.removeAllElements();
                
    vtText.removeAllElements();
                
    // then make vector index zero

                
    =0;
                
    j0;
                
    0;
                
    0;
                
    //    a.setVisible(false);
                //  a.removeAll();
                //finally, call repaint()
                //    remove(a);
                
    repaint();
                
    remove(a);
            }
            
    repaint2();
            return 
    true;

        } 

    Still methods but here are just Mouse events

    PHP Code:
    public boolean mouseUp(Event evtint xint y)
        {

            
    //Fianlly the mouse is up indicating shape drawing is over.

            //So set these mouseUp coordinates to set the end position.

            //Then update the Vector count.


            
    endpos =  new Point(x,y);
            if(
    bText)
            {
                for(
    int t 0;<vt.size();t++)
                {
                    
    Rectanglet rect =  (Rectanglet)vt.elementAt(t);
                    if((
    startpos.rect.getStart().0)&& (startpos.rect.getEnd().0)&&(startpos.rect.getEnd().0)&&(startpos.rect.getStart().0))
                    {
                        
    //              Rectangle rect1 =  new Rectangle(rect.getStart().x + 2, rect.getStart().y + 2 , rect.getHeight()/3, rect.getHeight()/3);
                        
    JTextArea a = new JTextArea();
                        
    //    textArea.setBounds(rect.x+rect.width/4, rect.y + rect.width/4, rect.width/2, rect.height/2);
                        //textArea.setBorder();

                        // Rectangle rec =  new Rectangle(rect.getStart().x + rect.getHeight()/4, rect.getStart().y + rect.getHeight()/4 , rect.getHeight()/2, rect.getHeight()/2);
                        //a.setBounds(rect1);
                        
    a.setBounds(rect.getStart().2rect.getStart().rect.getHeight()/3rect.getHeight()/3);
                        
    //        Rectanglet rect2 =  new Rectanglet(rect.getStart().x + 3, rect.getStart().y + 3 , rect.getHeight()/3, rect.getHeight()/3);
                        

                        
    a.setLineWrap(true);
                        
    a.requestFocusInWindow();
                        
    a.setEditable(true);
                        
    //   a.setVisible(true);
                        
    add(a);//za text area doar cand largesti imaginea
                        
    a.setCaretColor(Color.white);
                        
    a.setVisible(true);

                        
    //a.gett
                        ///////vtText.add(m, a.getText());
                        
    vtText.add(ma);
                        
    //    vtRect.add(n, rect2);
                        
    m++;
                        
    //   n++;
                    
    }
                }
            }
            if(
    bline)
            {

                for(
    int s=0;s<vt.size();s++)
                {
                    if(
    s!=check)
                    {
                        
    Rectanglet rect = (Rectanglet)vt.elementAt(s);
                        if((
    endpos.rect.getStart().0)&& (endpos.rect.getEnd().0)&&(endpos.rect.getEnd().0)&&(endpos.rect.getStart().0) )
                        {
                            
    //   check = s;
                            //Point newstart = new Point(startpos.x, startpos.y);
                            // Point drawStop =  new Point(endpos.x, endpos.y);
                            //    l.setStart(newstart);  de ce setam de 2 ori startul liniei?

                            
    l.setEnd(endpos);
                            
    vtLines.addElement(l);
                            
    =  (Line)vtLines.elementAt(j);
                            
    //    vtLine.add(j, l);
                            
    j++;
                        }

                    }
                }

            }
            if (
    brect)
            {

                
    Point drawto = new PointMath.max(x,startpos.x),Math.max(y,startpos.y));

                
    Point newstart = new Point(Math.min(x,startpos.x),Math.min(y,startpos.y));

                
    Point PointS newstart;
                
    Point PointF drawto;

                
    = (Rectanglet)vt.elementAt(i);

                
    r.setWidth(drawto,newstart);

                
    r.setHeight(drawtonewstart);
                
    r.setEnd(drawto);
                
    r.setStart(newstart);

                
    i++;

            }

            
    repaint2();

            return 
    true;


        }


        public 
    boolean mouseDown(Event evtint xint y)
        {
            
    startpos =  new Point(x,y);
            if(
    bline)
            {
                for(
    int s=0;s<vt.size();s++)
                {

                    
    Rectanglet rect = (Rectanglet)vt.elementAt(s);
                    if((
    startpos.rect.getStart().0)&& (startpos.rect.getEnd().0)&&(startpos.rect.getEnd().0)&&(startpos.rect.getStart().0) )
                    {
                        
    check s;
                        
    // pct = startpos;
                        
    =  new Line();
                        
    l.setStart(startpos);
                        
    //  vtLines.addElement(l);
                    
    }
                }
            }
            if (
    brect)
            {
                
    = new Rectanglet();     //Create the shape - Rectangle
                
    r.setStart(startpos);//Set the start position where mouse went down
                
    vt.addElement(r);    //and add the shape (Rectangle) to the vector vt
                //    vtStartPos.addElement(startpos);
            
    }
            if(
    bText)
            {
                for(
    int t 0;<vt.size();t++)
                {
                    
    Rectanglet rect =  (Rectanglet)vt.elementAt(t);
                    if((
    startpos.rect.getStart().0)&& (startpos.rect.getEnd().0)&&(startpos.rect.getEnd().0)&&(startpos.rect.getStart().0))
                    {

                        
    // RectangleText rect1 =  new RectangleText();
                        
    JTextArea a = new JTextArea();
                        
    //    textArea.setBounds(rect.x+rect.width/4, rect.y + rect.width/4, rect.width/2, rect.height/2);
                        //textArea.setBorder();

                        // Rectangle rec =  new Rectangle(rect.getStart().x + rect.getHeight()/4, rect.getStart().y + rect.getHeight()/4 , rect.getHeight()/2, rect.getHeight()/2);
                        //a.setBounds(rect1);
                        
    a.setBounds(rect.getStart().2rect.getStart().rect.getHeight(), rect.getHeight());
                
    //        Rectanglet rect2 =  new Rectanglet(rect.getStart().x + 3, rect.getStart().y + 3 , rect.getHeight()/3, rect.getHeight()/3);
                        //    JScrollPane scrollingResult = new JScrollPane(a);
                        //content.add(scrollingResult);
                        //      JPanel content = new JPanel();
                        //content.setLayout(new BorderLayout());
                        //    add(scrollingResult);
                        
    a.setLineWrap(true);
                        
    a.requestFocusInWindow();
                        
    a.setEditable(true);
                        
    //   a.setVisible(true);
                        
    add(a);//za text area doar cand largesti imaginea
                        
    a.setCaretColor(Color.white);
                        
    a.setVisible(true);
                        
    //vtText.add(m, a.getText());
                        
    vtText.add(ma);
                
    //        vtRect.add(n, rect2);

                    
    }
                }
            }
            
    repaint2();

            return 
    true;

        }




        public 
    boolean mouseDrag(Event evtint xint y)
        {
            
    //Boolean okrect=false;
            //Now the mouse is being dragged without releasing,

            //which means that the user may stop his mouse over a

            //point but not release it. So that point is the

            //current endpoint

            
    endpos = new Point(x,y);

            if(
    bline)
            {
                for(
    int s=0;s<vt.size();s++)
                {
                    if(
    s!=check){
                        
    Rectanglet rect = (Rectanglet)vt.elementAt(s);
                        
    //if((startpos.x - rect.getStart().x > 0)&& (startpos.x - rect.getEnd().x < 0)&&(startpos.y - rect.getEnd().y < 0)&&(startpos.y - rect.getStart().y > 0))
                        //{
                        
    if((endpos.rect.getStart().0)&& (endpos.rect.getEnd().0)&&(endpos.rect.getEnd().0)&&(endpos.rect.getStart().0) )
                        {
                            
    Point newstart = new Point(startpos.xstartpos.y);
                            
    //Point drawStop =  new Point(endpos.x, endpos.y);
                            //l =  (Line)vtLines.elementAt(j); ///era i inainte
                            
    l.setStart(newstart);
                            
    //l.setEnd(drawStop);
                            //j++; //era i inainte
                        
    }
                    }
                    
    //}
                
    }
            }
            if (
    brect)

            {

                
    Point drawto = new PointMath.max(x,startpos.x),Math.max(y,startpos.y));

                
    Point newstart = new Point(Math.min(x,startpos.x),Math.min(y,startpos.y));

                
    // nwidth1 = Math.abs((drawto.x - newstart.x));

                //nheight1 = Math.abs((drawto.y - newstart.y));

                //r = (Rectanglet)vt.elementAt(i);

                
    r.setWidth(drawtonewstart);

                
    r.setHeight(drawtonewstart);
                
    r.setEnd(drawto);
                
    r.setStart(newstart);
                
    // vtStartPos.addElement(newstart);
                //   vtEndPos.addElement(drawto);
                // i++;
                //  okrect=true;
            
    }


            
    repaint2();

            return 
    true;


        }

    Class Rectangle
    PHP Code:
    C

    import java
    .awt.Color;
    import java.awt.Graphics;
    import java.awt.Point;




    class 
    Rectanglet extends Object
         
    {
          
           private 
    int length;
           private 
    int width;
            public 
    Point ptStart;        //Start point of shape
           
    public Point ptEnd;     //End point of shape
       //    public int width;      //Width of shape
           
    public int height;
             public 
    Color clrFront;
               
    void Draw(Graphics g)

            {

                
    g.setColor(Color.blue.brighter()); //Set default color

                
    g.drawRect(ptStart.xptStart.ywidthheight);

            }
         public 
    Rectanglet(int xint yint wint h)
        {
            
    //ptStart = new Point();
            //ptEnd = new Point();
            
    this.ptStart.x;
            
    this.ptStart.y;
            
    this.width w;
            
    this.height h;
        }
         public 
    Rectanglet()
          {

           
    clrFront Color.red;
          }
          
    Boolean containes(Point p)
          {
           if((
    ptStart.p.0)&& (ptEnd.p.0)&&(p.ptStart.0)&&(p.ptEnd.0))
              {
                return 
    true;
              }
           else
         return 
    false;
        }
          public 
    Rectanglet getbounds()
          {
             return new 
    Rectanglet(ptStart.xptStart.ywidthheight);
             
    // return new Rectanglet(x1,x2,x3, x4);
          
    }

            
    void setStart(Point ptStart)
            {

             
    this.ptStart ptStart;

            }


            
    void setEnd(Point ptEnd)

            {

             
    this.ptEnd ptEnd;

            }

            
    Point getStart()
            {
               return 
    ptStart;
            }

             
    int getHeight()

            {

                return 
    height;

            }



        public 
    double getWidth(){
            return 
    width;
        }

            public 
    void setWidth(Point P1Point P2){
            
    this.width Math.abs(P1.P2.x);
        }
            public 
    void setHeight(Point P1Point P2)
            {
                
    this.height Math.abs(P1.P2.y);
            }
            
    Point getEnd()
            {

                return 
    ptEnd;

            }

            



        }



















            
    //Drawing routine 
    Sorry but i dont know how to do it more than this. If u need the other classes let me know. I did my best. If its not ok tell how i must do and i will
    Last edited by andreizeus; October 26th, 2010 at 08:18 AM.

  9. #7
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,447
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 544 Posts

    Default Re: Drawing Rectangles and Lines

    Again, that's not an SSCCE, and you didn't even bother to use the code tags. I'd love to help, but I don't have time to wade through unformatted code that isn't easy to run. You aren't going to get help if you continue down this road.

  10. The Following User Says Thank You to KevinWorkman For This Useful Post:

    andreizeus (October 27th, 2010)

  11. #8
    Junior Member
    Join Date
    Oct 2010
    Posts
    12
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Drawing Rectangles and Lines

    I modified the text as i could...see up

  12. #9
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    495
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: Drawing Rectangles and Lines

    TL;DR.

    I second Kevin's recommendation. Split your problem into individual parts and tackle each one separately. That way, if you get stuck in one part, you have a SSCCE that's short enough for people here to read and offer advice.

    Or keep hoping some sucker will put in the effort that you should. It's your choice.

    db

  13. The Following User Says Thank You to Darryl.Burke For This Useful Post:

    andreizeus (October 27th, 2010)

  14. #10
    Junior Member
    Join Date
    Oct 2010
    Posts
    12
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Drawing Rectangles and Lines

    my friends how can i split it if you need at least to know about the classes. Another try....
    First i dont know where is the problem. because i dont know how to do it.
    Maybe you didnt understand my problem. I dont know how to do that and dont know where is the problem.
    I tried to do it like this
    when i put the mouse down , at mouseDown i did something like this:
    I create my own class rectanglet everything is working but text, because when i click on the trectangle the text area doesnt display all , just a small part and after i enter some text it appears aand the rest but when i tried to change the button because i have buttons for every draw(rectangle , line, clear_all and text) the text dissapears. First i want to know how to save the text and draw it every time i change the shape.
    More if i try to delete all the shapes including the JTextArea the textarea reamins there.
    Declration variables and stuff

    PHP Code:
    public class RectangleTest extends FrameSet

    {

        
    //Line s;

        //Oval o;
        
    Line l;
        
    Rectanglet r;
        
    //Rectangle1 r2;

        
    JTextArea a;
        
    Point startposendpos//Declare the start and end positions
        
    static int check;
        
    Button btnLinebtnRect,btnClearbtnAddText;
        static 
    Point pct;
        
    Vector vt = new Vector(); //Vector for storing the shapes
        
    Vector vtLines =  new Vector();
        
    Vector vtRect =  new Vector();
        
    Vector vtLine =  new Vector();
        
    Vector vtText =  new Vector();
        
    int i 0//Vector index to keep count of elements(i.e.shapes)
        
    int j 0;
        
    int m 0;
        
    int n 0;
        
    int nheight1nwidth1;

        
    boolean bline false;  //booleans to know which button was

        
    boolean bText false;
        
    boolean brect false
    And the paint function

    PHP Code:
    public void paint(Graphics g)

        {
            
    Boolean drawBool false;
            
    int count 0;
            
    //To get a shadow effect

            
    g.setColor(Color.black);

            
    g.fillRect(0,0,size().width,size().height);

            
    g.setColor(new Color(255,255,154));
            
    g.fillRect(1,1,size().width-3,size().height-3);

            for (
    int t 0vt.size(); t++)
            {
                
    //Add the shapes to the vector
                
    Rectanglet sh = (Rectanglet)vt.elementAt(t); //elementAt(i);
                
    sh.Draw(g);
                
    //   drawBool=true;
            
    }
          
            for(
    int k 0;vtLines.size();k++)
            {
                
    Line lines = (Line)vtLines.elementAt(k);
                
    lines.Draw(g);
            }


            for(
    int k =;vtText.size();k++)
            {
                
    JTextArea jtext= (JTextArea)vtText.elementAt(k);
                
    jtext.setVisible(true);
                
    //   jtext.paint(g);

            
    }


        } 


    MouseDown event
    PHP Code:
    for(int t 0;<vt.size();t++)
                {
                    
    Rectanglet rect =  (Rectanglet)vt.elementAt(t);
                    if((
    startpos.rect.getStart().0)&& (startpos.rect.getEnd().0)&&(startpos.rect.getEnd().0)&&(startpos.rect.getStart().0))
                    {

                        
    // RectangleText rect1 =  new RectangleText();
                        
    = new JTextArea();
                    
                        
                        
    a.setLineWrap(true);
                        
    a.requestFocusInWindow();
                        
    a.setEditable(true);
                 
                        
    add(a);
                        
    a.setCaretColor(Color.white);
                        
    a.setVisible(true);
                        
    //vtText.add(m, a.getText());
                       // vtText.add(a);
      

                    
    }
                }
            } 
    in the next mouse event
    mouseUp i tried to save it in a vector
    PHP Code:
    for(int t 0;<vt.size();t++)
                {
                    
    Rectanglet rect =  (Rectanglet)vt.elementAt(t);
                    if((
    startpos.rect.getStart().0)&& (startpos.rect.getEnd().0)&&(startpos.rect.getEnd().0)&&(startpos.rect.getStart().0))
                    {
                     
                  
                        

                        
    a.setLineWrap(true);
                        
    a.requestFocusInWindow();
                        
    a.setEditable(true);
                
                        
    add(a);//za text area doar cand largesti imaginea
                        
    a.setCaretColor(Color.white);
                        
    a.setVisible(true);

                        
    vtText.add(ma);
                   
                        
    m++;
                        
    //   n++;
                    
    }
                } 

  15. #11
    Junior Member
    Join Date
    Oct 2010
    Posts
    12
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Drawing Rectangles and Lines

    So in the end someone will help me or not?? I want to know if i lose my time here, because i kind of have a deadline. If not ok , i will leave.

  16. #12
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,447
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 544 Posts

    Default Re: Drawing Rectangles and Lines

    Quote Originally Posted by andreizeus View Post
    So in the end someone will help me or not?? I want to know if i lose my time here, because i kind of have a deadline. If not ok , i will leave.
    You've been told what you need to do to get help. That's going to be the case no matter where you go, unless you're paying for a professional tutor. Whether or not you're willing to put forth that effort is up to you.

    If you read the SSCCE link, you'll see that we're not asking for this just for our benefit. The process of creating an SSCCE is a crucial skill to pick up, even if you do it without really thinking about it.

  17. The Following User Says Thank You to KevinWorkman For This Useful Post:

    andreizeus (October 27th, 2010)

  18. #13
    Junior Member
    Join Date
    Oct 2010
    Posts
    12
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Drawing Rectangles and Lines

    ok man , i will explain like i do for a kid.
    I must be able to put comment box inside rectangles , rectangles created from mouse events and stored in a vector, with my own class rectangle. How can i do this?, Because when i paint it all dont work.

    here is the paint function

    PHP Code:
    public void paint(Graphics g)

        {
            
    Boolean drawBool false;
            
    int count 0;
            
    //To get a shadow effect

            
    g.setColor(Color.black);

            
    g.fillRect(0,0,size().width,size().height);

            
    g.setColor(new Color(255,255,154));
            
    g.fillRect(1,1,size().width-3,size().height-3);

            for (
    int t 0vt.size(); t++)
            {
                
    //Add the shapes to the vector
                
    Rectanglet sh = (Rectanglet)vt.elementAt(t); //elementAt(i);
                
    sh.Draw(g);
                
    //   drawBool=true;
            
    }
          
            for(
    int k 0;vtLines.size();k++)
            {
                
    Line lines = (Line)vtLines.elementAt(k);
                
    lines.Draw(g);
            }


            for(
    int k =;vtText.size();k++)
            {
                
    JTextArea jtext= (JTextArea)vtText.elementAt(k);
                
    jtext.setVisible(true);
                
    //   jtext.paint(g);

            
    }


        } 
    the format is more than SSCCE.

  19. #14
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,447
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 544 Posts

    Default Re: Drawing Rectangles and Lines

    Quote Originally Posted by andreizeus View Post
    ok man , i will explain like i do for a kid.
    And so will I: You aren't going to get help until you create an SSCCE and ask a specific question about the specific part of the problem you're stuck on. We can't really answer general "how do I do this" type questions except to point you to the basic tutorials. Go through them.

    Quote Originally Posted by andreizeus View Post
    I must be able to put comment box inside rectangles , rectangles created from mouse events and stored in a vector, with my own class rectangle. How can i do this?, Because when i paint it all dont work.
    Which part of that are you having trouble with? Post an SSCCE that demonstrates that specific part. Is it the Mouse Event part? The drawing part? The storing of data? Creating your own class? Getting typed input? Storing typed input? Drawing typed input? Pick one to start with. Create an SSCCE.

    Quote Originally Posted by andreizeus View Post
    the format is more than SSCCE.
    No. It's less.

  20. The Following User Says Thank You to KevinWorkman For This Useful Post:

    andreizeus (October 27th, 2010)

  21. #15
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    495
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: Drawing Rectangles and Lines


  22. The Following User Says Thank You to Darryl.Burke For This Useful Post:

    andreizeus (October 27th, 2010)

  23. #16
    Junior Member
    Join Date
    Oct 2010
    Posts
    12
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Drawing Rectangles and Lines

    I dont know, thats the problem, what you dont understand...i save it in the vectors but when i try to display them in paint it doesnt work. they dissapear.

  24. #17
    Junior Member
    Join Date
    Oct 2010
    Posts
    12
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Drawing Rectangles and Lines

    i save it in vector in mouse up

    PHP Code:
    if(bText)
            {
                for(
    int t 0;<vt.size();t++)
                {
                    
    Rectanglet rect =  (Rectanglet)vt.elementAt(t);
                    if((
    startpos.rect.getStart().0)&& (startpos.rect.getEnd().0)&&(startpos.rect.getEnd().0)&&(startpos.rect.getStart().0))
                    {
                       
                        
    a.setBounds(rect.getStart().2rect.getStart().rect.getHeight()/3rect.getHeight()/3);
                         
    a.setLineWrap(true);
                        
    a.requestFocusInWindow();
                        
    a.setEditable(true);
                     
                        
    add(a);//za text area doar cand largesti imaginea
                        
    a.setCaretColor(Color.white);
                        
    a.setVisible(true);

                     
                        
    vtText.add(ma);
                   
                        
    m++;
                  
                    }
                }
            } 
    mouse down the same but a little bit different

    PHP Code:
     if(bText)
            {
                for(
    int t 0;<vt.size();t++)
                {
                    
    Rectanglet rect =  (Rectanglet)vt.elementAt(t);
                    if((
    startpos.rect.getStart().0)&& (startpos.rect.getEnd().0)&&(startpos.rect.getEnd().0)&&(startpos.rect.getStart().0))
                    {

                    
    a.setBounds(rect.getStart().2rect.getStart().rect.getHeight(), rect.getHeight());
                    
    a.setLineWrap(true);
                        
    a.requestFocusInWindow();
                        
    a.setEditable(true);
                        
    //   a.setVisible(true);
                        
    add(a);//za text area doar cand largesti imaginea
                        
    a.setCaretColor(Color.white);
                        
    a.setVisible(true);
                        
    //vtText.add(m, a.getText());
                        
    vtText.add(ma);
                
    //        vtRect.add(n, rect2);

                    
    }
                }
            } 
    but in the end its not working, in paint i do something like this

    PHP Code:
    for(int i 0<vtText.size())
    {
        
    JTextArea jtext =  (JTextArea)vtText.elementAt(i);
       
    jtext.setVisible(true);


  25. #18
    Junior Member
    Join Date
    Oct 2010
    Posts
    12
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Drawing Rectangles and Lines

    Thankx for your help!!! You are supposed to be experts but as far as i read...better without!. Let me explain you someting, i am not a newbie on programming so i know what you need to do it ,and in the end after all the commentaries i understood what you know and how you manage things.I made a big mistake asking for help. Good day, Andrei

  26. #19
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    495
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: Drawing Rectangles and Lines

    I take it you won't be back, then? Good riddance.

    db

  27. #20
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,332
    Thanks
    181
    Thanked 829 Times in 772 Posts
    Blog Entries
    5

    Default Re: Drawing Rectangles and Lines

    Thankx for your help!!! You are supposed to be experts but as far as i read...better without!. Let me explain you someting, i am not a newbie on programming so i know what you need to do it ,and in the end after all the commentaries i understood what you know and how you manage things.I made a big mistake asking for help. Good day, Andrei
    andreizeus, these members are trying to help, all on their own time without pay, and without a short and clear question it makes that effort to help difficult. You have a lot of code there with quite a few behaviors on top which may not be necessary to the problem at hand, which makes it even more difficult for those on our side to help. I suggest if you wish to get more constructive feedback, you read the first few responses to your original post - strip many of those behaviors and items out of your code and focus on the exact problem at hand: if you say 'they disappear', then remove every other component you paint except those that disappear, remove all the mouse listeners, and see what happens. If they still 'disappear', remove more. When they 'appear', slowly add all those back.

  28. #21
    Junior Member
    Join Date
    Oct 2010
    Posts
    12
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Drawing Rectangles and Lines

    Finally someone answered pointing something, yeah i tried everything after deep search i find out it was the JTextArea class program , everytime i was drawing the rectangle in the paint function it seems that it was painting the color after the color of the jtextarea ...So after using only TextArea or String it worked. So thankx a lot for trying to give me and advice. I go pissed off because all the time they ask for stupid SSCCE, but they even didnt try to see wtf is happening there. i marked the code with php tags and nothing...So in the end i got very angry because i am sick of the programmers that they say they know and they dont. If you know how to do it than fucking do it not ask for stupid SSCE , because i know better than them what they needed. I gave them the all code , all they should have done was to copy paste it... So in the end i got very angry.Thankx

  29. #22
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,447
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 544 Posts

    Default Re: Drawing Rectangles and Lines

    And for posterity's sake, I just got this gem in my private inbox from andreizeus:

    Dont try to scream and say that you tried to do something because you didnt give me any advice. I know something in my life , i know i talk , i dont i shut up. I gave you the all code , all you should have done is just to copy paste it and then i told you what i want to do the code with the mention that i have no idea why it isnt working. So shut up and next time if will ever post something here , because i dont think i will ever, talk if you know. Dont waste my time and your time too.
    Yikes.

Similar Threads

  1. How to form a rectangle from the union of two Rectangles.
    By javapenguin in forum What's Wrong With My Code?
    Replies: 8
    Last Post: September 3rd, 2010, 07:22 AM
  2. My lines won't work!!!
    By The Mewzytion in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 2nd, 2010, 10:24 AM
  3. Drawing circles with smoother lines?
    By tabutcher in forum Java Theory & Questions
    Replies: 4
    Last Post: April 18th, 2010, 10:12 AM
  4. [SOLVED] reading only certain lines from a .txt file
    By straw in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: March 7th, 2010, 06:49 PM
  5. [SOLVED] Supressing empty lines and does not do until the end! Why ?
    By lumpy in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 18th, 2010, 06:38 AM