Java Forum / First Aid / February 2006
Does any one use blueJ
sheldon.sc@gmail.com - 10 Feb 2006 20:43 GMT Does any one use Blue J Ive jsut started working on it Im doing this course from a book caleed object of java I need some help with some prgrams I hope somebodys there who can help me out I really dont know how to post this ova here So let me know caus I need to submit these assnmts on sunday
http://www.ucfv.bc.ca/cis/comp155/labs/lab01.htm
U will find a description of the assnmt on ht elink above Its realy simple but I cant seem to figure out the method to get a Random Color
sheldon.sc@gmail.com - 10 Feb 2006 20:52 GMT just doing it with a math. Random and no arrays just the simple stuff I dont know if there is any way that I can attach files here So that someone can check my code
Oliver Wong - 10 Feb 2006 21:12 GMT > just doing it with a math. Random and no arrays just the simple stuff > I dont know if there is any way that I can attach files here So that > someone can check my code The compiler will check your code for compilation errors. Then you, as a programmer, have to actually test your code by giving various inputs and seeing if it behaves the way you expect.
See http://home.earthlink.net/~patricia_shanahan/beginner.html
- Oliver
Roedy Green - 10 Feb 2006 21:54 GMT >just doing it with a math. Random and no arrays just the simple stuff >I dont know if there is any way that I can attach files here So that >someone can check my code just post them inline. It helps to keep lines short so they don't wrap, and to run them through beautifier so they are decently indented.
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
sheldon.sc@gmail.com - 10 Feb 2006 23:08 GMT ============= Director class ============== import aLibrary.*;
public class Director { private DotRand rDot; private DotBW bwDot; private Button selectButton, actionButton; private Dot dot; private AWindow win;
public Director() { //create the window win = new AWindow(100, 100, 300, 300); rDot = new DotRand(75, 100); bwDot = new DotBW(150, 100); rDot.place(win); bwDot.place(win); selectButton = new Button("Select", 60, 180,this); actionButton = new Button("Action", 150 ,180 ,this); selectButton.place(win); actionButton.place(win); win.repaint();
}//end method
public void getText(){ } public void doAction(Button b) { if (b.getText().equals("Action")) { dot.action(); } else if(dot instanceof DotRand) { dot = bwDot; } else { dot = rDot; } //end if else
win.repaint(); }//end method }//end class ============= Button class ============= import aLibrary.*; import java.awt.event.*;
public class Button extends AButton{
private Director theDirector;
public Button(String name, int x, int y, Director dir){ super(name,x, y, 70, 20); theDirector = dir; } public void action() {
} } ====== Dot class ======= import aLibrary.*; import java.awt.*;
public abstract class Dot extends AOval{
public Dot(int a, int b, int c, int d){ super(a,b,c,d);
}
public abstract void action(int a, int b, int c);
}//end class =========== DotRand class ========== import aLibrary.*; import java.awt.Color;
public class DotRand extends Dot{
public DotRand (int a, int b){ super(a, b, 50, 50);
} public void action(int red, int green, int blue) {
// Change the color of the canvas to a random color. red = (int)(256*Math.random()); green = (int)(256*Math.random()); blue = (int)(256*Math.random()); repaint(); } // end
}//end class ========== DotBw Class ========== import aLibrary.*; import java.awt.Color;
public class DotBW extends Dot{
public DotBW(int a, int b){ super(a, b, 50, 50); setColor(Color.black); setToFill();
} public void action(){ Color fillColor = rDot.getColor();
if(fillColor == Color.white) { theRectangle.setColor(Color.black); } else { theRectangle.setColor(Color.white); }//end if
theRectangle.repaint();
}
}//end class =================
Oliver Wong - 13 Feb 2006 14:35 GMT [code snipped]
Not sure if BlueJ has some sort of feature to counteract this, but I noticed that none of the classes you posted had a "static void main" method, and nothing inherits from Applet. Usually, Java applications need to have one of those two conditions fufilled in order to run.
- Oliver
Liz - 13 Feb 2006 18:25 GMT >[code snipped] > > Not sure if BlueJ has some sort of feature to counteract this, but I >noticed that none of the classes you posted had a "static void main" method, >and nothing inherits from Applet. Usually, Java applications need to have >one of those two conditions fufilled in order to run. Oliver, BlueJ is a simple IDE for use by students, and it has an "object testbed", where you can create instances without the need for a main method.
 Signature Liz
Oliver Wong - 13 Feb 2006 18:43 GMT >>[code snipped] >> [quoted text clipped - 7 lines] > "object testbed", where you can create instances without the need for > a main method. Okay, thanks.
To the OP, I'm presuming then that "Director" is your "main" class that gets everything going. It also looks like you're using some library called "aLibrary" which I'm not familiar with. So when you have code like:
<code> public class DotRand extends Dot{
public DotRand (int a, int b){ super(a, b, 50, 50);
} </code>
I have no idea what the super constructor does with the four parameters it received. If you had given the parameters more meaningful names than "a" and "b", I might have been able to guess what was going on, but as it is, I don't.
So I don't know how to actually create a dot with a random colour, but if you have questions about the Math class or the Random class, we can answer those, since they are documented on Sun's website.
- Oliver
Rhino - 11 Feb 2006 15:01 GMT > Does any one use Blue J > Ive jsut started working on it [quoted text clipped - 9 lines] > Its realy simple but I cant seem to figure out the method to get a > Random Color <rant> Please tell me that you are just learning English; I really don't want to believe that a Canadian University student with English as a first language could write as badly as you have.
What you said/what you meant to say:
> Does any one use Blue J Does anyone here use BlueJ?
> Ive jsut started working on it I've just started working on it.
> Im doing this course from a book caleed object of java I'm doing this course from a book called Object of Java. [maybe you mean "Objects in Java"??]
> I need some help with some prgrams I need some help with some programs.
> I hope somebodys there who can help me out I hope somebody here can help me out.
> I really dont know how to post this ova here I really don't know how to post here.
> So let me know caus I need to submit these assnmts on sunday So let me know because I need to submit these assignments on Sunday.
> http://www.ucfv.bc.ca/cis/comp155/labs/lab01.htm > > U will find a description of the assnmt on ht elink above You will find a description of the assignment at the link above.
> Its realy simple but I cant seem to figure out the method to get a > Random Color It's really simple but I can't seem to figure out the method to get a random Color.
I hope you don't plan to send out resumes written with such little care; you'll never get a job if you do, even in IT. Good communication skills are vital in any job.
By the way, let me emphasize that I take back everything - except the preceding paragraph - if you are new to English. I know English is a very difficult language for non-English speakers and if you're just starting to learn it, you're off to a reasonable start. Keep working at it and you'll be fine before too long.
But if you have lived your whole life in this country, your teachers and the politicians who run your school system should all be deeply ashamed for having done such a poor job of teaching you the dominant language in this country. If this counts as mastery of English these days, our educational system - and the country in general - is in deep trouble. </rant>
-- Rhino
sheldon.sc@gmail.com - 11 Feb 2006 19:53 GMT Thanks for the English course, I do appreciate it but that is not the reason why I had written in the first place. I was in a hurry because I had to leave to go meet a friend to help me with the assignment. Some of it was not intentional but thanks for pointing it out. May be you should have become a English teacher. You did not help at all. May be it's because of you that this country is such a beautiful place. Keep up the good work.
Rhino - 11 Feb 2006 21:02 GMT > Thanks for the English course, I do appreciate it but that is not the > reason why I had written in the first place. I was in a hurry because I [quoted text clipped - 3 lines] > it's because of you that this country is such a beautiful place. > Keep up the good work. You're welcome.
Considering your snotty attitude, you probably won't believe this but I was really just trying to encourage you to communicate in proper, correctly spelled sentences using capitalization and punctuation so that we would have a better chance of understanding your question. The sort of mangled English you put in your initial post was a complete turnoff to me and probably to some others. I just wanted you to understand that it is discourteous to your readers to write in such a sloppy way if you know better. Some people will refuse to read writing that is that bad even if they would normally be willing to help you. We all make allowances for people that are new to English but it's sheer laziness on your part to write mangled English when you can do better. I don't normally bother to help anyone who is that lazy.
As for generating a random Color, you were on the right track with your code: choosing an integer between 0 and 255 for each of the three colour components, Red, Green, and Blue sounds like a good approach to me.
If you look at the API for the Color class, you will see that there are a variety of constructors for Color. One of the most commonly-used ones, the sixth of the constructors in the Java 1.5.0_06 API, calls for three integers to be passed to the constructor. Therefore:
Color myBlack = new Color(0, 0, 0); Color myWhite = new Color(255, 255, 255); Color myRed = new Color(255, 0, 0); Color myBlue = new Color(0, 255, 0); Color myGreen = new Color(0, 0, 255);
You just need to put an expression that generates a random integer between 0 and 255 in each of the three parameters to the Color constructor. Something like:
Color myColor = new Color(<expression to calculate random int>, <expression to calculate random int>, <expression to calculate random int>);
Naturally, the text I put within angle brackets needs to get replaced by real code.
I'm not going to tell you the code; you'll learn more by working it out on your own. If you don't see how to do it, try looking at the Random class. The API may tell you enough that you can code it yourself but, if not, use a Google Groups search to find examples of the Random class in the comp.lang.java.* newsgroups.
Once you have constructor your new random Color, you simply have to use it. For example, if you are drawing an oval and want it to be your new Color, you'll need code like this (assuming you have already defined the random Color):
g.setColor(myColor); g.drawOval(90, 60, 20, 20);
In other words, you have to set the color that the drawing method is supposed to use, then draw the object(s) that you want drawn in that color.
That should be all you need to know to solve the problem you were having.
By the way, your problem really has nothing to do with BlueJ; it's really just a Java question. If you post here again at some point, try to choose a subject line that is more appropriate. For instance, a better title for this post would have been something like "Need help generating random Color". I almost didn't read your post at all because it looked like a BlueJ question and I don't know much about BlueJ.
-- Rhino
Roedy Green - 12 Feb 2006 04:58 GMT > May be you >should have become a English teacher. It is irritating, like deliberately mumbling. You write once, and many read, so it makes sense for you to put in some effort to make your post comprehensible.
It says between the lines, "You are not important. My time is valuable. Yours is not, so serve me you worm."
No wonder you get some backs up. It is more than about spelling.
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
Thomas Weidenfeller - 13 Feb 2006 10:07 GMT > Thanks for the English course, I do appreciate it but that is not the > reason why I had written in the first place. I was in a hurry because I > had to leave to go meet a friend to help me with the assignment. So you are more important than we are? Well, your post was so bad, that even I, as a non-native speaker, couldn't be bothered to decode it.
> You did not help at all. I think he was very helpful in explaining why you didn't get much help.
/Thomas
 Signature The comp.lang.java.gui FAQ: ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
trippy - 14 Feb 2006 05:34 GMT In article <1139604211.489490.63350@g44g2000cwa.googlegroups.com>, sheldon.sc@gmail.com took the hamburger, threw it on the grill, and I said "Oh wow"...
> Does any one use Blue J > Ive jsut started working on it [quoted text clipped - 9 lines] > Its realy simple but I cant seem to figure out the method to get a > Random Color Actually, Blue J makes a nice quick little testing environment when you just want to test a class or two. But I haven't used it in forever. I use J-Edit for all my java now but that'll change to probably eclipse when I take the last java class in my major. Even then I've talked to people that prefer J-Edit over eclipse. Sometimes, it's just easier to do stuff yourself. It's only a tool if you can use it. Otherwise, it's just a fancier rock.
Some of those plug-ins for Eclipse are beaucoup expensive too. Eclipse is free but the sweet toys that make it a dream (one would hope anyway) are expensive as hell. For the money I heard, it better be. 20k. Per computer. f.cking ouch. There's a development budget for ya. That's what I've heard anyway, I haven't seen it for myself. Maybe someone's who's kicked in the tires on them could tell you more about it.
 Signature trippy mhm31x9 Smeeter#29 WSD#30 sTaRShInE_mOOnBeAm aT HoTmAil dOt CoM
NP: "Jelly Roll" -- Blue Murder
"Now, technology's getting better all the time and that's fine, but most of the time all you need is a stick of gum, a pocketknife, and a smile."
-- Robert Redford "Spy Game"
sheldon.sc@gmail.com - 14 Feb 2006 08:48 GMT Well most of the colleges use blueJ because it is for student. I wanted to use Eclipse but I really don't know how to operate it. Well if you need it Ill upload it up for you. I really don't know if its the full version. I had a VB .Net mid term today so ill try to get back to the assignment. I'll try to complete it tonight. Will let you'll know how it goes.
sheldon.sc@gmail.com - 16 Feb 2006 02:47 GMT Now I cant figure out how to get a black and white dot. When it is white it has to have a black border so that we know that there is a circle that exists
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|