|
The way the UI thread works is this: 1. Have any events happened? 2. If yes, run the associated event handler 3. Have any events happened? One of those events is the window-drawing event - when something on the window changes and the whole thing needs to be redrawn, the redraw is processed much like any other event. If your event handling code locks itself up (say but doing a Thread.sleep()), then the redrawing code won't ever get to run until your event handler finishes up. You basically need to be using the timer class - make sure you're using the javax.swing.Timer version, as you can run into threading issues with java.util.Timer.
|
# ? Feb 28, 2011 00:34 |
|
|
# ? Jun 11, 2024 23:38 |
|
Paolomania posted:I'd like to use this on our log processing options page, but someone might think that's "unprofessional". I think you can't get any more professional than a machine like that.
|
# ? Feb 28, 2011 16:23 |
|
Cojawfee posted:After a few years of doing nothing, I've decided to get back into Java. I want to redo some dungeon crawler game I made for a final project in high school. I'm off to a somewhat decent start as NetBeans easily created a nice GUI for me (the one I made in high school was some sort of Frankenstein's monster I created out of frantic googlings of Swing and AWT). But I've fallen into an old habit where I want to try something that I probably will never use but I can't move forward until I've made it work. Try and use SwingWorker! Have some code: code:
|
# ? Feb 28, 2011 20:02 |
|
I need to do some simple stuff in Java ME, what would be the best SDK/ GUI to go about it?
|
# ? Mar 1, 2011 18:38 |
|
cisneros posted:I need to do some simple stuff in Java ME, what would be the best SDK/ GUI to go about it? There's Java ME SDK 3.0 for Windows which is the latest official SDK. You can use the Java ME SDK 3.0 with Eclipse by installing a Mobile Tools for Java plugin. The SDK has a UI for compiling, running and packaging so you may not need an IDE at all. Then there's the older Wireless Toolkit 2.5.x that's available on Linux as well. Java ME consists of few related technologies, so it's hard to give better suggestions without knowing what devices you're targeting and how simple your stuff is.
|
# ? Mar 1, 2011 21:35 |
|
Alright, in my java programming class I'm doing a change calculator. Underwhelming I know. I know for a fact I am doing many things wrong on the math but I am not sure how to fix it properly, and I can't figure out how to display the final results properly, those being my only two problems.code posted:import java.util.Scanner; e: accidentally posted while trying to indent (tab and space), but I have the feeling it is still readable this way. e2: after much dickery this is the best I can get it, sorry Speed fucked around with this message at 03:09 on Mar 2, 2011 |
# ? Mar 2, 2011 02:52 |
|
Do you have a question about how to do something specific aside from "fix my program"? Displaying one of your computed values is as simple as System.out.println("Silly Canadian two-dollar coins = " + toonies);
|
# ? Mar 2, 2011 03:27 |
|
Yeah I guess it looked like that. Something specific is that whenever I get a value displayed it comes out as 0.0, I can't figure out what is causing this. Solving that would be a better start for me, as I could just go the long way for displaying all of the values.
|
# ? Mar 2, 2011 03:38 |
|
I am in posted:There's Java ME SDK 3.0 for Windows which is the latest official SDK. You can use the Java ME SDK 3.0 with Eclipse by installing a Mobile Tools for Java plugin. The SDK has a UI for compiling, running and packaging so you may not need an IDE at all. Then there's the older Wireless Toolkit 2.5.x that's available on Linux as well. Just some basic matrix stuff(rref, etc), I had that sdk you linked, but for some reason it doesn't run on my machine, but I got a complete version of NetBeans and that did the trick.
|
# ? Mar 2, 2011 04:18 |
|
while (option < 1|| 6>6 ){ what edit: also, tip: '1' != 1.
|
# ? Mar 2, 2011 04:20 |
|
E: I completely overthought this entire thing and I am an idiot case 1:while (money >2){ money = money - 2; ++toonies; } All I had to do to overcome this stupidly easy thing. Speed fucked around with this message at 05:16 on Mar 2, 2011 |
# ? Mar 2, 2011 04:40 |
|
Speed posted:Well I basically rewrote the program and got rid of the ' and that incredibly weird while loop (no idea when I put that in or why). Its working now for the most part, the only problem being that remainders exist so I'm getting 5.375 when dividing 10.75 by 2, I'm not sure what to do about that though. But this has been help anyway so thank you. int a = (int) (10.75 / 2); But something important to know is to never ever using floating-point math when ever dealing with money ever. (That means no floats, no doubles, no decimals.) As an example of why, compile and run this: code:
|
# ? Mar 2, 2011 05:14 |
|
Aleksei Vasiliev posted:But something important to know is to never ever using floating-point math when ever dealing with money ever. Specifically if you're doing any sort of arithmetic at all.
|
# ? Mar 2, 2011 18:26 |
|
Fly posted:Repeat the above line 100 times. Every time I encounter money as float I first feel a twinge of self satisfaction knowing I'm not that dumb, then I feel an overwhelming sense of dread as I've probably just nicked the tip of the iceberg.
|
# ? Mar 3, 2011 01:37 |
|
So, I'm dealing with a String that could be in one of two formats. Either ABC or BC, where A/C are a positive integer, and B is the letter S. I need a way to split the String into it's pieces. I've tried using String.trim().split("S"), but for the Array I get from that, .size() returns 2, even if the format is AX. I tried using a scanner, using this code: Scanner scanForNums = new Scanner(a); if (scanForNums.hasNextInt()) { test.add(scanForNums.nextInt()); } System.out.println(test.size()); but then test.size() returns 0, so I can't use that. My best guess right now, is to use .split, because it at least gives me the correct pieces, and I count them manually with an int to know how many there are. Any ideas better than that? BTW, the goal of this is to return an ArrayList containing the A instances of the String "BC".
|
# ? Mar 3, 2011 04:00 |
|
How about just:code:
|
# ? Mar 3, 2011 05:42 |
|
Seafea posted:So, I'm dealing with a String that could be in one of two formats. Either ABC or BC, where A/C are a positive integer, and B is the letter S. So you want to return the ones that are <number>S<number> in a list, and not the ones that are S<number>? Or you want to return only the first number from the instances that have an S in the middle? (I'm a little confused about your change in lettering, from ABC/BC to AX to 'the A instances of the String "BC"') Why not just just use .startsWith("S") to determine which case you're in, then you can do .substring(0, .firstInstance("S")) or whatever to get the first number (if that's what you're looking for??)?
|
# ? Mar 3, 2011 05:48 |
|
Kilson posted:So you want to return the ones that are <number>S<number> in a list, and not the ones that are S<number>? Or you want to return only the first number from the instances that have an S in the middle? (I'm a little confused about your change in lettering, from ABC/BC to AX to 'the A instances of the String "BC"') I need it in 2 different blocks of code. The first one just strips that first coeffecient, leaving me with BC. The second one will add A instances of BC to an ArrayList. (I guess I could create a class for that that would just hold A and BC, to waste less space in ArrayLists, but don't need to for the moment.) Oops. I had the lettering as AXA at first, and changed it to clarify that the two A's did not have to be the same integer. I like the .startsWith("S") though. It's a simple solution I overlooked. Thanks!
|
# ? Mar 3, 2011 07:45 |
|
Is there any simple way to perform an action without notifying a listener? I've got a JXTreeTable with a tree expansion listener on it, which I want to get notified when a single node is expanded, but not when the "expand all" function is used (this just iterates over each row and attempts to expand it). The issue is that on expansion the table creates a hashtable of all the entries, in order to determine which colour the rows will be. However if there are, say, 20,000 entries in the table, when all are expanded the listener will be notified 20,000 times, which will then go over all 20,000 records for each notification.
|
# ? Mar 3, 2011 15:10 |
|
Probably easier for your expansion listener to just ignore expansion of the root.
|
# ? Mar 3, 2011 17:41 |
|
I'm trying to extract a bodypart from a MIME Multipart message. I get the correct bodypart and everything, but this code isn't working as I understand it should.code:
java.lang.ClassCastException: javax.mail.internet.MimeBodyPart cannot be cast to java.lang.String I don't understand why bp.getContent() would give me back a MimeBodyPart. Setting the DataHandler as text/plain is supposed to give me back a String. Also, I'm pretty sure this code used to work. Is there a proper way to do this?
|
# ? Mar 4, 2011 21:05 |
|
Well, I don't know specifically an answer (never used), however, the documentation MimePart.getContent says that it always returns a subclass of MultiPart for objects that are a multipart type, which I assume your MimeBodyPart would be in this case.
|
# ? Mar 5, 2011 01:33 |
|
After a year of developing Java EE apps in Eclipse, I've now been asked to switch to Maven by Monday. Does anyone have any suggestions for quality online resources that can show me the "best practices" of Maven? It seems like there's an archetype for everything-- many of which are old, or just plain fail when I try to use them to build a project. I'm starting to wonder if most folks just use a "generic" archetype of some sort and then put a shitload of dependencies in the POM.
|
# ? Mar 6, 2011 02:40 |
|
MariusMcG posted:After a year of developing Java EE apps in Eclipse, I've now been asked to switch to Maven by Monday. Does anyone have any suggestions for quality online resources that can show me the "best practices" of Maven? It seems like there's an archetype for everything-- many of which are old, or just plain fail when I try to use them to build a project. I'm starting to wonder if most folks just use a "generic" archetype of some sort and then put a shitload of dependencies in the POM. I've always freeloaded on this, but I wouldn't think you'd contrast the two. You layout your war or ear projects the way maven wants, run mvn eclipse:eclipse (or mvn eclipse:m2eclipse) then continue developing in eclipse like you always have. m2eclipse has good user doc.
|
# ? Mar 6, 2011 03:11 |
|
covener posted:I've always freeloaded on this, but I wouldn't think you'd contrast the two. m2eclipse? Thanks; I'll read through that. I'm a complete newbie to Maven, and am eventually looking to build these projects on the server using Hudson, so I figure it'd be best to learn how most folks do this while I'm learning Maven in general.
|
# ? Mar 6, 2011 03:18 |
|
What are some decent frameworks that anyone can recommend I take a look at - I know a bit about what's out there, but I've been mainly stuck in Struts and Apache Jackrabbit / Sling for the last 5 years and really haven't really looked. I have the opportunity to possibly pick something fresh (for me anyway) for a small freelance project I'm taking. The project is a licensed search-oriented application based on pre-defined content - there are other details to be handled but that is the bulk of the application.
|
# ? Mar 6, 2011 18:55 |
|
geeves posted:What are some decent frameworks that anyone can recommend I take a look at - I know a bit about what's out there, but I've been mainly stuck in Struts and Apache Jackrabbit / Sling for the last 5 years and really haven't really looked. I have the opportunity to possibly pick something fresh (for me anyway) for a small freelance project I'm taking. I dig straight-up Java EE 6, man. EJB 3.1, CDI, Bean Validation, and JSF... Very powerful stuff.
|
# ? Mar 6, 2011 20:08 |
|
geeves posted:What are some decent frameworks that anyone can recommend I take a look at - I know a bit about what's out there, but I've been mainly stuck in Struts and Apache Jackrabbit / Sling for the last 5 years and really haven't really looked. I have the opportunity to possibly pick something fresh (for me anyway) for a small freelance project I'm taking. Spring Grails if you want a full on web thing Guice is supposedly nice Solr for search rules
|
# ? Mar 6, 2011 20:55 |
|
geeves posted:What are some decent frameworks that anyone can recommend I take a look at - I know a bit about what's out there, but I've been mainly stuck in Struts and Apache Jackrabbit / Sling for the last 5 years and really haven't really looked. I have the opportunity to possibly pick something fresh (for me anyway) for a small freelance project I'm taking.
|
# ? Mar 7, 2011 14:13 |
|
Been playing with GWT at work, kinda cool but kinda dumb. Would learn some Spring if you've never worked with it though
|
# ? Mar 7, 2011 16:23 |
|
geeves posted:What are some decent frameworks that anyone can recommend I take a look at - I know a bit about what's out there, but I've been mainly stuck in Struts and Apache Jackrabbit / Sling for the last 5 years and really haven't really looked. I have the opportunity to possibly pick something fresh (for me anyway) for a small freelance project I'm taking. Though at this point it's probably better go straight to Seam 3.0 as it's getting close to release and 3.0 brings portable CDI based on EE 6.
|
# ? Mar 7, 2011 19:11 |
|
osama bin diesel posted:Been playing with GWT at work, kinda cool but kinda dumb. Would learn some Spring if you've never worked with it though GWT is terrible for anything of any size or complexity.
|
# ? Mar 8, 2011 01:55 |
|
Stubb Dogg posted:I recently worked on a project with Seam 2.2 and it removed lots of usual annoying stuff you have to deal with when doing complex web sites in Java and made it actually enjoyable. Thanks to everyone who responded - seems it was all for naught though - for at least the demo. I have to convert their DB from... Filemaker Pro to MySQL. 1 million records which will convert to about 25k after properly designing the DB. Unfortunately it seems I'll be doing the proof of concept in PHP since more of my time is being spent converting this database - as well as hosting it myself.
|
# ? Mar 8, 2011 05:02 |
|
I was wondering if anyone could help me out here, I'm currently in a high school computer science 2 class and our current project (and final for the year)is as a class we're writing super smash brothers as a class (teacher included). The only real requirements is that every piece of code besides the engine must be written from scratch. Here lies our problem, none of my classmates (There's 7 of us) except for one guy knows jack poo poo about writing a physics engine. That one guy however also has to handle all of the networking code because he is the only one in the class that knows anything about networking as well. Most of us all feel that it's not exactly fair or going to be efficant for him to be writing the two most important parts of the code. My question is does anyone know any opensource 2D physics engines that are relatively good and easy to understand? I've stumbled around trying to look for a decent one and came across Phys2D as well as JBullet. The problem is our teacher doesn't like the idea of using JBullet (or couldn't understand the code) so we're back at square one. So to make this short and simple, does anyone know a decent opensource 2D physics engine that would be acceptable for writing a java version of Super Smash Brothers? keep in mind this doesn't have to be perfect we're a bunch of worthless highschool students.
|
# ? Mar 11, 2011 06:40 |
|
If you're just trying to make a sidescrolling beat-em-up, do you really need to do that much in terms of physics? For a 2D game, you need to understand two concepts- collision and movement. Checking if the hitboxes for two sprites overlap doesn't have to be any more complicated than: code:
The other easy option is doing circular collision- compare the distance between the centerpoints of your sprites and see if they're closer than a bounding radius. Apply the pythagorean theorem. For movement, crack open a calculus textbook. It'll contain about five percent concepts and ninety-five percent algebra and applications- focus on that first five percent. Think about how things in your game move in terms of changes to their position, their velocity and their acceleration. Gravity is a constant acceleration downards. Hitting a horizontal or vertical wall multiplies the vertical or horizontal component of the object's velocity, respectively, by something close to -1. Play with it. Just try to think like a developer for the NES. If something is hard, is there some way you can fake it or simplify it? Taking a conservative, aggressively DIY approach may not create the most impressive game in the world, but you'll learn way more than you would by using a physics engine you barely understand. Just my two cents. If you try to do things from scratch and run into specific problems along the way, I'm sure we'd be happy to offer suggestions.
|
# ? Mar 11, 2011 07:11 |
|
Internet Janitor posted:Gravity is a constant acceleration downards. Hitting a horizontal or vertical wall multiplies the vertical or horizontal component of the object's velocity, respectively, by something close to -1. Play with it. Your post was all good advice, I just want to add that having a terminal velocity is a very good idea.
|
# ? Mar 11, 2011 10:27 |
|
baquerd: Oh yeah, totally. You should also have a minimum velocity cutoff so that friction makes things stop eventually. I didn't mean for that to sound like an exhaustive explanation.
|
# ? Mar 11, 2011 17:12 |
|
Thanks for the help guys, I really appreciate it. We were looking at using an open source engine just for the purpose of saving time since we only have about 7 weeks to write everything else. However three of us just ended up getting together and writing our own. So far we have friction, gravity and jumping and all of our characters are going to inherit or be based off a basic rectangle (am I saying that right?) On a completely unrelated note from this project, 7 years ago or so my computer science teacher had the class at the time write their own version of Legend of Zelda. The class never got very far other than creating a basic dungeon you could walk through that had a short midi sound file playing in the background. You could "attack" but you wouldn't do any damage and there was only one little enemy that didn't attack you but he also couldn't be killed. The weird issue is and it's an issue we believe with how the sound threading was coded? (I'm trying to explain things that are over my head again) however when the midi file for the dungeon sound ends the program closes and no one can figure out why the hell this happens. anyone have any ideas on what the problem could be? like I said it was coded by the kids who took his class 7 years ago so other than having the code I really don't know anything about how it was written. again, thanks for the help guys.
|
# ? Mar 11, 2011 22:32 |
|
For hitboxes I would favor composition (a character has a rectangle used for collision) over inheritance (a character is a rectangle that can collide with things), but either approach can work. If you start to have a more complex hierarchy of things in your game that are similar to characters you'll probably see where I'm coming from with this. Without the code that sound issue will probably remain shrouded in mystery. If you can pastebin the source to whatever class was responsible for playing music we might be able to figure it out. Do you know if the game crashes with an exception or just exits cleanly?
|
# ? Mar 11, 2011 23:09 |
|
|
# ? Jun 11, 2024 23:38 |
|
In my programming class I'm working on a project where I have a JPanel class that I am going to put several rectangles on (by using fillRect in its paint method), and am going to be able to move the rectangles around with the mouse. My problem is, the only way I can think of checking if a rectangle is being clicked is by checking if the mouse event's xy-coordinates are within the rectangle's boundaries, which causes issues when I click over an area where two rectangles are overlapping where both rectangles snap to one location, so one is covering the other. Is there another way to check if a rectangle is being selected? Or at least some way for my program to know which rectangle is above another?
|
# ? Mar 12, 2011 10:30 |