noobie needs help

K

kheris

hey! i was asked to do 2 tasks, but i don't know how. these are easy
tasks, i can't handle it as i've skipped lessons (explained how to do)
thx for your help

1)filled circle (and square) with color that i've to choose from
color-able box.
then i can move it on the square using mouse.

2)circles with random color and radius randomized from (0,r), where r
is lenght of the shorter edge from aplet. should be also checkbox-clear
screen before next circle appeared.
 
R

Rhino

hey! i was asked to do 2 tasks, but i don't know how. these are easy
tasks, i can't handle it as i've skipped lessons (explained how to do)
thx for your help

1)filled circle (and square) with color that i've to choose from
color-able box.
then i can move it on the square using mouse.

2)circles with random color and radius randomized from (0,r), where r
is lenght of the shorter edge from aplet. should be also checkbox-clear
screen before next circle appeared.
We prefer to handle homework questions on comp.lang.java.help. However, we
do not _not_ do your homework for you! If you ask clear questions there and
if you show your own best code to answer the question, you will probably get
some _hints_ on how to solve the problem.

You didn't _really_ expect that you could skip classes, then post your
homework questions and have someone hand you complete solutions did you?
 
L

Luc The Perverse

hey! i was asked to do 2 tasks, but i don't know how. these are easy
tasks, i can't handle it as i've skipped lessons (explained how to do)
thx for your help

1)filled circle (and square) with color that i've to choose from
color-able box.
then i can move it on the square using mouse.

2)circles with random color and radius randomized from (0,r), where r
is lenght of the shorter edge from aplet. should be also checkbox-clear
screen before next circle appeared.

So because you skipped lessons . . . that is our problem?

Here's a great idea - go back and do the lessons you skipped. It will be
far more beneficial to you than simply being provided an answer anyway.
 
U

uit_cs3(Java_pgmer)

Nice question.....
expect an aswer soon

i think for the random color and radius u could use Math.random()
function. it returns a value between 0 and 1 , so it will be decimal
value so multiply by 100 b4 proceeding.So the statment should be

int color_num = 100* Math.random();
int radius_num = 100* Math.random();

for filled circle use DrawFilledOval()

Rest of the questions
expect a aswers soon
 
K

kheris

how can i add box with avaible colors of circles appeared??

and-i skipped lessons not by truancy but beacose i was in hospital i
wasn't able to study and use computer
 
R

Rhino

how can i add box with avaible colors of circles appeared??

and-i skipped lessons not by truancy but beacose i was in hospital i
wasn't able to study and use computer
In that case, I'm surprised that the teacher is insisting that you complete
assignments for the time you were sick. But maybe the schools in Poland are
strict so here are some suggestions to get you started:
1)filled circle (and square) with color that i've to choose from
color-able box.
then i can move it on the square using mouse.

This sounds very much like you are supposed to use Java's "drag and drop" to
drag a color from one component of a GUI into another component.

This article should be very helpful in answering this question:
http://java.sun.com/docs/books/tutorial/uiswing/misc/dnd.html

I think you'll need to create a JColorChooser to serve as the palette of
colors from which you can choose. You'll probably want to create a JPanel so
that you can draw your circle and square; that should be easy.

The tricky part will be dragging and dropping your color on the circle and
square in the JPanel. You may need to write a custom TransferHandler to do
that; I'm not sure since I'm just learning to do drag and drop myself right
now. Getting the color from the color chooser shouldn't be too hard but
transferring that color to your circle and square may be difficult. (I'm
assuming that you want to be able to make the square a different color from
the circle and that both colors will be different from the background color
of the JPanel.)
2)circles with random color and radius randomized from (0,r), where r
is lenght of the shorter edge from aplet. should be also checkbox-clear
screen before next circle appeared.

Creating a random color is easy enough; you can simply choose three
different integers between 0 and 255 inclusive via a random number generator
(see the Random class) and then use these three integers to represent the
RGB (red, green, blue) values of a color.

