Solved

Java clear part canvas

Posted on 2010-09-15
5
744 Views
Last Modified: 2013-11-23
Hi all

I'm new to Java and learning

If I was to clear the canvas I would use removeAll()

how can I remove objects only from the bottom half of my canvas and specify the x y of what part I want to clear

Thanks
0
Comment
Question by:markavo
  • 3
5 Comments
 
LVL 26

Expert Comment

by:ksivananth
ID: 33689034
you need to provide the impl,

1. travese all the components in the canvas
2. compare the co-ordiante of the components in the canvas against your x, y
3. if it is after that, remove that component
0
 
LVL 37

Expert Comment

by:zzynx
ID: 33689208
>> specify the x y of what part I want to clear
Why would you want to do that?

When I read this, I think you're working a bit unusual.
That's why I ask you the previous question.

If I know what components I need to remove at some point in time, I would keep references to them.
Then to remove them I can simply call

remove( getMyComponent1() );
remove( getMyComponent2() );
...
remove( getMyComponentN() );
0
 

Author Comment

by:markavo
ID: 33695631
Hi

Thank you , can you give me an example please how i would reference for example

GRect rect = new GRect (x,y, height, width) ;
add(rect);

so rect holds a new Grect

this would remove the object ---- remove(rect);

How would i pass the reference through to methods so i can remove objects from within a method and call remove(rect)

help appreciated
0
 
LVL 37

Accepted Solution

by:
zzynx earned 250 total points
ID: 33699111
>> How would i pass the reference through to methods so i can remove objects from within a method and call remove(rect)

GRect rect = new GRect (x,y, height, width) ;
add(rect);

....

yourMethod1(rect);
...
yourMethod2(rect);

with

private yourMethod1(GRect rect) {
   ....
   remove(rect);
   ....
}

and

private yourMethod2(GRect rect) {
   ....
   remove(rect);
   ....
}
0
 
LVL 37

Expert Comment

by:zzynx
ID: 33723881
Thanx 4 axxepting
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question