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.

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

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.

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

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)

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.

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.

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

Re: Drawing Rectangles and Lines

Originally Posted by andreizeus

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.

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.

Re: Drawing Rectangles and Lines

Originally Posted by andreizeus

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.

Originally Posted by andreizeus

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.

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

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.

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

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.