Assuming you are drawing your circle in a JPanel, you can set the JPanel
dimensions with the setSize() or setPreferredSize() methods. Then, you can
ask the JPanel how big it is via the getSize() method and decide which is
the shorter dimension. Then, using the Graphics class, you can use the
setColor() method to establish the color that you want your circle to be,
then use the fillOval() method in the Graphics class to draw your circle;
the circle will be drawn the color that you established with setColor().
 
M

Monique Y. Mudama

In that case, I'm surprised that the teacher is insisting that you
complete assignments for the time you were sick.

Very much depends on the professor. I went to school in the US, and I
had a Diff EQ professor who told a friend of mine that his grandmother
dying was no excuse to turn in homework late. "If you really know the
material, emotions shouldn't get in the way." Right.

Same professor who, when I came to him asking for help, asked me what
my major was, then told me that I was bad at math and logic, so here
are the CS courses that would give me the most trouble. (Need I
mention he was dead wrong? Finite automata was my favorite class,
actually ...)
 
M

Monique Y. Mudama

i even don't know how to begin

Why are you taking this class? If you genuinely are interested in
computer science, then you need to learn the basics, even if it means
taking this course again. Yes, it would suck, but it would be better
than getting others to do your homework for this course, then finding
yourself stuck in the next.
 
K

kheris

all wright'

how can i drag and drop figure??
in wchich method (paint?) shall i put it in?
 
R

Rhino

Monique Y. Mudama said:
Very much depends on the professor.

That's why I gave him/her the benefit of the doubt and described the basic
approach to solving the problem. That should get the ball rolling; if the
questions were sincere, the original poster will probably need to come back
with some detailed questions and will show the code they built in response
to the various suggestions and we can help them fine tune the solution.

I'm sure every prof has a different set of conditions under which they will
give a student a break. You can be sure that the students will have tried
many different excuses over the years to see what succeeds in getting them
out of assignments from that particular prof and the rumour mill will have
distributed the information far and wide. Of course some students will even
lie and invent an illness or dying relative to get out of assignments.

I feel sorry for the prof in these situations; unless he/she is completely
rigid, he/she is going to want to believe what students say but will also
wonder if the student is just lying to them to get out of work. Asking for
proof will offend some students and possibly earn the prof a reputation as a
"nazi" but believing every student will soon earn the prof a reputation as a
pushover. Either way, bad feelings result.
I went to school in the US, and I
had a Diff EQ professor who told a friend of mine that his grandmother
dying was no excuse to turn in homework late. "If you really know the
material, emotions shouldn't get in the way." Right.
Maybe the prof thought your friend was making up the dying grandmother to
get out of work?
Same professor who, when I came to him asking for help, asked me what
my major was, then told me that I was bad at math and logic, so here
are the CS courses that would give me the most trouble. (Need I
mention he was dead wrong? Finite automata was my favorite class,
actually ...)
Telling a student that they're bad at the subject has always seemed like a
bad idea to me. An instructor should always try to encourage the student to
help make them believe in themselves and their ability to do the thing being
taught in the course. I don't mean that he should tell every student that
they're a genius - I don't have much use for false praise either - but the
instructor should certainly not disparage the student's innate abilities.

Some people will get things right away, some will have to struggle a while
before the light dawns, and a few might never get it but it's not because
they are brilliant or stupid; it has a lot more to do with how things are
presented to them. A given student may get what the prof is saying simply
because he explained it in the same way that the student thinks about
things; another student, equally smart, may not get it because he needed to
have it explained in a different way. In an ideal world, each instructor
would have enough time to present the information in several different ways
to each class so that everyone involved would hear the information presented
in a way that is meaningful to them. In the real world of course, the
instructor tends to present the material in whatever way it is laid out in
the text book or course notes and leave it to people who don't follow that
presentation to "translate" that information into terms they understand on
their own time.

