|
Trying to generate some images in Java. To visualize what the grid would look like:code:
I would eventually like to make it 3D for an isometric view but that isn't required and down the road.
|
# ? Oct 24, 2008 17:08 |
|
|
# ? Apr 28, 2024 05:27 |
|
You probably just want to draw into a BufferedImage and use ImageIO.write(RenderedImage,String,String) to write it out.
|
# ? Oct 24, 2008 17:27 |
|
Yea, that looks like more what I need to do. Didn't occur to me that I could do that. I've only used BufferedImages to modify existing images, never to create one from scratch.
|
# ? Oct 24, 2008 17:41 |
|
dvinnen posted:Yea, that looks like more what I need to do. Didn't occur to me that I could do that. I've only used BufferedImages to modify existing images, never to create one from scratch. Yeah, it's quite easy to create a new BufferedImage and just loop through all the pixels, filling them in with what you want. Something like this: code:
|
# ? Oct 24, 2008 19:03 |
|
Yeah, "BufferedImage" is just "in memory image". It's your go-to class for drawing stuff from what I've seen.
|
# ? Oct 24, 2008 20:33 |
|
Mill Town posted:Yeah, it's quite easy to create a new BufferedImage and just loop through all the pixels, filling them in with what you want. Something like this: Sweet, thanks man, looks like that is exactly what I needed to see. It looks like the line: code:
code:
code:
|
# ? Oct 27, 2008 14:25 |
|
I'm trying to create an arrayList of an object. The object is composed of three strings, and some simple methods. Constructor for my Calc object. code:
What I basically have now: code:
|
# ? Oct 27, 2008 23:37 |
|
Lazlo posted:Basically if you want to be able to print the object in a way that makes sense, you need to define your own toString() method in Calc: public String toString() { return name; } or whatever best suits your needs.
|
# ? Oct 27, 2008 23:44 |
|
Lazlo posted:I'm trying to create an arrayList of an object. The object is composed of three strings, and some simple methods. You need a toString() method in your Calc class, then when you print it out it should be: System.out.println("This is the Calc Object: " + al.get(arrayCount).toString()); // Don't actually need the .toString() part - it's automatically called. Something vaguely like this: code:
|
# ? Oct 27, 2008 23:45 |
|
Kilson posted:Cool, thanks. But what if I also want to retrieve the members individually, like "Units" and "Quantity" from a particular index, is there a way I can do that with a method in the Calc class?
|
# ? Oct 28, 2008 03:35 |
|
First of all you should be using generics, it makes your code much easier to work with since you don't have to cast your objects all the time. This has some other benefits like preventing accidentally adding an object that isn't a Calc into your arraylist.code:
code:
Janitor Prime fucked around with this message at 04:55 on Oct 28, 2008 |
# ? Oct 28, 2008 04:52 |
|
quote != edit
|
# ? Oct 28, 2008 04:53 |
|
Can someone please explain lazy deletion to me? I know you just mark something as being deleted rather then actually deleting it but I'm afraid I'm not quite sure what that means. Thanks
|
# ? Oct 29, 2008 20:03 |
|
.
lament.cfg fucked around with this message at 00:55 on Jan 15, 2011 |
# ? Oct 29, 2008 20:08 |
|
Startacus posted:Can someone please explain lazy deletion to me? I know you just mark something as being deleted rather then actually deleting it but I'm afraid I'm not quite sure what that means. In data structures, it usually means that you leave a hole in your structure (typically marked in some fashion, maybe using null as a sentinel) instead of actually cleaning up after yourself. In situations where deletion is rare, that can be a major win, at least in terms of development effort. traveling midget posted:But I'm basically oblivious as to what the Unit class should look like. DAYS should be a Unit object, but I have no clue how to represent them. There's an efficient solution which exploits the linear relationship between these units, and there's a less-efficient solution which addresses the general problem that Unit.DAYS and Unit.MINUTES might need to behave differently. If I've got two objects, and they need to behave differently when a particular method is called on them, what's the general way to achieve that?
|
# ? Oct 30, 2008 02:03 |
|
I'm playing around and messing with some programming homework and I'm getting a little stumped on this. This program basically uses a linked list and lets the user write a polynomial, input a number to be evaluated, and then returns the answer. So far I have all the math working, except I can't figure out a solution to print out the user's polynomial. Here is my code: Polynomial.java Node.java When I compile this code, I am getting this output: code:
lmao zebong fucked around with this message at 03:22 on Oct 31, 2008 |
# ? Oct 31, 2008 02:11 |
|
Sarah Sherman posted:I'm playing around and messing with some programming homework and I'm getting a little stumped on this. This program basically uses a linked list and lets the user write a polynomial, input a number to be evaluated, and then returns the answer. So far I have all the math working, except I can't figure out a solution to print out the user's polynomial. Here is my code: You will be really annoyed when you find out the answer. From where are you getting the values you are printing?
|
# ? Oct 31, 2008 08:15 |
|
ynef posted:You will be really annoyed when you find out the answer. Ah poo poo, thanks for the nudge in the right direction. Now I need to figure out a way to have it not print the polynomial until after the user is done inputting the numbers... if I try to do this: code:
code:
also, thanks a lot for the help.
|
# ? Oct 31, 2008 09:01 |
|
I'm assuming printPoly() prints all of the Polynomial's nodes each time it is called? How many times is printPoly() being called in your example?
|
# ? Oct 31, 2008 10:26 |
|
drat, now i'm thinking you guys know my code better than i do. thanks a lot for the help guys, it's always nice to have a couple fresh sets of eyes to catch the glaring errors in your code that you overlook.
|
# ? Oct 31, 2008 17:22 |
|
I have a question about JUnit, specifically the (now deprecated) swingui test runner. We've got an old version of JUnit (3.8.1) specifically because the teacher wanted the green bar for all testing, but we're having trouble getting it working. The window opens, but only while the tests are running. Does anyone know how to make it leave the window open after it's done? We're using Ant 1.7.1, I can post build.xml or anything else that's relevant. Thanks! [Fake edit] IDEs are verboten for this project. We're running everything from a command line.
|
# ? Oct 31, 2008 20:55 |
|
I need a way to search for a value through a hierarchical list, while keeping track of each descent made. The hierarchy may have an arbitrary number of levels (nodes), though probably less than ten. I think I can come up with a way to parse each line up using a Scanner, but I cant think of a good way to keep track of where Ive been in the hierarchy. Is there a package I could use to make navigating through the list easier? Example of the input I want to process: code:
|
# ? Oct 31, 2008 23:05 |
|
I'm stumped..here's my code:code:
code:
|
# ? Nov 1, 2008 01:10 |
|
You shouldn't compare objects with ==. Trying using the .equals method of the string. if( direction.equals("E") )
|
# ? Nov 1, 2008 02:17 |
|
MEAT TREAT posted:You shouldn't compare objects with ==. Trying using the .equals method of the string. ohhh yeahhh. Thank you
|
# ? Nov 1, 2008 02:25 |
|
Lazlo posted:I need a way to search for a value through a hierarchical list, while keeping track of each descent made. The hierarchy may have an arbitrary number of levels (nodes), though probably less than ten. As long as this file format is a regular language and not gigantic, I'd personally write a small parser in ANTLR. You'd end up writing a baby parser anyhow, but with ANTLR you have a ton of tools to help you, plus it's drat good at its job.
|
# ? Nov 1, 2008 19:25 |
|
alright guys, i got another linked list question for you. How do i delete a Node from the list? I have this code written:code:
|
# ? Nov 2, 2008 00:15 |
|
Sarah Sherman posted:however, for some reason it doesn't delete the node. This is how my teacher told the class to delete a node, but I guess it's not working. Any help? MEAT TREAT posted:You shouldn't compare objects with ==. Trying using the .equals method of the string.
|
# ? Nov 2, 2008 02:21 |
|
triplekungfu posted:
|
# ? Nov 2, 2008 06:55 |
|
Sarah Sherman posted:ah poo poo, i always forget about compareTo(). thanks. equals()
|
# ? Nov 2, 2008 15:17 |
|
TRex EaterofCars posted:As long as this file format is a regular language and not gigantic, I'd personally write a small parser in ANTLR. You'd end up writing a baby parser anyhow, but with ANTLR you have a ton of tools to help you, plus it's drat good at its job. Ok, ANTLR seems pretty cool, but as a novice, how difficult would it probably be to learn to use this tool, and then get it to work with the java code I've already got? So far, working from their tutorials and faq, I still can't get antlr to actually run yet.
|
# ? Nov 2, 2008 20:25 |
|
Hello. I'm writing a program in java to random seed a tournament. My initial inclination was to do this: Scanner input = new Scanner(System.in); System.out.println("Enter number of players:"); Integer num = input.nextInt(); Integer count=0; while (count <= num) { Random r = new Random(); int randint = r.nextInt(num); System.out.println(randint); count++; } But it creates repeats. I learned from #cobol that I need to add the numbers to a list and then shuffle the list. How do I do that?
|
# ? Nov 4, 2008 18:47 |
|
Collections.shuffle() shuffles a List object. You'll probably want an Arraylist.
|
# ? Nov 4, 2008 18:57 |
|
BELL END posted:Collections.shuffle() shuffles a List object. You'll probably want an Arraylist. Okay, but how exactly do I do that?
|
# ? Nov 4, 2008 18:57 |
|
Not at a compiler so I can't check this, but something along the lines of:code:
|
# ? Nov 4, 2008 19:00 |
|
The Light Eternal posted:But it creates repeats. I learned from #cobol that I need to add the numbers to a list and then shuffle the list. How do I do that? I must not've been in #cobol at the time Shuffling isn't the answer here. You're creating a new Random on each iteration of the while loop. By default, the Random object is seeded by the system time, which in a fast loop will be the same on each iteration of the loop. Two Random objects initialized with the same seed are guaranteed to produce the same pseudorandom sequence. That's why you're getting repeats. Always seed random objects outside of a loop unless you know why you're doing it any other way. code:
|
# ? Nov 4, 2008 19:44 |
|
While that's true, it won't necessarily stop the same number coming up more than once.
|
# ? Nov 4, 2008 19:47 |
|
BELL END posted:While that's true, it won't necessarily stop the same number coming up more than once. True, though it's a hell of a lot less likely. Anyway, I suspect his "repeats" problem looks something like this: 4 4 4 4 4 4 4 4 4 4 4 4 7 7 7 7 7 7 7 7 7 7 7 7 3 3 3 3 3 3 3 3 3 3 3 3 Besides, how is shuffling an answer to "preventing repeats" in the first place? It might space them further apart from each other, but they'd still be repeated in the sequence. Seriously shuffling is just not a solution to anything that has to do with repeats, unless your requirement is that two identical numbers can't be next to each other - and even then it's not a guarantee.
|
# ? Nov 4, 2008 19:55 |
|
In my example (assuming it works) you're creating an array of [1, 2, 3, 4, 5...] and then shuffling it so you know the numbers are different. I think that's what he was asking, maybe I'm reading the problem wrong.
|
# ? Nov 4, 2008 19:57 |
|
|
# ? Apr 28, 2024 05:27 |
|
BELL END posted:In my example (assuming it works) you're creating an array of [1, 2, 3, 4, 5...] and then shuffling it so you know the numbers are different. The fact remains that shuffling is never ever ever going to eliminate repeats or reliably spread them around if your sequence has repeats in it in the first place. I don't have a javac in front of me, but here's The Light Eternal's code in C#: code:
code:
code:
code:
code:
|
# ? Nov 4, 2008 20:24 |