|
MEAT TREAT posted:This is the correct way to do it, you don't want random people on the internet to have direct access to your database. Yeah, I figured as much. I'm new to Java anyway, and so far have had to learn HTTP pushes and JDBC connections. I guess I'll need to learn about opening socket connections and such?
|
# ? Sep 17, 2008 16:05 |
|
|
# ? Apr 27, 2024 15:57 |
|
Flamadiddle posted:Yeah, I figured as much. I'm new to Java anyway, and so far have had to learn HTTP pushes and JDBC connections. I guess I'll need to learn about opening socket connections and such? This is pretty much exactly what web services are meant to do. Secure, abstracted, simple (for various values of simple).
|
# ? Sep 17, 2008 17:02 |
|
TRex EaterofCars posted:This is pretty much exactly what web services are meant to do. Secure, abstracted, simple (for various values of simple). If it's some practice toy app for fun running on a local network, there's nothing wrong with just opening a socket to the server and passing serialized objects for messages.
|
# ? Sep 17, 2008 18:35 |
|
1337JiveTurkey posted:If it's some practice toy app for fun running on a local network, there's nothing wrong with just opening a socket to the server and passing serialized objects for messages. I agree. Maybe I misunderstood but he used the word "staff" so I figured this would be production.
|
# ? Sep 17, 2008 18:57 |
|
Yeah, it's actually for work (a university). It's a system we're planning on opening up to staff so they can text their students in the event that they can't make a lecture or tutorial, so they need to be able to access it from home. I'm thinking I'll build a server side application that does all the populating of data from the database before sending the message. My applet will just be a GUI for people to enter the message and that'll just get passed to the server. There's authentication and stuff on a couple of levels (within the DB and with the SMS provider) but you obviously need to pass a username/password to the database, so it's probably better that that all sits on the server side application, rather than floating around in some public .jar file. Thanks for the advice.
|
# ? Sep 17, 2008 19:36 |
|
Flamadiddle posted:My applet will just be a GUI for people to enter the message and that'll just get passed to the server. Honestly a simple html form is all you need. No need to even make an applet.
|
# ? Sep 17, 2008 22:11 |
|
MEAT TREAT posted:Honestly a simple html form is all you need. No need to even make an applet. My HTML isn't up to my Java, which isn't up to much. How would you even get an HTML form to submit to the server-side application? With an HTTP Get or something?
|
# ? Sep 17, 2008 22:58 |
|
I'm doing the 'create a payroll program' assignment and having some trouble with the 'double' lines. Here's what I've got so far: code:
|
# ? Sep 18, 2008 00:22 |
|
If you look at the String API, you'll see that there is no such method as doubleValue(). What you need to do is use the Double class to parse your strings like so.code:
|
# ? Sep 18, 2008 01:07 |
|
MEAT TREAT got to the bit about parsing doubles before I could, so I'm going to go off on a total tangent, because you seem to be confused about variables. Clearing that up won't fix your problem, but it's important if you're going to do anything.icehewk posted:
In Java, a variable of object type (i.e. a variable that's not of type int, char, boolean, double, etc. --- note that these are all lower case) holds a reference to an object. If you've got two different variables, that means you've got two different references, but there's nothing saying that the references can't be to the same object. So suppose you type in "48.5" on this line; in.readLine() will return a String object with data "48.5", and then we assign a reference to that object to the variable 'input', so that memory looks like this: code:
code:
code:
code:
code:
|
# ? Sep 18, 2008 01:13 |
|
I'm having quite a bit of trouble, could you hit me up on AIM? icehewk
|
# ? Sep 18, 2008 02:30 |
|
Flamadiddle posted:My HTML isn't up to my Java, which isn't up to much. How would you even get an HTML form to submit to the server-side application? With an HTTP Get or something? What kind of webserver are you running? Honestly it sounds like java is over kill if all you need is a interface to get data into the database. I would consider just a PHP or a CGI page in perl or something to handle it. Should be able to find a tutorial online for either of those very easily. To use a HTML you will need a Java application server (Tomcat/Jetty/GlassFish etc) as far as I know. From there it would be easier to write a JSP page. There are other ways of course, HttpServletRequest allows you to read GET data via getParameter(String). It's not a bad idea to set up an app server if you plan to write some more web apps but a little overkill for this project. If you run Apache then setting it up to forward the correct stuff to Tomcat isn't that hard, with IIS it is a little more difficult but doable. Again, I don't think Java is the correct tool for the job here. PHP or a CGI script can open up the database handle you need and keep everything on the server side.
|
# ? Sep 18, 2008 03:38 |
|
dvinnen posted:What kind of webserver are you running? Honestly it sounds like java is over kill if all you need is a interface to get data into the database. I would consider just a PHP or a CGI page in perl or something to handle it. Should be able to find a tutorial online for either of those very easily. Thanks for that. We're discussing the merits of all the options at the moment. I'll have a word with our Perl guy and see what he thinks about building the page. I think we're on IIS but I'd have to check.
|
# ? Sep 18, 2008 08:46 |
|
I'm still getting a 'few' errors. I think I'm missing something from the beginningcode:
code:
|
# ? Sep 19, 2008 03:28 |
|
icehewk posted:I'm still getting a 'few' errors. I think I'm missing something from the beginning drat dude, I usually like helping people do their homework but you got some serious issues. Lets start with the obvious stuff. code:
With the current iteration why did you remove the BufferedReader? You need that to read the input. What is 'Input' suppose to be? You never declared it, nor did you declare 'input'. Java is case sensitive so it sees those as different variables. From the code last night do this. code:
Later on I notice you are using the variable 'Hours' instead of 'hours'. The variable 'Rate' is also not declared (guess it should be 'payrate'). Next issue are this line: code:
The above should get it close to compiling I would guess. It is obvious you are new to programming here (CS101?) but you need some help. Does you your school offer CompSci tutoring? If not go spend a few hours in the professors office.
|
# ? Sep 19, 2008 05:14 |
|
It does offer tutoring, when the tutor remembers to show up. Thanks for your help and patience. I'll definitely get the basics down before I post again. edit: I got it running perfectly thanks to your suggestions and a little error googling. Thanks! icehewk fucked around with this message at 07:19 on Sep 19, 2008 |
# ? Sep 19, 2008 06:21 |
|
edit: I figured it out. Hey guys, I've got an issue that you might be able to help me with. I'm making a swing-based UI with one JTree and one JList. When an item is selected on the JTree, it updates the JList with a string array based on the value of the item selected in the JTree. The items in the JList represent test results, and the items in the JTree represent dates on which tests are run. Each date has children for both the test cases run that that day and the failures reported. If the user clicks on the test cases node, the tests cases run that day are shown in the JList, and if they click on the failures node, the failures recieved that day are displayed in the JList. Now heres where I'm running into my problem. I want to display colors on the rows in the JList when Test Cases are selected. If a test case passed, I want it to be green, and if it failed, red. I'm using a custom JUnit class called ZebraJList, which displays rows with alternating background colors. I added in a line in the class' ListCellRenderer to adjust the foreground color based on a variable I set from another class. However, my app seems to add all of the data to the JList, and then call the renderer for each row in that JList, rather than adding a row and immediately calling the renderer for it. This means that the entire list is rendered with the last foreground color that was specified, rather than being rendered with the two different colors in different areas. Hopefully this still makes sense! Here is the code for the cell renderer, followed by my MouseListener code (Which picks up selections in the JTree and updates the JList) code:
code:
Thanks in advance! Blackout fucked around with this message at 20:05 on Sep 19, 2008 |
# ? Sep 19, 2008 17:06 |
|
Nevermind, I figured it out.
|
# ? Sep 19, 2008 20:04 |
|
Blackout posted:Basically my question is how do I get the cell renderer to render each row as it is created, rather than after the entire array of data has been added to the list? You don't. Swing UIs aren't just drawn once to some sort of static image; they're redrawn repeatedly in response to all sorts of possible user events. At any point in time, you have to be prepared to re-render all or part of the list. As such, you can't rely on precise order of execution like that. The way JList is designed is that the UI invokes the ListCellRenderer to get a drawing component for each row, passing in whatever arbitrary object was added to the list (which doesn't have to be a string). Generally this is the same component over and over, and the renderer just sets properties on it specific to that row. Since it looks like you're already adding useful objects (i.e. the actual test-case objects) to the list, I would suggest just modifying your ListCellRenderer to 1) check whether the passed-in object is a test case and, if so, 2) change the background color on the rendering component according to whether the test case failed or not.
|
# ? Sep 19, 2008 20:08 |
|
Is there some sort of smart method when I've extracted an array of bytes from a file, to convert them to long, short, or chars in Java?
|
# ? Sep 19, 2008 21:43 |
|
Boz0r posted:Is there some sort of smart method when I've extracted an array of bytes from a file, to convert them to long, short, or chars in Java? What sort of conversion do you have in mind? If you mean "read these bytes according to host-specific encoding conventions", take a look at java.nio.ByteBuffer.
|
# ? Sep 19, 2008 21:50 |
|
rjmccall posted:What sort of conversion do you have in mind? If you mean "read these bytes according to host-specific encoding conventions", take a look at java.nio.ByteBuffer. I'm not too hot on programming yet, but doesn't abstract mean the function hasn't been defined? Otherwise, that class does everything I looked for.
|
# ? Sep 19, 2008 21:53 |
|
Boz0r posted:I'm not too hot on programming yet, but doesn't abstract mean the function hasn't been defined? It means that the class doesn't define the methods, yes, and cannot be directly instantiated. In the case of ByteBuffer, that's because there are several interesting implementation-specific subclasses. There are static methods on ByteBuffer (allocate(int), allocateDirect(int), wrap(byte[]), and wrap(byte[],int,int)) which are useful for creating various different kinds of buffer; if you've already got a byte array, you should probably just use wrap.
|
# ? Sep 19, 2008 22:02 |
|
rjmccall posted:It means that the class doesn't define the methods, yes, and cannot be directly instantiated. In the case of ByteBuffer, that's because there are several interesting implementation-specific subclasses. There are static methods on ByteBuffer (allocate(int), allocateDirect(int), wrap(byte[]), and wrap(byte[],int,int)) which are useful for creating various different kinds of buffer; if you've already got a byte array, you should probably just use wrap. Ok, but when I've used wrap and gotten a ByteBuffer with the bytes in it, how do I get it out in the different types, as I still can't use the getLong(), getShort()... methods?
|
# ? Sep 21, 2008 13:38 |
|
Boz0r posted:Ok, but when I've used wrap and gotten a ByteBuffer with the bytes in it, how do I get it out in the different types, as I still can't use the getLong(), getShort()... methods? wrap and allocate appear to actually return an instance of HeapByteBuffer, which presumably implements those abstract methods.
|
# ? Sep 21, 2008 15:30 |
|
triplekungfu posted:wrap and allocate appear to actually return an instance of HeapByteBuffer, which presumably implements those abstract methods. I can't seem to find this HeapByteBuffer anywhere in the API, though.
|
# ? Sep 21, 2008 16:36 |
|
What kind of file are you reading from? Edit: realized I didn't read carefully enough. lamentable dustman fucked around with this message at 18:52 on Sep 21, 2008 |
# ? Sep 21, 2008 18:32 |
|
Boz0r posted:Ok, but when I've used wrap and gotten a ByteBuffer with the bytes in it, how do I get it out in the different types, as I still can't use the getLong(), getShort()... methods? What do you mean, you can't use the getLong, getShort, etc. methods? Any object returned by wrap or allocate will have those methods defined, even if what it's returning is an instance of the abstract base class. You're not supposed to need to know the precise implementation, HeapByteBuffer or whatever.
|
# ? Sep 21, 2008 18:36 |
|
For a small project at school we're supposed to round a number to the nearest 5 using Math.ceil(). As far as I can tell ceil just round up to the nearest integer. How can I make it so that it rounds to the nearest 5?
|
# ? Sep 21, 2008 21:14 |
|
Capc posted:For a small project at school we're supposed to round a number to the nearest 5 using Math.ceil().
|
# ? Sep 21, 2008 21:20 |
|
BELL END posted:Divide by 5, call Math.ceil() on that to get an integer, then multiply the result by 5 - this would round up to the nearest 5 (if that was what you meant). If you want to get to the nearest 5 you'd have to use Math.round() instead of Math.ceil(). Yes, thank you. That's exactly what I needed.
|
# ? Sep 21, 2008 22:08 |
|
If you need to do a round rather then just round up all you have to do is the following. 1) Divide by 5 2) Subtract .5 (cast to double for all this of course) 3) Call the ceiling function. 4) Multiply that by 5. ex) 24/5 = 4.8 - .5 = ceiling(4.3) = 5 * 5 = 25 ex) 22/5 = 4.4 - .5 = ceiling(3.9) = 4 * 5 = 20
|
# ? Sep 21, 2008 22:28 |
|
It was just to round up to the nearest nickel when giving change. I ended up doing it like this: (Math.ceil((change*100)/5)*5.0)/100.0 Is this the best, or even right, way to be doing this? It seems overly complicated, but it does work.
|
# ? Sep 22, 2008 00:15 |
|
Capc posted:(Math.ceil((change*100)/5)*5.0)/100.0 That looks okay to me. I usually advise people to avoid floating-point representations for fixed-point values like currency, but given that this is an intro-programming assignment, it's probably not worth the effort. If you get weird one-off errors, though, that's where it's coming from.
|
# ? Sep 22, 2008 01:55 |
|
Is there an easy way to insert the contents of an array into another array? I have two arrays: int[] mapSignature = new int[4]; int[] mapVersion = new int[2]; Which I want to be the first 6 entries in a new array: int[] header = new int[22]; is there any way around making for loops to insert them?
|
# ? Sep 22, 2008 17:30 |
|
Boz0r posted:is there any way around making for loops to insert them? There is System.arraycopy.
|
# ? Sep 22, 2008 17:55 |
|
Alan Greenspan posted:There is System.arraycopy. You, sir, are of high moral fiber. Is it possible to assign the same value to two different destinations at the same time, like: i=j=4; or something? Boz0r fucked around with this message at 23:15 on Sep 22, 2008 |
# ? Sep 22, 2008 19:31 |
|
Boz0r posted:You, sir, are win. Really? quote:Is it possible to assign the same value to two different destinations at the same time, like: Try it and see if a compiler error results. Should work just fine
|
# ? Sep 22, 2008 19:39 |
|
csammis posted:Really? Well, he knows more Java than me, so by that definition, most people in this thread are high moral fiber. csammis posted:Try it and see if a compiler error results. Should work just fine Hey, what do you know, it works. Boz0r fucked around with this message at 23:16 on Sep 22, 2008 |
# ? Sep 22, 2008 19:57 |
|
|
# ? Apr 27, 2024 15:57 |
|
Boz0r posted:Well, he knows more Java than me, so by that definition, most people in this thread are win. What I meant was, didn't calling something "win" used to be probatable?
|
# ? Sep 22, 2008 20:49 |