java rubberbanding Programming Software Development by YingKang the program draws lines, but every time I draw a new line, the previous one disappears. How can I let it show all the lines drawn? I know my problem is in the array, but how to fix it? thanks for help [code] import javax.swing.JPanel; import java.awt.*; import java.awt.event.*; import java.util.ArrayList; public class RubberLinesPanel … Re: java rubberbanding Programming Software Development by Ezzaral Read carefully what you are doing in the paintComponent() method. You are looping through every point in the array list and each time drawing a line between point1 and point2 - which are completely separate from your list of points. Perhaps you want to loop the array list by it's index and for each pair of points draw a line and increment by two.… Re: java rubberbanding Programming Software Development by ladybritt public int joinedInMonth( int month) { if (month>0 && month<13){ return clubMembers.size(); } else{ System.out.println("Error: Month must be between 1 and 12"); return= 0;} } I get an error of illegal start of expression pointing to … Re: java rubberbanding Programming Software Development by YingKang [QUOTE=Ezzaral;1030068]Read carefully what you are doing in the paintComponent() method. You are looping through every point in the array list and each time drawing a line between point1 and point2 - which are completely separate from your list of points. Perhaps you want to loop the array list by it's index and for each pair of points draw a … Re: java rubberbanding Programming Software Development by YingKang > start quote: public int joinedInMonth( int month) { if (month>0 && month<13){ return clubMembers.size(); } else{ System.out.println("Error: Month must be between 1 and 12"); return= 0;} } > I get an error of illegal start of expression pointing to the … Re: java rubberbanding Programming Software Development by Ezzaral [QUOTE=YingKang;1030118]thanks , I revised my code but got a couple of error messages, which I indicated in the following code. what could my problems be? thanks again for any help : ) [/QUOTE] You're trying to access the elements of lineList like an array, but it's an ArrayList. Use [icode]lineList.get(i)[/icode] instead. Re: java rubberbanding Programming Software Development by ladybritt [QUOTE=YingKang;1030122]I think you probably need to use "return 0; " instead of "return = 0;"[/QUOTE] thank you, that worked! I am new at this, but really would like to learn it. Thanks again:) Re: java rubberbanding Programming Software Development by YingKang [QUOTE=Ezzaral;1030132]You're trying to access the elements of lineList like an array, but it's an ArrayList. Use [icode]lineList.get(i)[/icode] instead.[/QUOTE] thanks Ezzaral : ) that problem is solved,but I got another error in the for loop, can you take a look for me please? thank you [code] for(int i=0;i<lineList.size();i++) … Re: java rubberbanding Programming Software Development by YingKang Since I didn't make it work, now I go back to arrayList<Point>, but it doesn't seem to work well. can anyone help please? thanks [code] import javax.swing.JPanel; import java.awt.*; import java.awt.event.*; import java.util.ArrayList; public class RubberLinesPanel extends JPanel { /** * */ private static final long … Re: java rubberbanding Programming Software Development by Ezzaral [quote]thanks Ezzaral : ) that problem is solved,but I got another error in the for loop, can you take a look for me please? thank you [/quote]I think you are getting more detailed information than "error message". I can guess what it is, but actually posting those error messages would be helpful. They are usually very specific in telling… Re: java rubberbanding Programming Software Development by YingKang [QUOTE=Ezzaral;1030743]I think you are getting more detailed information than "error message". I can guess what it is, but actually posting those error messages would be helpful. They are usually very specific in telling you the problem. edit: posted while you were posting this most recent version.[/QUOTE] there is not error while … Re: java rubberbanding Programming Software Development by Ezzaral So examine your loop and the code in it and try to figure out how it could access an index that is too high for your collection. Re: java rubberbanding Programming Software Development by YingKang I revised my code again. it compiles and runs, but when i draw a single line, it looks like mulitiple lines together. what the pronblem is? can anyone help please ? thank you : ) [code] import javax.swing.JPanel; import java.awt.*; import java.awt.event.*; import java.awt.geom.Line2D; import java.util.ArrayList; public class RubberLinesPanel… Re: java rubberbanding Programming Software Development by Ezzaral You're adding a new line for every mouseDragged() event. You only want to add a line when the mouse is released. Re: java rubberbanding Programming Software Development by BestJewSinceJC Well, what is the size of your array when it draws two lines next to each other? Is it one, or two? Do some debugging. If the array's size is two, then no wonder it looks like that. If its one, my theory is kaput, but have you even made this simple check? Re: java rubberbanding Programming Software Development by BestJewSinceJC Oops, posted at the same time as you Ezzaral. Re: java rubberbanding Programming Software Development by YingKang [QUOTE=Ezzaral;1030875]You're adding a new line for every mouseDragged() event. You only want to add a line when the mouse is released.[/QUOTE] I moved the code to mouseReleased from mousedragged,. it seems to run but lose its "rubber banding "effect, which is this program supposed to do. is there any way to keep the "rubber … Re: java rubberbanding Programming Software Development by Ezzaral Keep the [iCODE]point2[/iCODE] assignment and a [iCODE]repaint()[/iCODE] in [iCODE]mouseDragged()[/iCODE]. Leave [iCODE]mouseReleased()[/iCODE] as you have it, but also set [iCODE]point2[/iCODE] to null. Then alter your [iCODE]paintComponent()[/iCODE] method to draw a line from [iCODE]point1[/iCODE] to [iCODE]point2[/iCODE] if [iCODE]point2[/iCODE]… Re: java rubberbanding Programming Software Development by YingKang thanks for all the help. I revised my code again. it works fine now, with the help from the nice people here and a friend of mine. what I did is I added "point1 = point2" in mouseDragged class. thanks again to everyone who left message here. thank you Ezzaral : ) [code] import javax.swing.JPanel; import java.awt.*; import java.awt.… Re: java rubberbanding Programming Software Development by Ezzaral Ok, that isn't exactly what I thought you wanted to do, but if it works for you, great :) I thought you wanted to be able to draw multiple lines by clicking and dragging to stretch the line, like this:[code]import javax.swing.JPanel; import java.awt.*; import java.awt.event.*; import java.awt.geom.Line2D; import java.util.ArrayList; import … Re: java rubberbanding Programming Software Development by YingKang [QUOTE=Ezzaral;1031755]Ok, that isn't exactly what I thought you wanted to do, but if it works for you, great :) I thought you wanted to be able to draw multiple lines by clicking and dragging to stretch the line, like this:[code]import javax.swing.JPanel; import java.awt.*; import java.awt.event.*; import java.awt.geom.Line2D; import java.… Re: Paint Tool In flash Digital Media UI / UX Design by JasonHippy … shapes like rectangles and circles! If you want to add rubberbanding to the shapes (whilst positioning and sizing them) then again…