|
Are they javax.swing.JComboBox objects? There's a few ways to do it. The most basic would probably be this: 1. Create 3 instances of a DefaultComboBoxModel, one for each JComboBox. assign them with JComboBox.setModel(). Add all the choices to all of them. 2. Create add Action Listeners for each JComboBox. When you change the first combo box, it should update 2 and 3 to remove the choice you selected (removeElement()). When you change the second, it should update the third to remove that choice too. You can get fancier than that, that should get you started. Using an IDE will help guide you along. I ran through it in NetBeans in about 5 minutes.
|
# ? Apr 7, 2008 23:25 |
|
|
# ? May 6, 2024 03:47 |
Is there a way to do this without int count?code:
|
|
# ? Apr 8, 2008 00:50 |
|
fletcher posted:Is there a way to do this without int count? There are lots of ways... code:
code:
epswing fucked around with this message at 21:41 on Apr 8, 2008 |
# ? Apr 8, 2008 02:15 |
|
I'm looking for some info on asynchronous method calls in Java, sorta like the .NET Asynchronous Programming Model. I know you could do it manually by creating a thread and spinning off work (and maybe using a Future<> and an Executor) but that's annoying and cumbersome and in the case of asynchronous I/O, fairly wasteful if you could do it directly to the hardware instead of spinning up a new thread to do it. I'm finding surprisingly little via Google and Sun's site (though maybe I'm just missing something).
|
# ? Apr 8, 2008 03:09 |
edit: nevermind
|
|
# ? Apr 8, 2008 04:37 |
|
epswing posted:There are lots of ways... This makes my brain hurt, or maybe its a coffee deficiency. code:
code:
|
# ? Apr 8, 2008 12:46 |
|
fletcher posted:Is there a way to do this without int count? How's that? epswing & Brain Candy: I was under the impression that the compiler will take care of substituting StringBuilder during string concatenation? http://java.sun.com/developer/technicalArticles/Interviews/community/kabutz_qa.html posted:When Strings are added using the + operator, the compiler in J2SE 5.0 and Java SE 6 will automatically use StringBuilder
|
# ? Apr 8, 2008 14:07 |
|
Brain Candy posted:Just check that length is non-zero instead? triplekungfu posted:epswing & Brain Candy: I was under the impression that the compiler will take care of substituting StringBuilder during string concatenation?
|
# ? Apr 8, 2008 16:05 |
|
epswing posted:Sounds like this will create a new StringBuilder instance per iteration, in which case the extra append calls would be better.
|
# ? Apr 8, 2008 16:22 |
|
JSTL SQL Insert Query - Kinda fixedcode:
Whenever I run it, I get a quote:java.sql.SQLException: General error Any ideas why I can't get it to work? Running on a Tomcat 6.0.10 server. EDIT: don't know how, but the INSERT is running fine now. Don't know what I changed to fix it EDIT 2: Goddamn it, don't know whether it good or not that, after being stuck for an hour or so, I manage to fix my problem with 10 mins of posting. EVERY. TIME. Fixed statement: code:
Kennedy fucked around with this message at 17:00 on Apr 8, 2008 |
# ? Apr 8, 2008 16:41 |
|
TRex EaterofCars posted:Why would the compiler do that? I don't know anything about the java compiler. From my lofty perch, far from such low-level details, it sounds like code:
code:
epswing fucked around with this message at 16:58 on Apr 8, 2008 |
# ? Apr 8, 2008 16:45 |
|
epswing posted:I don't know anything about the java compiler. From my lofty perch, far from such low-level details, it sounds like I just decompiled this code (All code generated using JDK6_u3, should probably upgrade): code:
code:
|
# ? Apr 8, 2008 17:31 |
|
TRex EaterofCars posted:...and it uses .append() with only 1 instance of StringBuilder. That's exactly what I was concerned with: does the following mean 5 instances of StringBuilder? code:
|
# ? Apr 8, 2008 17:38 |
|
epswing posted:That's exactly what I was concerned with: does the following mean 5 instances of StringBuilder?
|
# ? Apr 8, 2008 17:55 |
|
TRex EaterofCars posted:Sure does. Ok, which brings me back to http://forums.somethingawful.com/showthread.php?threadid=2780384&pagenumber=5#post342041228 epswing posted:Sounds like this will create a new StringBuilder instance per iteration, in which case the extra append calls would be better. TRex EaterofCars posted:Why would the compiler do that? Looks like it would. In which case I'm saying that N*3 calls to append might be faster than N new StringBuilder objects.
|
# ? Apr 8, 2008 18:07 |
|
I have a JTable with two columns and I want their widths to be distributed 9:1, i.e. if the whole table is 100px wide, column1 should be 90px and column2 10px. After some searching it looked like these lines could help, but they don't seem to have any effect: jTable1.getColumnModel().getColumn(0).setPreferredWidth(9); jTable1.getColumnModel().getColumn(1).setPreferredWidth(1); What am I doing wrong? Also, it seems like when I restart the program, it will automatically resize the columns to the way they were in the last session. Why does this happen? Could it be the reason why the two lines don't work?
|
# ? Apr 8, 2008 18:45 |
|
Here's how I set my column widths:code:
|
# ? Apr 8, 2008 18:55 |
|
epswing posted:Ok, which brings me back to http://forums.somethingawful.com/showthread.php?threadid=2780384&pagenumber=5#post342041228 Yeah, I misread your post. I actually copied that code straight now and disassembled it and it's definitely creating 2 new StringBuilder instances for every loop. I wonder if HotSpot would be able to optimize this further and move the allocation if it unrolled the loop. This bugged the poo poo out of me so I benchmarked it. You're right, the overhead of allocating those StringBuilders is significant for even modest numbers of iterations. I'll post the code if anyone wants, but for 1000 keys of random size, it took anywhere from 875-1000ms to run the naive method, and from 0-3ms for the explicit append() method. I run under linux so the JVM uses the server VM by default. I tried this under -client and got FAR worse performance for the naive method, even after HotSpot dealt with it.
|
# ? Apr 8, 2008 21:11 |
|
TRex EaterofCars posted:I'll post the code if anyone wants I'd love to see it firsthand.
|
# ? Apr 8, 2008 21:38 |
|
epswing posted:I'd love to see it firsthand. code:
|
# ? Apr 8, 2008 21:59 |
|
epswing posted:Nope, depends on if qry already has content such as "select ...". In the code block you gave, you constructed qry inside the block. So if your while loop executes at least once, the last char of qry will be ','.
|
# ? Apr 9, 2008 00:19 |
|
Is there a "Java way" to accomplish the same thing as bitflags? I know it's possible to do bitflags in Java, but it just doesn't feel right. I'd like the same kind of functionality, but without significantly more complicated syntax. For example, I'd rather avoid making a whole new class containing a half-dozen Booleans, then have to construct this class every time I want to call a function. What I have now is basically: code:
|
# ? Apr 9, 2008 00:45 |
|
ColdPie posted:How "should" I be doing this in Java? Inheritance and/or enums. Its hard to say exactly without any idea of why you want to use bit flags.
|
# ? Apr 9, 2008 01:32 |
|
Brain Candy posted:Inheritance and/or enums. Its hard to say exactly without any idea of why you want to use bit flags. Yeah, please let us know a bit more about your problem. There is almost always a more elegant way of handling that sort of multiplexing.
|
# ? Apr 9, 2008 02:13 |
|
TRex EaterofCars posted:Yeah, please let us know a bit more about your problem. There is almost always a more elegant way of handling that sort of multiplexing. Basically a utility function that compares two strings in different ways based on the bitflags. The code's for work, so I don't have it on me, but the flags are something like COMP_CASE_INSENSITIVE, COMP_BEGINS_WITH, COMP_ENDS_WITH, COMP_CONTAINS and so on. It's a whole lot easier to maintain one function and a couple bitflags than a few dozen functions with various combinations of the above options. The functions signature is essentially static void compare(String expected, String found, int flags).
|
# ? Apr 9, 2008 04:56 |
|
Brain Candy posted:In the code block you gave, you constructed qry inside the block. So if your while loop executes at least once, the last char of qry will be ','. Look at what fletcher gave us initially, there's a qry variable out of nowhere, it could contain anything. I instantiated a StringBuilder in my block because I needed a StringBuilder instead of a String, I clearly needed to indicate this somehow, but that's not necessarily where he/she is instantiating it. (That's what the // ... is for.) (Edit: Yay, first time I use [fixed]!) epswing fucked around with this message at 06:21 on Apr 9, 2008 |
# ? Apr 9, 2008 06:06 |
|
ColdPie posted:Basically a utility function that compares two strings in different ways based on the bitflags. The code's for work, so I don't have it on me, but the flags are something like COMP_CASE_INSENSITIVE, COMP_BEGINS_WITH, COMP_ENDS_WITH, COMP_CONTAINS and so on. It's a whole lot easier to maintain one function and a couple bitflags than a few dozen functions with various combinations of the above options. The functions signature is essentially static void compare(String expected, String found, int flags).
|
# ? Apr 9, 2008 07:25 |
|
I'm writing an applet which plays a card game, but I wrote it misunderstanding how the game works. How it's supposed to work: three cards are drawn, two are put face up, user enters how much money he/she would like to bet that the integer value of the third card is between the two being shown, third card is shown and winnings are added/subtracted accordingly. How I wrote it: user enters how much money they'd like to bet, all 3 cards are drawn at once and uses whatever bet was given before beginning the round. beginRound is the function that compares the cards, determines if the card is in between the first and second card drawn, and accordingly adds/subtracts from the user's total winnings. The user enters into a textfield his/her bet and any button clicked will automatically get the bet for the user, but how do I make it so for begin round, two cards are drawn, and then have the program wait for the user to enter a new bet and click the corresponding button associated with bet before continuing with the rest of the function? I feel like right after the line with curCard3 is where it should wait for the user's bet before continuing, but I can't find any information on how to make the program wait on a non-input dialog basis. The rest of the program works perfectly. Thank you! code:
|
# ? Apr 9, 2008 11:04 |
|
epswing posted:Here's how I set my column widths: Does anybody here have experience with the Apache Commons FTPClient class? When I try to cancel an upload with abort(), the program just freezes and waits for the upload to complete. Afterwards abort() returns true, though.
|
# ? Apr 9, 2008 11:24 |
|
Whilst farting I posted:but I can't find any information on how to make the program wait on a non-input dialog basis. code:
|
# ? Apr 9, 2008 11:37 |
|
Whilst farting I posted:I'm writing an applet which plays a card game... [list=1] [*]Display 2 cards [*]Accept user's bet [*]Final card and winnings calculation [/list] Now, #1 is triggered by "startround", #2 by "bet", and #3 by #2?
|
# ? Apr 9, 2008 13:29 |
|
triplekungfu posted:I may be missing something, but shouldn't the flow go something like this: You're right, I knew something didn't seem right. I solved the problem by dealing the cards in the start round function and moving the actual comparison and calculation functions and display into the bet. The GUI includes 3 buttons: Start a New Game (start from scratch), Start A New Round (deals 3 new cards and displays 2), and Bet (gets the bet from the user, displays the last card, and gives output). So the flow is now identical to what you just posted. This is really rough (error-checking statements to be added, variable names are hosed up, graphic display of cards to add), but it works. Thank you! code:
|
# ? Apr 9, 2008 15:03 |
|
zootm posted:Yeah, you probably want enums, assuming you're using Java 5 or newer. The EnumSet class will let you do the 'bitflag' thing in a typesafe way while also getting the full functionality of the Set interface. It's implemented as bitflags too so you get that time efficiency. Neat, that looks like a good solution. Thanks.
|
# ? Apr 9, 2008 15:24 |
|
ColdPie posted:Basically a utility function that compares two strings in different ways based on the bitflags. The code's for work, so I don't have it on me, but the flags are something like COMP_CASE_INSENSITIVE, COMP_BEGINS_WITH, COMP_ENDS_WITH, COMP_CONTAINS and so on. It's a whole lot easier to maintain one function and a couple bitflags than a few dozen functions with various combinations of the above options. The functions signature is essentially static void compare(String expected, String found, int flags). That sounds like something which might be more efficiently described with java.util.regex.
|
# ? Apr 9, 2008 19:05 |
Thank you to all the replies about my previous question. I've got another one for you guys. I want to find unique values from a collection SomeCollection. Right now I'm just iterating through the collection and throwing every value into a HashMap<String, String> SomeUniqueCollection, where the key and value are both the key from SomeCollection. Should I be using a different type of collection for SomeUniqueCollection since I don't really need a K,V but just a K? Or is there a better way to approach this?
|
|
# ? Apr 9, 2008 22:15 |
|
fletcher posted:Thank you to all the replies about my previous question. I've got another one for you guys. HashSet does exactly what you're looking for.
|
# ? Apr 9, 2008 22:23 |
1337JiveTurkey posted:HashSet does exactly what you're looking for. Right on, thanks!
|
|
# ? Apr 9, 2008 22:26 |
|
Whilst farting I posted:Out of curiousity for the future, though, does anyone know a better way for making a program wait on a non-input dialog basis besides the sleep method BELL END mentioned? The technique BELL END mentioned is called polling, and is usually a bad idea. If you've got an event driven UI (which is the case here), then you don't need to poll; actions are triggered by events. An alternative to this is to use queues, and when attempting to read from a queue the consumer will be blocked until something is available (same goes for the producer putting stuff into the queue if the queue is full). Once a message becomes available in the queue, the consumer will be awoken and handed the message. I used the above a couple of times in Uni assignments, rolling my own queue in Java 4. Java 5 includes BlockingQueue, which probably would have saved me a bit of time. Also, TRex EaterofCars and epswing thanks for the clarification on StringBuilder.
|
# ? Apr 9, 2008 23:53 |
|
Im having a problem with 2d arrays. How can I assign a value to each spot in the array? I dont know if this would further complicate the issue, but the size of the array is based on user input. this is what i have right now. My hope is that this will assign a random boolean to each location within the array. Will this function how I would like it to? quote:boolean[][] lifegame = new boolean[i][h];
|
# ? Apr 10, 2008 22:55 |
|
|
# ? May 6, 2024 03:47 |
|
Drumstick posted:this is what i have right now. My hope is that this will assign a random boolean to each location within the array. Will this function how I would like it to?
|
# ? Apr 10, 2008 22:59 |