|
PierreTheMime posted:I have a Swingworker to go fetch records and hunt through them to search for a given pattern. This works great, but on larger groups of records I wanted to add a JProgressBar to give the user an idea of how much longer it would be. I'm having trouble understanding how to properly implement the Process() method, though. I looked up some examples and attempted to use it as-is, but where theirs worked mine only publishes after the entire search is completed, so it will sit at 0% and then jump to 100%. The kicker being I can do a stdout of the increment values and that works in real-time just fine. I may be chasing down the wrong thing, but how are you setting up your progress bar? Are the values of i starting at 0 and going to 100? Or are they some other range?
|
# ? Nov 9, 2016 19:30 |
|
|
# ? Jun 13, 2024 05:49 |
|
carry on then posted:I may be chasing down the wrong thing, but how are you setting up your progress bar? Are the values of i starting at 0 and going to 100? Or are they some other range? For the time being it's just sitting in my main GUI layout, counting up from 0 to however many records it's searching through (jpb.setMaximum(jobsListing.size())). The thread publishes the final value (the maximum size of the records found) to the JProgressBar just fine, but all values in between are being ignored for some reason.
|
# ? Nov 9, 2016 19:53 |
|
carry on then posted:Absolutely not in my experience. Well, "modifying a stream as it's copied from source to destination" is exactly the wheelhouse of `sed`. Maybe your coworkers just suck at their jobs? I guess reinventing the wheel in a programming language that is wildly inappropriate for the task is nothing new though.
|
# ? Nov 9, 2016 20:11 |
|
KildarX posted:Welp last question of the year; Two approaches. Create an object that holds the two arrays, pass that in, and use it for the return type. Or return void, accept two arrays, and modify them in place as they are. Volguus posted:And then you will have student A with grade 2.5 even though the grade he got was 9.5. Great job. Would have loved to have you create the grading programs for the schools I've been to, since my name starts with an Z, I would have been top of the class all the time . Only if you implement it wrong? This is totally off dude. You can do it in-place if you want to. You just have to operate on both arrays at the same time. Its really not hard.
|
# ? Nov 9, 2016 21:04 |
|
PierreTheMime posted:I have a Swingworker to go fetch records and hunt through them to search for a given pattern. This works great, but on larger groups of records I wanted to add a JProgressBar to give the user an idea of how much longer it would be. I'm having trouble understanding how to properly implement the Process() method, though. I looked up some examples and attempted to use it as-is, but where theirs worked mine only publishes after the entire search is completed, so it will sit at 0% and then jump to 100%. The kicker being I can do a stdout of the increment values and that works in real-time just fine. I haven't worked with SwingWorker but looking at the javadoc do you need to call setProgress() ? publish() calls are queued up, so if you call publish() 5 times you may only get a single call to process() which contains all 5 results. You can't depend upon publish() to do your progress updates. You need setProgress().
|
# ? Nov 9, 2016 21:10 |
|
Thanks everyone. I was sleep deprived doing that, and the reason I wasn't getting it to sort was because I didn't order a printarray thing I made so it would out put both arrays nicely, put both arrays out nicely again,and then sort. and leave me confused that it wasn't sorting. So... don't code when your under a ton of stress and lack of sleep?
|
# ? Nov 9, 2016 21:53 |
|
Paul MaudDib posted:Well, "modifying a stream as it's copied from source to destination" is exactly the wheelhouse of `sed`. Maybe your coworkers just suck at their jobs? Please point me to the location where sed resides by default on a standard Windows Server installation Please point me to the data set where sed resides on a standard zOS installation Please point me to how I should be using sed in a platform independent way that does not include shipping a third party binary with the product, which requires legal approval. Not everyone writing Java is doing so for one-off tasks on their local system.
|
# ? Nov 9, 2016 22:24 |
|
Anyone in here ever tried Apache ISIS? Looks like a really convenient way to get a working application out the door, but the huge amount of code generation sounds potentially risky.
|
# ? Nov 9, 2016 22:51 |
|
carry on then posted:Please point me to the location where sed resides by default on a standard Windows Server installation quote:Please point me to the data set where sed resides on a standard zOS installation I mean I'm really surprised if it doesn't come standard with any Unix-like operating system and/or built into shell. Not that I use it personally, perl -pe usually does the trick for me
|
# ? Nov 9, 2016 23:41 |
|
rt4 posted:Anyone in here ever tried Apache ISIS? Looks like a really convenient way to get a working application out the door, but the huge amount of code generation sounds potentially risky. Usually they use a Blackhawk on ISIS, not the Apache.
|
# ? Nov 10, 2016 01:39 |
|
Zaphod42 posted:I haven't worked with SwingWorker but looking at the javadoc do you need to call setProgress() ? I modified it to essentially match the example straight out of the Javadoc and I'm not having updates. Basically here's what I have (just the snippets that are related/updated)... GUI class: code:
FindJobsByScript class: code:
I'm getting the proper output with a test stdout, but it's still just updating at the completion. PierreTheMime fucked around with this message at 18:06 on Nov 10, 2016 |
# ? Nov 10, 2016 17:41 |
|
I don't think you should be doing that setMaximum call on the progress bar from within doInBackground, that runs on a worker thread and you might get concurrency issues? e- why are you setting it to the size of jobsListing anyway? Aren't you covering your progress value to 0-100 by hand? If you have a lot of jobs that might make your progress look very small baka kaba fucked around with this message at 18:05 on Nov 10, 2016 |
# ? Nov 10, 2016 18:01 |
|
As far as I can see there is nothing wrong with the SwingWorker. It really should work. Something else must be the culprit. However, I did notice that you have "jpb.setMaximum(jobsListing.size());" in the doInBackground method. Don't. That method gets executed in a different thread than the UI thread, and it should not update Swing components. You are telling the progress bar that it goes from 0 to 100 when you create it. Just calculate the progress properly and you don't need to change the max size. But , other than that, which shouldn't really have an effect on how it work, I can't see anything wrong with the code.
|
# ? Nov 10, 2016 18:04 |
|
baka kaba posted:I don't think you should be doing that setMaximum call on the progress bar from within doInBackground, that runs on a worker thread and you might get concurrency issues? Sorry that was already removed. I accidentally copied it from my old post, but it's gone. Edited.
|
# ? Nov 10, 2016 18:04 |
|
PierreTheMime posted:Sorry that was already removed. I accidentally copied it from my old post, but it's gone. Edited. Is it gone or are you doing it somewhere else? I edited because I noticed you're also converting your progress range to 0-100, you need to pick one Honestly I think you need to post your whole task class, the threading stuff means certain things have to go in certain methods or you'll get inconsistent behaviour, so it could be something sneaky like that
|
# ? Nov 10, 2016 18:09 |
|
baka kaba posted:Is it gone or are you doing it somewhere else? I edited because I noticed you're also converting your progress range to 0-100, you need to pick one I'll post it when I get back. Edit: How's the Swingworker class in its entirety: code:
PierreTheMime fucked around with this message at 19:17 on Nov 10, 2016 |
# ? Nov 10, 2016 18:11 |
|
baquerd posted:Usually they use a Blackhawk on ISIS, not the Apache. Thank you. I couldn't think of a good pun for this.
|
# ? Nov 11, 2016 00:27 |
|
e: Ignore. Want to re-formulate my question.
venutolo fucked around with this message at 21:43 on Nov 14, 2016 |
# ? Nov 14, 2016 21:40 |
|
Coming from zero experience, what would be a good web service interface for basic Java interaction on a website? I set up a generic Tomcat install and tried out a dynamic web service build right out of Eclipse, but I'm mostly just playing around to understand the concepts. What's a decent approach for a "RESTful" interface? I basically just need a site that can query a database based on limited user input and return formatted text. My code works fine as a stand-alone, but I'm being told implementing it as an internal website is the way they want it presented.
|
# ? Nov 15, 2016 01:15 |
|
PierreTheMime posted:Coming from zero experience, what would be a good web service interface for basic Java interaction on a website? I set up a generic Tomcat install and tried out a dynamic web service build right out of Eclipse, but I'm mostly just playing around to understand the concepts. What's a decent approach for a "RESTful" interface? Some may say Spring, but I think Jersey is a hell of a lot easier to setup and get running - especially if you're using Maven. Jersey's documentation uses Grizzly container (I've never used it), but it's fully compatible with Tomcat and requires some modifications to your web.xml like setting your root API "directory". I use Jersey for my personal products and we run our REST interface with it at my job. You should be able to get up and running without too much complication if you follow this: https://jersey.java.net/documentation/latest/getting-started.html Then for the front end, you can use whatever JS framework (or just straight JS) to read the resultant JSON. You can also send back XML, Text, HTML as well from your Resources / Controllers.
|
# ? Nov 15, 2016 02:40 |
|
geeves posted:Some may say Spring, but I think Jersey is a hell of a lot easier to setup and get running - especially if you're using Maven. Jersey's documentation uses Grizzly container (I've never used it), but it's fully compatible with Tomcat and requires some modifications to your web.xml like setting your root API "directory". I use Jersey for my personal products and we run our REST interface with it at my job. Echoing all this. You don't do the web with java, you do the web with HTML/JS and then you AJAX call to REST when you need to perform operations. And Jersey is my favorite implementation of a REST server on Java as well. Spring is good but its a huuuuge framework, so its more messy to get started. Jersey is also the reference implementation of JAX-RS, so you can use pretty much the same code with other JAX-RS implementations with little to no modifications, if you end up having some issue with Jersey. Its also well supported. I haven't used it with Grizzly, I had it running in JBoss. If you wanna use Java to actually generate the pages then you're looking for something like Thymeleaf, but you're going to end up using Javascript for any interactive elements regardless.
|
# ? Nov 15, 2016 03:06 |
|
Go ahead and start with dropwizard, which packages Jersey with a bunch of other libraries (json, logging, metrics, an http server) that you'll end up using anyways.
|
# ? Nov 15, 2016 03:21 |
|
Zaphod42 posted:.... Spring is good but its a huuuuge framework, so its more messy to get started. .... That was true 10 years ago. 5 years ago even it ceased to be correct. 2 years ago Spring Boot came into existence, which made what was trivial before even easier: code:
But, like other have said, there are a lot of frameworks to choose from. Today you have (besides Spring boot) dropwizard, Spark (http://sparkjava.com/) and even JHipster which claims that it will generate crap for you : https://jhipster.github.io/ Give them a try or ... just pick one and make your mind up.
|
# ? Nov 15, 2016 04:45 |
Got a very simple homework assignment, but I can't for the life of me figure out why an exception keeps getting thrown. It's a Java EE project, I'm accessing the DB through a data source / connection pool. I'm just trying to add a row to the order table, but when it comes to executing the query, an SQL exception is thrown. code:
code:
It's a MySQL database if that matters. denzelcurrypower fucked around with this message at 06:32 on Nov 15, 2016 |
|
# ? Nov 15, 2016 06:22 |
|
I think that's just the error message cutting off at the toppings value - you probably want to look at where the error starts, which is the 'order' part. Is your query syntax correct? Does it look like other examples?
|
# ? Nov 15, 2016 06:47 |
baka kaba posted:I think that's just the error message cutting off at the toppings value - you probably want to look at where the error starts, which is the 'order' part. Is your query syntax correct? Does it look like other examples? Yeah... if I paste this into MySQL code:
denzelcurrypower fucked around with this message at 07:05 on Nov 15, 2016 |
|
# ? Nov 15, 2016 06:53 |
|
I'm curious as to why you used backticks when running it directly when it has single quotes in the java string. Did you re-type it by hand instead of copy-pasting?
|
# ? Nov 15, 2016 07:45 |
For some reason it sometimes pastes with that strange version of single quote character but I tried replacing with regular single quote ' and the same errors seem to persist regardless. I've been copy pasting between NetBeans and php my admin so I guess at some point the text encoding is being changed. Don't think it's related to the error though since I've tried replacing any of the strange characters.
|
|
# ? Nov 15, 2016 07:49 |
|
Ornithology posted:For some reason it sometimes pastes with that strange version of single quote character but I tried replacing with regular single quote ' and the same errors seem to persist regardless. The difference between single quotes and backticks is the root cause of your problem. Ignoring it entirely and looking for some other issue is not going to be fruitful.
|
# ? Nov 15, 2016 07:55 |
|
Pretty sure you cant have a table called 'order' in Mysql. Its a keyword (such as order by blah). Edit - I'm seeing conflicting results about this - I know I personally had to change an order table to orders a few weeks ago because of a similar issue though. Try changing it to orders and see if it works? Edit 2 - Also why are you separating your PreparedStatement variable away from its assignment? Put em together inside the try, save a line! FateFree fucked around with this message at 14:11 on Nov 15, 2016 |
# ? Nov 15, 2016 14:05 |
|
You can have a table named `order`, but you have to escape the name using backticks (hence, `order`) since ORDER is a SQL keyword.
|
# ? Nov 15, 2016 18:21 |
|
ExcessBLarg! posted:You can have a table named `order`, but you have to escape the name using backticks (hence, `order`) since ORDER is a SQL keyword. Or, you know, just not cause a massive headache by using a reserved word as a table name.
|
# ? Nov 15, 2016 22:32 |
Sometimes fate just has it in for you. "release" is a keyword now, but it wasn't back when I first designed the system
|
|
# ? Nov 16, 2016 00:33 |
|
Data Graham posted:Sometimes fate just has it in for you. "release" is a keyword now, but it wasn't back when I first designed the system Radium account spotted.
|
# ? Nov 16, 2016 13:45 |
|
geeves posted:Or, you know, just not cause a massive headache by using a reserved word as a table name. Yeah the problem comes from using the keyword, forcing the single quotes, causing syntax errors. Wish you could do escaped literal strings with @ like in C#, would probably make this easy. But I'd change your database schema if at all possible. FateFree posted:Edit 2 - Also why are you separating your PreparedStatement variable away from its assignment? Put em together inside the try, save a line! Saving a line doesn't matter. Who cares. Lines != Instructions. Compilers are smart.
|
# ? Nov 16, 2016 19:13 |
|
Zaphod42 posted:Saving a line doesn't matter. Who cares. Lines != Instructions. Compilers are smart. You don't write code for compilers. You write code for people. Initializing a variable when you declare it prevents a very ugly class of potential bugs. Not now, but probably later when another person will modify the code. If you don't need variable X outside a scope, don't declare it outside the scope.
|
# ? Nov 16, 2016 19:18 |
|
Volguus posted:You don't write code for compilers. You write code for people. Initializing a variable when you declare it prevents a very ugly class of potential bugs. Not now, but probably later when another person will modify the code. If you don't need variable X outside a scope, don't declare it outside the scope. That's my point exactly, you write code for people. Its a very minor thing to nitpick and putting it above the try as a statement of intent isn't really a cardinal sin. You could move it but it really isn't worth correcting someone over.
|
# ? Nov 16, 2016 19:33 |
|
Zaphod42 posted:That's my point exactly, you write code for people. Its a very minor thing to nitpick and putting it above the try as a statement of intent isn't really a cardinal sin. You could move it but it really isn't worth correcting someone over. Its not minor at all, writing code is built upon small decisions like these. Why would you separate something into two lines that can (should) be explained in one? If a person gets in this habit every day of their job, they waste thousands of lines of code, and worse, you waste time and brainpower piecing together something that should be together. It would be like reading a book where someone split sentences in half and finished them down the line. This is the exact sort of thing that separates good coders from bad coders, trying to make things as easy and simple as possible at every opportunity is important and should be taught to people when you have a chance to.
|
# ? Nov 16, 2016 20:57 |
|
FateFree posted:Its not minor at all, writing code is built upon small decisions like these. Why would you separate something into two lines that can (should) be explained in one? If a person gets in this habit every day of their job, they waste thousands of lines of code, and worse, you waste time and brainpower piecing together something that should be together. It would be like reading a book where someone split sentences in half and finished them down the line. This is the exact sort of thing that separates good coders from bad coders, trying to make things as easy and simple as possible at every opportunity is important and should be taught to people when you have a chance to. For me it's out of habit, because we write a lot of complex SQL via StringBuilder, etc. that might have some if / else clauses when adding parameters to the question you're ultimately asking. Suddenly throwing SQL directly into a preparedStatement("SELECT...."); is structurally jarring and I have not seen any company for which I've worked do except in rare or random instances. Even if I'm doing simply "SELECT * FROM foo;" it's its own string since I expect to modify the question at some point in the future. Many programmers I work with Java wasn't their first language and that language may have been one where they would pre-sanitize the string before passing it on to the language's driver. Also Java's own documentation follows this model as well. https://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html geeves fucked around with this message at 21:54 on Nov 16, 2016 |
# ? Nov 16, 2016 21:51 |
|
|
# ? Jun 13, 2024 05:49 |
|
FateFree posted:Its not minor at all, writing code is built upon small decisions like these. Why would you separate something into two lines that can (should) be explained in one? If a person gets in this habit every day of their job, they waste thousands of lines of code, and worse, you waste time and brainpower piecing together something that should be together. It would be like reading a book where someone split sentences in half and finished them down the line. This is the exact sort of thing that separates good coders from bad coders, trying to make things as easy and simple as possible at every opportunity is important and should be taught to people when you have a chance to. Why do you have to continue to talk down to me dismissively like I've never heard of improving code readability? Everything I've posted in this thread suggests I know exactly what you're talking about. Where we disagree is over how big a deal this is to readability; not whether readability matters period. Very arrogant attitude.
|
# ? Nov 16, 2016 22:19 |