One of my friends, Clive, is quite bright but has never learned much
programming; he had one or two courses years back but gave up on programming
when he couldn't understand arrays and array processing, particularly
multi-dimensional arrays. Then, one day, Clive and I and one of my friends
from university, Alex, were sitting down to eat at a social occasion. Alex
and Clive had never met before. Alex, started talking about programming
with me. He mentioned how he had once helped the light dawn for some
students who were struggling with arrays and described what he had said.
Clive, as a non-programmer, was just listening politely when suddenly his
face lit up: Alex's explanation had suddenly cleared away all of the
confusion he had had about arrays many years before and he suddenly got it.
It was a real "Eureka" moment for Clive. Clive was always bright; he just
hadn't had someone explain arrays in terms that made sense to him until that
moment.
 
S

Stefan Ram

Rhino said:
Telling a student that they're bad at the subject has always
seemed like a bad idea to me.

I usually had teachers that did /not/ tell me, when I was bad
at something ... so I had to find out the hard way. (And this
process is not even finished yet!)

So, it can actually be helpful to get to know this at the
right time. However, this might also be difficult for both
sides, so it simply might be more comfortable for the teacher
/not/ to tell you, even if it would be actually helpful to
you.

The first part »life lessons« by »Martin Scorsese« of the move
»New York Sories« (1989) deals with the subject, where a woman
desperately wants to get a word from her painting teacher
(played by Nick Nolte) about her giftedness. IIRC he seems to
refuse to tell her that she is not gifted because he still
wants to keep her as his lover. She begs him to tell him, if
she is not gifted, because then she will be able to stop to
waste her time on painting.

For example, when you start learning at a higher age you will
not become a master of some musical instruments however hard
you try and a good teacher should tell you so.
 
R

Roedy Green

R

Roedy Green

how can i add box with avaible colors of circles appeared??

and-i skipped lessons not by truancy but beacose i was in hospital i
wasn't able to study and use computer

Computer science is unlike most other subjects. You CAN'T skip a
lesson. Even missing a single POINT can make everything that comes
after sound like Greek. It is extremely cumulative.
 
M

Monique Y. Mudama

For example, when you start learning at a higher age you will not
become a master of some musical instruments however hard you try
and a good teacher should tell you so.

That assumes that the entire point of doing something is to be
incredibly good at it. I'd rather spend my time doing the things I
enjoy, even if I'm never going to be world famous for them.

I think it's incredibly unhealthy to hold the belief that you should
stick to what you're good at and drop what you're not. I've been
spending much of my life trying to fight that attitude in myself.
It's amazing how much perfectly enjoyable time you can ruin for
yourself by always holding out for the next better stage.
 
R

Rhino

all wright'

how can i drag and drop figure??

I'm not sure if you can drag and drop a figure: I assume you are talking
about dragging and dropping the circle or square. I think you can drag and
drop the color from the JColorChooser easily enough; that much is clear from
the article I cited earlier about Drag and Drop. I think you may have to
write a custom TransferHandler to copy the color from the JColorChooser and
then use that color in the method that draws your circle and square; you
could pass that color to the method and then do a setColor() within the
method to set the drawing color to the one passed in the custom
TransferHandler. Then your circle and square would be drawn in that color.
in wchich method (paint?) shall i put it in?
Yes, that sounds right.

I think the tricky bit will be to write the custom TransferHandler so that
the color will be "seen" by the paint() method. I am very new to drag and
drop myself so I don't know if the approach I suggested will work; it seems
reasonable but I don't know enough and drag and drop to be sure.

I don't see any examples of passing colors to paint() methods in that
article either so there is nothing that confirms whether my approach will
work or not.

Perhaps some drag and drop experts will jump in to confirm if this is a
valid approach?
 
L

Luc The Perverse

Monique Y. Mudama said:
Very much depends on the professor. I went to school in the US, and I
had a Diff EQ professor who told a friend of mine that his grandmother
dying was no excuse to turn in homework late. "If you really know the
material, emotions shouldn't get in the way." Right.

Same professor who, when I came to him asking for help, asked me what
my major was, then told me that I was bad at math and logic, so here
are the CS courses that would give me the most trouble. (Need I
mention he was dead wrong? Finite automata was my favorite class,
actually ...)

Well some people are just assholes - regardless of profession
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top