|
Why does Java allow $ and _ as valid variable names? Apparently it's legacy, and I'm wondering what it was used for. (edit: Apparently only $ is legacy) Somewhat relevant to the card talk, here's a Fisher-Yates shuffle: code:
Malloc Voidstar fucked around with this message at 12:23 on Dec 10, 2010 |
# ? Dec 10, 2010 11:55 |
|
|
# ? May 9, 2024 14:37 |
|
Why shouldn't they be allowed? The language shouldn't mandate what is and isn't a good identifier; in general, it's an impossible decision for a compiler to make. I think that the above is negligibly less understandable thancode:
|
# ? Dec 10, 2010 14:56 |
|
AV: There are a ton of valid unicode characters, too. I know there's at least one valid character that is invisible and a number of characters (like capital Alpha) that share glyphs with normal Latin characters. Unicode is a massive bag of worms no matter how you slice it. Did you know unicode escapes (\uXXXX) are processed before tokenization?
|
# ? Dec 10, 2010 15:25 |
|
I can see why they've chosen not to fix it. A Unicode Character 'ZERO WIDTH NO-BREAK SPACE' (U+FEFF) written in UTF8 encoding should be able to be read back using the inverse code, but that's not possible:Unicode.org posted:Q: I am using a protocol that has BOM at the start of text. How do I represent an initial ZWNBSP? The root cause is that Unicode uses bytes 0000FEFF, FFFE0000, FEFF, FFFE, EFBBBF as a byte-order mark when in actuality they are magic numbers that specify the format of the contents that follows: UTF-32 (variant A) = 0000FEFF + UTF-32BE UTF-32 (variant B) = FFFE0000 + UTF-32LE UTF-16 (variant A) = FEFF + UTF-16BE UTF-16 (variant B) = FFFE + UTF-16LE But for UTF8, the magic number is optional, worse yet it's a valid byte sequence in the contents that follows. The problem is in the Unicode Standard. In Java it could be fixed by adding a new Charset UTF-8B that writes the BOM to start and reads a BOM from start if one is present.
|
# ? Dec 10, 2010 16:24 |
|
Internet Janitor posted:Did you know unicode escapes (\uXXXX) are processed before tokenization? Man was I confused over that. Also I didn't know Unicode characters are valid identifiers, which is fun. But why does Oracle specifically point out never ever to use $? (Here, Naming section) edit: I am in posted:But for UTF8, the magic number is optional, worse yet it's a valid byte sequence in the contents that follows. Malloc Voidstar fucked around with this message at 16:58 on Dec 10, 2010 |
# ? Dec 10, 2010 16:25 |
|
Aleksei Vasiliev posted:Why does Java allow $ and _ as valid variable names? How else could you write something like this? code:
Parantumaton fucked around with this message at 16:52 on Dec 10, 2010 |
# ? Dec 10, 2010 16:50 |
|
Aleksei Vasiliev posted:ZWNBSP was deprecated in 2002. U+FEFF, mid-stream, is supposed to be treated as a zero-width non-breaking space because it does nothing. As long as it is supposed to be treated in any way other than as an invalid byte sequence the problem remains. But eight years should be long enough time to finally disallow that codepoint
|
# ? Dec 10, 2010 17:43 |
|
Aleksei Vasiliev posted:But why does Oracle specifically point out never ever to use $? (Here, Naming section) Inner classes (and closures in other languages) use $ to denote their "inner-classness" when javac builds their class files. It's probably just so you never run into a situation where an inner class name collides with a variable you made.
|
# ? Dec 10, 2010 19:23 |
|
Necc0 posted:for the life of me I can't figure out how graphics2D is supposed to work. the two relevant classes: fwiw The paintComponent method isn't being called at all if that helps any. Anyone have any ideas?
|
# ? Dec 10, 2010 19:30 |
|
TRex EaterofCars posted:Inner classes (and closures in other languages) use $ to denote their "inner-classness" when javac builds their class files. It's probably just so you never run into a situation where an inner class name collides with a variable you made. They wouldn't collide. Inner classes look like FooClass$BadName (inner class BadName) as opposed to FooClass.$BadName (class member $BadName).
|
# ? Dec 10, 2010 20:31 |
|
Paolomania posted:They wouldn't collide. Inner classes look like FooClass$BadName (inner class BadName) as opposed to FooClass.$BadName (class member $BadName). ...but it doesn't matter, I tried to make it collide and javac figured it out fine.
|
# ? Dec 10, 2010 20:40 |
Is there any way that I can use the batik rasterizer in a webapp without having to execute a shell command or write to the local file system?
|
|
# ? Dec 10, 2010 20:55 |
|
fletcher posted:Is there any way that I can use the batik rasterizer in a webapp without having to execute a shell command or write to the local file system? You can get the source... just dick around with the methods that handle the argument list and you should be able to figure out how to call it from within your program.
|
# ? Dec 10, 2010 21:11 |
|
fletcher posted:Is there any way that I can use the batik rasterizer in a webapp without having to execute a shell command or write to the local file system? Though using PNGTranscoder instead of JPEGTranscoder, obviously. And don't use a FileOutputStream, keep it in memeory.
|
# ? Dec 10, 2010 21:48 |
Aleksei Vasiliev posted:http://xmlgraphics.apache.org/batik/using/transcoder.html#createImage Sweet! Thank you!
|
|
# ? Dec 10, 2010 22:37 |
|
Necc0 posted:fwiw The paintComponent method isn't being called at all if that helps any. Anyone have any ideas? anyone? I still haven't figured this out and I'm ready to scream.
|
# ? Dec 12, 2010 01:52 |
|
Necc0 posted:anyone? I still haven't figured this out and I'm ready to scream. ShardPhoenix fucked around with this message at 06:13 on Dec 12, 2010 |
# ? Dec 12, 2010 03:20 |
|
ShardPhoenix posted:Your code is pretty complicated, try doing something simpler and see if you can get drawing working at all. Also, I don't know why you have separate Graphics2d objects for each image (I'm no expect on Java graphics but when I've done it, I've had one graphics object that I used to draw everything). I create separate java graphics objects per layer of rendering- specifically its useful if you need to apply different AffineTransforms to the different drawing layers in a game.
|
# ? Dec 12, 2010 04:36 |
|
I cant figure out for the life of me what this swing component is named. Its pretty much a JComboBox but instead of dropping down, it has an up/down arrow button on the right side. It is used through going through a large amount of data or selecting numbers or anything that is in an order.
|
# ? Dec 12, 2010 08:40 |
|
Stealthgerbil posted:I cant figure out for the life of me what this swing component is named. Its pretty much a JComboBox but instead of dropping down, it has an up/down arrow button on the right side. It is used through going through a large amount of data or selecting numbers or anything that is in an order. JSpinner
|
# ? Dec 12, 2010 08:55 |
|
Is there a more-proper way to do what I'm doing here?code:
quote:Germany, 421 It works fine, but I'm wondering if I'm going about this in completely the wrong way.
|
# ? Dec 12, 2010 12:43 |
|
SortedMap perhaps? edit: oh, sorting on value, nevermind.
|
# ? Dec 12, 2010 14:27 |
|
Seems fine to me. If you're going to hand the result list off to someone else you should consider creating your own immutable value class to hold the key-value pairs. The reasons are the Entries might hold a reference to the HashMap preventing it from being GC'd and your API shouldn't be leaking implementation details.
|
# ? Dec 12, 2010 14:50 |
|
I have been having some trouble setting up the JSpinner to retrieve data from my database. While it works perfectly, I have it so that each time the JSpinner changeevent happens, it connects to the database and executes an SQL statement. While it works for my purpose, I feel that connecting and doing a statement every time that the user changes the value in the JSpinner is terribly inefficient. I cant figure out the proper way to just pass the entire resultset into the changeevent. Ideally I would have it initialize the connection when the panel loads, do the SQL statement and pass the resultset into the changevent. Then when the program is closed, it will close the connection with the database. I know that just doing one connection and one SQL statement is way better then doing it every time the user wants to retrieve the value. At the moment, I have it check how many rows there are and then set the range for the JSpinner to that amount. Then when you click the JSpinner, it will retrieve the values from the row number. Edit: I really just cant figure out how to pass the resultset into the changelistener I am totally stuck unless there is a better way Stealthgerbil fucked around with this message at 00:32 on Dec 13, 2010 |
# ? Dec 12, 2010 22:14 |
|
When the panel loads, execute your SQL query to get your list of values for the spinner, use getArray to get the column that has your values in from the ResultSet, and create a SpinnerListModel with the Array. Then when you create the JSpinner you pass it the SpinnerListModel. e: If I've correctly understood what you're trying to do. chippy fucked around with this message at 03:20 on Dec 13, 2010 |
# ? Dec 13, 2010 03:01 |
|
chippy posted:When the panel loads, execute your SQL query to get your list of values for the spinner, use getArray to get the column that has your values in from the ResultSet, and create a SpinnerListModel with the Array. Then when you create the JSpinner you pass it the SpinnerListModel. This actually helped some however I figured it out. My current problem is pretty much increasing the range of the JSpinner and refreshing the ResultSet. Once I add in a value, it doesn't appear until I exit and reopen the program. Obviously that wont work. Is there a way just to like reload the panel or just increase the range of the JSpinner and retrieve another resultset? Here is my code so far if it helps http://pastebin.com/JnAr4C9R edit: Well I just created a method in the frame class which deletes the tab and re-adds it and it works :P I guess that's java for you... Stealthgerbil fucked around with this message at 07:30 on Dec 13, 2010 |
# ? Dec 13, 2010 06:01 |
|
The real solution is to have your model live outside the scope of that method so that when you refresh the model the JSpinner updates automatically.
|
# ? Dec 13, 2010 16:07 |
|
ShardPhoenix posted:Your code is pretty complicated, try doing something simpler and see if you can get drawing working at all. Also, I don't know why you have separate Graphics2d objects for each image (I'm no expert on Java graphics but when I've done it, I've had one graphics object that I used to draw everything). this: Surface posted:I create separate java graphics objects per layer of rendering- specifically its useful if you need to apply different AffineTransforms to the different drawing layers in a game. Is exactly right. We're going to have the map, objects on the map, other players on the server, your own character, and a HUD, eventually. All of these can be pointing their own directions. This is really frustrating for me because usually this isn't an issue, and I've used Graphics2D in the past without any problems. For some reason *this time* I'm getting all sorts of hell.
|
# ? Dec 13, 2010 19:57 |
|
Necc0 posted:anyone? I still haven't figured this out and I'm ready to scream. Have you created a thread that calls paint() (...or repaint()) on the JFrame (Display)? Swing only repaints components when needed unless you make it do otherwise. On StackOverflow I answered a question about how to setup a tile based game, some of what is explained there might help you: http://stackoverflow.com/questions/4189267/2d-java-game-moving-sprite-above-tiled-images/4189601#4189601 Here are some extracts: Surface (instanceofTom) on StackOverflow posted:A technique that works well for me is to separate the drawing logic of each layer into a separate class that implements the Painter interface (or a similar interface you define).
|
# ? Dec 14, 2010 01:18 |
|
I've created a GUI in Java using the Swing containers, but I can't figure out how to connect the buttons on the GUI to the code. All the examples I've seen have the buttons being created in the code, or they only have one button which doesn't have a label (so I don't know how it can tell the difference between different buttons). When using Swing, is it wrong to create the GUI first and the code later?
|
# ? Dec 14, 2010 02:15 |
|
Surface posted:Have you created a thread that calls paint() (...or repaint()) on the JFrame (Display)? Swing only repaints components when needed unless you make it do otherwise. Are you saying the display class will have to call the draw's paintComponent with the paint call? Like, draw.repaint() or something like that? I thought that calling this.repaint inside it's own thread would handle that.
|
# ? Dec 14, 2010 02:18 |
|
Aleksei Vasiliev posted:Somewhat relevant to the card talk, here's a Fisher-Yates shuffle: Good to see you're all coming around to writing Perl . Here's a Christmas present. code:
|
# ? Dec 14, 2010 02:23 |
|
Necc0 posted:Are you saying the display class will have to call the draw's paintComponent with the paint call? Like, draw.repaint() or something like that? I thought that calling this.repaint inside it's own thread would handle that. Didn't see you calling repaint() on line 121 (by pastebin), that is the type of call I was talking about. Swing is setup so that (re)paint() calls should eventually call paintComponent, but you said it isn't being called? Just for grins try overriding the paint() method and placing the code from paintComponent() in there. You should figure out why paintComponent is not being called though. Surface fucked around with this message at 02:30 on Dec 14, 2010 |
# ? Dec 14, 2010 02:25 |
|
This is driving me nuts Surface posted:Swing is setup so that (re)paint() calls should eventually call paintComponent, but you said it isn't being called? Just for grins try overriding the paint() method and placing the code from paintComponent() in there. You should figure out why paintComponent is not being called though. Correct. I know the thread is declared correctly as the println in the run() is printing, but the println in paintComponent() isn't. No clue. I'll try overriding the paint() method tomorrow to see what happens. Necc0 fucked around with this message at 04:00 on Dec 14, 2010 |
# ? Dec 14, 2010 02:28 |
|
Otto Skorzeny posted:Good to see you're all coming around to writing Perl . Here's a Christmas present.
|
# ? Dec 14, 2010 04:36 |
|
How would one write a method that would translate a text file into a 2-dimensional character array with whitespace? IE: code:
{{'X',' ','X',' ','X'}, {' ','X',' ','X',' '}, {'X',' ','X',' ','X'}}
|
# ? Dec 16, 2010 00:12 |
|
I'd use a loop
|
# ? Dec 16, 2010 00:19 |
|
osama bin diesel posted:I'd use a loop Can you be more specific? A for loop or a while loop?
|
# ? Dec 16, 2010 00:27 |
|
epswing posted:A for loop or a while loop?
|
# ? Dec 16, 2010 00:45 |
|
|
# ? May 9, 2024 14:37 |
|
I'll bet he's going to need a variable as well. Maybe even two.
|
# ? Dec 16, 2010 00:48 |