7,116 Posted Topics
Re: Add an ActionListener to the combo box. That will be called whenever the user selects a new Widget. In there you can update the price and total. Same thing for the Quantity spinner. http://docs.oracle.com/javase/tutorial/uiswing/components/combobox.html#listeners | |
Re: Do you mean something like JUnit, where you define test cases and it runs them and checks that the results are correct? | |
Re: Step 1: Try to arrange your code so that there are the smallest number of classes and methods that the client needs to call on the server. You may want to create a new class that just acts as a "wrapper" for the server classes/methods so that everything the client … | |
Re: I use Eclipse, mainly because it was the obvious next step from Borland JBuilder which I was using when that expired many years ago. However, since then I have been constrained because IBM (the largest employer of Java developers in this part of the world) prefers SWT over Swing, so … | |
Re: Because the if/else/print"no" is inside the while loop it will be executed once for each line in the file. Your logic should check for the password being in the file, then display the frame or the error afterwards. Something like this (pseudo-code) boolean passwordFound = false read each line of … | |
Re: (to clarify Majestic's post: == works exactly as the language definition says it should, including for Strings. It tests for two references being equal, ie referring to exacty the same object. However, it doesn't do what beginners sometimes think it does, ie test for two Strings containing the same sequence … | |
Re: When you created the instances of Node that currentNode refers to, what did you have in the <> How is curentNode defined? | |
Re: star88 Where do we start? Your post is just a pile of low-quality code with no explanation I have no idea why you posted it You seem unaware that this is the Java forum and that's not Java code Any comments before I delete it? | |
Re: There are lots of people here who will freely give their time to help you become the best Java programmer you can be. There's nobody here who is interested in helping you cheat or doing your homework for you. DaniWeb Member Rules include: "Do provide evidence of having done some … | |
Re: The Java classes like Integer, Boolean etc are good examples or wrapper classes, but they are not the only ones. This discussion says it all... http://stackoverflow.com/questions/889160/what-is-a-wrapper-class | |
Re: That's just how postfix works. O n line 4 the value of x-- (10) is passed to the met method, then the value of x is decremented. In the method met, the value of the expression x-- (also 10) is evaluated. The parameter x is them decremented, but this is … | |
Re: So your sound is in a byte array? In that case you can simply write that to the socket via an ObjectOutputStream. At the receiver you just read it via an ObjectInputStream and now the receiver has a copy of the sender's array. You already have code to do that, … | |
Re: st is a copy of s1, which is a ref to a Sample1. You then try to cast that so Sample2, which is invalid. The relevant rule is that you can cast a subclass to it superclass, but not vice-versa. This is because every Sample2 is, by definition a Sample1, … | |
Re: OK, you have code to show a letter grade. What *exactly* is wrong with the results it gives you? Maybe you are getting multiple letter grades? Eg if the grade is 80 then it will pass the if tests on lines 43, 46, 49, 52 and 55. Have a look … | |
Re: Use it to replace the code that's already in main to print the parallelogram. How much of this program did you write, and how much did you copy without really understanding it? Your code looks like typical Java learner code, but the code in main for the parallelogram looks like … | |
Re: Java is not the same as JavaScript. You have posted in the wrong forum. | |
Re: Yes. @niravn: the code on that site is a terrible example of how to code Java in 2012. Post deleted. Remember ou are required to comply with DaniWeb member rules, including "Do ensure that all posts contain relevant content and substance and are not simply vehicles for external links". Any … | |
Re: By using Eclipse you are adding layers of complexity to your task. I can't immediately see anything wrong with you code, so its probably something to do with your usage of Eclipse, eg the run configuration. At your stage of learning you would be best advised to stick to a … | |
Re: When you send a file it goes in two stages 1. You read the file into an array, one block at a time 2. You write those blocks to the socket ... similarly at the receive end. If you don't have a file then the data will be in some … | |
Re: You're close. All you need to do is to add the new field to the existing visible JFrame - not a button, not a new frame, just the existing one. Depending on what layout manager you are using you may also need to call pack() afterwards to let the layout … | |
Re: You could try JNI. Here's a decent-looking tutorial: http://www.codeproject.com/Articles/2876/JNI-Basics-1 | |
Re: In Java "this" is always the current object - the one whose context the current method is executing in. The Thread constructor takes an instance of Runnable as its parameter, so "this" must be an object whose class implements the Runnable interface (which consists of a single run method). When … | |
Re: Integer values won't fit in a byte. Perhaps you could show a small example of what Integer values you expect, and how they should look after being converted? | |
Re: Look at the line of your code where the NPE was thrown. Print the values of the variables at that line to see which is null. Backtrack with more prints until you find out why it's null. ps: `if (e.equals(button1))` e is an ActionEvent, button1 is JButton. They can never … | |
Re: Maybe you have a class of your own called Date that is in the same directory as this code? | |
Re: It's a floating point binary number, and cannot exactly store the decimal value. This is true of all floating point binary - any hardware, any language. To format your output with (eg) rounding to 2 decimal places see these tutorials: http://docs.oracle.com/javase/tutorial/java/data/numberformat.html http://docs.oracle.com/javase/tutorial/i18n/format/numberFormat.html | |
Re: The recursive call on line 84 is ringing an alarm bell, but the variables names are so totally useless (what's m supposed to be?) that I can't tell any more than that. | |
Re: getBytes will extract the text bytes from the string - it doesn't know or care about hex. It will give you {'1', '0', 'B' ... Then you convert each of those and you get 32 integer values each in the range 0-15. To decode that as 16 integer values each … | |
Re: Please check the Daniweb member rules before posting DaniWeb Member Rules include: "Do provide evidence of having done some work yourself if posting questions from school or work assignments" http://www.daniweb.com/community/rules | |
Re: You have that error message because you out an executable statement that's not in a method. Executable statements need to be in a method or constructor. That could be main, or any other method that gets called directly or indirectly from main (including constructors). (Ps: for the experts out there, … | |
Re: If you post your code we can help you fix/improve it. | |
Re: You seem to be getting some reasonable code written there, so what's your question? | |
Re: Please check the Daniweb member rules before posting DaniWeb Member Rules include: "Do provide evidence of having done some work yourself if posting questions from school or work assignments" http://www.daniweb.com/community/rules | |
Re: Once you have your socket connection you can send the file over it by simply reading it in sensible sized blocks and writing them in a single stream of bytes to a DataOutputStream via the socket. This is the standard code for doing that kind of thing, which you will … | |
Re: You could try creating the input stream before you write anythung to the output stream - maybe there was a response but you missed it before you opened the input stream? Anyway, add print statements at key points in that code so you can see exactly where it is hanging … | |
Re: That seems a reasonable start. I would now expect to see quite a lot more detail about how you find the plants that meet the criteria - probably some kind of loop with an if test??? Ps proper indentation makes this much easoer to read, and helps you spot errors. | |
Re: http://docs.oracle.com/javase/tutorial/uiswing/misc/jlayer.html | |
Re: > It is not working. Do nothing. Put some print statements into your code, starting at the first line of main so you can see what code is being executed, for how many times, and what isn't. ps: I agree with stultuske - classes like that is how you would … | |
Re: You're not ready to start any coding yet because you don't know what the code is supposed to do! I suggest you get a paper and pencil and try drawing a calendar or two - with real dates. That way you will learn what's needed in your program. | |
Re: DaniWeb Member Rules include: "Do provide evidence of having done some work yourself if posting questions from school or work assignments" http://www.daniweb.com/community/rules | |
Re: line 34 you initialise aspStr as null, but then on line 37 you try to append text to it. You can't append anything to a null. Initialise it to an empty String ie "" instead. | |
Re: > Actually I got it running by removing... Very unlikely! If you remove `public static void main(String[] args)` your program won't run at all. `for(counter%10==0){...` will ignore the counter variable and loop forever, just executing sleep after sleep. Since this is the last thing in the program it will just … | |
Re: Please post your code here, using the "code" button in the post editor so we can all read it. | |
Re: Lines 57,58 You only need one Name object becuase that contains both first and last name fields You may also consider some constructors that allow fields to be set, eg `public Name(String first, String last) { ...` because that's simpler to use than creating an empty name then setting both … | |
Re: > the String class is automatically copied if you use get() from the ArrayList Have you any reference or demo for this? I would be very surprised if get did anything other than just return a ref to the original object. | |
Re: Why synchronised? Why interrupt the server - that means it won't be listening when you start the client. Just start the server then start the client in two different threads and let them both run. | |
Re: I ran the code and it displays the numbers 1-12 in a circle, like a clock. *Except*: the circle is distorted - more like a pear lying on its side, and the numbers are rotated so 12 is upside-down. So it's safe to conclude that the code basically works, but … | |
Re: You can get the contents of any cell in the table, so you just need a loop that accesses every row in one column. When the data is changed you can add a listener to the table that will be called so you can recalculate the sum. Study the API … | |
Re: > If it's a double then it will ALWAYS have a numeric value. Unless, of course its value is NaN (Java Language Spec. 4.2.3) ;) | |
Re: 1. How much memory does each calculation need (how many of what kind of objects)? 2. Do you need to keep all the objects for each calculation? 3. Is it possible to run a smaller version of the calculation so you can tell whether it is a bug or a … |
The End.