7,116 Posted Topics
Re: Because your dates are in a known fixed format, it's easy to use the SimpleDateFormat class to convert the String to a Date, and vice-versa. Java Dates are essentially millisecs since some arbitrary zero point, so you can do arithmetic on them. For more interesting date manipulation convert to a … | |
Re: You can simplify this to two cases as follows: [CODE]NB: keep track of how much space is remaining on the current line at all time split input into array of words print the first word for every remaining word: if it fits print " " + the word else print … | |
Re: Pointers are only useful if you are working with memory locations. Java memory management is completely automatic, there's no context in which you need to manipulate the address of anything. However All Java variables of type Object or array are what Java calls "reference" variables. They contain a reference to … | |
Re: Animation in Swing isn't hard to set up. Use a javax.swing.timer to run a method every (eg) 50mSec. In that method update the sizes/positions etc of your animated objects, and call repaint() for the JPanel (or whatever) that contains your animation to trigger a screen update. Override the paintComponent method … | |
Re: Aviras is right. The OP's code includes setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); so this looks like Swing, in which case it's already double-buffered unless you have explicitly turned off double buffering. It's almost always a mistake to override paint, you should override paintComponent instead. Overriding update(Graphics g) is futile, as update is never called … | |
Re: (Norm: am I going bonkers here? Why no NPE's?) [CODE]TVShow[] myShowArray = new TVShow[TV_MAX]; .. for(d = 0; d < TV_MAX; ++d) .. myShowArray[d].setShowName(tvInput);[/CODE] This shouldn't work. Have you been ignoring null pointer error messages? Line 1 creates an array of TVShow pointers, initially all null Line 3 tries to … | |
Re: That seems like strange advice. Java was designed to be multi-platform, which is great, but the downside is that it doesn't tie strongly into the system of any one environment. You'll find that all kinds of system calls that you would use in C* are not available in Java unless … | |
Re: [CODE]public static void Calculate(int [] Years, double [] Population, int Size, double CurrentPercent, double LargestPercent, int LargeYear1, int LargeYear2)throws IOException { ... CurrentPercent= (((Population[counter+1])/(Population[counter]))-1)*100; ... LargestPercent=CurrentPercent; LargeYear1= Years[counter]; LargeYear2= Years[counter+1]; [/CODE] This code isn't going to work because Java parameters are passed as a copy - ie when you call … | |
Re: To control the loop like that you just need an ordinary local variable within the method (which cannot, by definition, be static). If you need a single value that is shared between all instances of the class and all methods of the class then declare it static, but [I]outside [/I]any … | |
Re: Sorry purijatin but that's not right, although it is a common mistake. All calls in Java are calls by value. There is no such thing as a call by reference in Java. @hackit: I have no idea what kind of problem you have in mind, but all calls in Java … | |
Re: AFAIK there's no sensible way to merge cells. The only work-around is to use a custom cell renderer and work out what to display in each of the individual cells so it looks like they are combined into one. - not easy or elegant, but possible. Setting background color for … | |
Re: Hint: [CODE]if(numstreet == 1)street = "Port Washington Boulevard"; else if(numstreet == 2) street = "Main Street"; etc[/CODE] You should use an array of Strings for this: [CODE]String[] streets = {"Port Washington Boulevard", "Main Street" ... street = streets[numstreet-1]; // first element is number 0[/CODE] Simple way to save the number … | |
Re: ^ yes. int[] a is also documented in the official tutorials [QUOTE]You can also place the square brackets after the array's name: float anArrayOfFloats[]; // this form is discouraged However, convention discourages this form; the brackets identify the array type and should appear with the type designation. [/QUOTE] [url]http://download.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html[/url] ps … | |
Re: 1. By overriding paint(Graphics g) you have taken responsibility for painting the whole applet - including the combo box. Normal solution is to call super.paint(g) as the first line of your paint so everything "normal" gets painted, then go on to draw your shapes. 2. the triangle is offset because … | |
Re: [QUOTE=chiiqui;1642087]you cannot shuffle double numbers[/QUOTE] Would you like to justify that somewhat surprising statement? | |
Re: ... or, since this is 2011, you can use the enhanced for loop from Java 1.5 A common solution to this problem is to make a copy of the original list and iterate thru that while updating the original. [CODE]ArrayList<Mouse> master = ..... ArrayList<Mouse> copy = new ArrayList<Mouse>(master); // copies … | |
Re: You can read/write a RandomAccessFile using your own code to convert your objects to/from bytes of data. You can use Java ObjectOutputStream / ObjectInputStream to write/read simple or complex objects (including arrays & collections) with a single statement. You can use XMLEncoder /XMLDecoder to encode/decode simple or complex objects (including … | |
Re: This is a duplicate of the OP's post [url]http://www.daniweb.com/software-development/java/threads/381276[/url] where it has already been answered. | |
Re: I don't understand your request. Perhaps an example would help? If the text is "1-2year" what EXACTLY would you get when you "extract only numeric data"? | |
Re: Here's a little pseudocode template that shows the general approach. It will loop asking for input and diagnosing exceptions and failed validation tests until good input is received [CODE]boolean inputIsOK = false; while (! inputIsOK) { prompt user try { get input if (input < 0 && input >= size) … | |
Re: [CODE]ResultSet rs=ps.executeQuery(); ps.setString(1,tp);[/CODE] Maybe you would do better with these two lines the other way round? | |
Re: I guess you can call it whatever you like, although you would have a lot more success finding stuff if you used the same words as everyone else. Anyway, Googling [I] java move file [/I] gives this as the first hit: [url]http://www.java-forums.org/new-java/440-how-move-file-another-directory.html[/url] and this as the third [url]http://download.oracle.com/javase/tutorial/essential/io/move.html[/url] the second … | |
Re: Because on line 7 you have a new Thread(...), so there you create a Thread instance, just like you can create a String or any other kind of Object. | |
Re: Have you run your program? In what exact way does its output differ from the output you expect? The calculations for deductions seem to be present and sensible (lines 51-62) | |
Re: One of the joys of Java is that there isn't often a need to do that. Maybe X is found to be insufficient in some way, and needs to be enhanced with a second parameter. Java polymorphism means you can keep the old version, and add the new version alongside … | |
Re: The "null error" (presumably null pointer error) also tells you the exact line number where it happened. Would you like to tell us, or do we have to guess? | |
Re: ArrayLists are serialisable, so if you put all your Shelves into an ArrayList<Shelf> object you can write that to XML as a single object, and read it back with a single read. How simple is that? | |
Re: Is this a Java question? Java chars and Strings are 16 bit Unicode with support for all those langauges and more, but LONGVARCHAR is nothing to do with Java | |
Re: In every one of your catch blocks you need to print the information about the exception - this shows exactly what went wrong and where (line number). By not printing this info you do not know anything except that an exception was thrown. To print the details add the following … | |
Re: [url]http://download.oracle.com/javase/tutorial/deployment/applet/[/url] | |
Re: Start with this: [url]http://www.daniweb.com/software-development/java/threads/99132[/url] | |
Re: ca1.get(Calendar.MONTH + 1) Calendar.MONTH is an int constant signifying "month", so MONTH+1 is another int constant signifying (I don't know what), so it get's the wrong field. You need (ca1.get(Calendar.MONTH) + 1) | |
Re: I don't [I]think [/I]you can use getResource... for things outside the jar/classpath (hopefully someone will correct me if I'm wrong...). However, this little snippet from deep in my old code box will give you a File reference to the jar that the class in which you execute this code came … | |
Re: java,exe takes the name of your [I]class[/I], not the name of your class [I]file[/I]... so that should be simply [B]java main[/B] | |
Re: cannot find symbol symbol : variable JOPtionPane Java is case-sensitive JOPtionPane != JOptionPane getKontonummer() is not a method of that class, it's in class Konto | |
Re: That's not what message digest does. Google [I]java messagedigest tutorial[/I] to find out more. Google [I]java encryption decryption[/I] to find lots of tutorials and sample code (Now, that wasn't hard was it? Next time maybe try Google first?) | |
Re: Scanner is useful when you know what kind of data to expect before you read it. From your description it sounds like you should use a BufferedReader, read one complete line at a time, then parse it for delimiters etc yourself. | |
Re: Maybe your array should be an array of Squares, not an array of ints? | |
Re: I had a quick look at that code and nothing appears to inefficient. There's certainly nothing wrong with the multiple || in the if. I would just tidy up the formatting, and a few comments to explain what each part of the code is supposed to achieve, then get on … | |
Re: If you have no programs written in Java then you don't need Java. If you have any programs written in Java (of which there are many) then you need a Java Runtime Environment, and it's best to have one with the latest security fixes. | |
Re: [url]http://www.java.com/en/download/whatis_java.jsp[/url] [url]http://en.wikipedia.org/wiki/Java_%28programming_language%29[/url] | |
Re: You could use the transform(AffineTransform at) method on your Path2D star1, with an AffineTransform obtained from AffineTransform.getRotateInstance(double theta, double anchorx, double anchory) to rotate it by any desired angle AffineTransformations look very scary, and often they are, but in essence they take a shape and change it by stretching, skewing, … | |
Re: [url]http://download.oracle.com/javase/tutorial/java/javaOO/objectcreation.html[/url] | |
Re: [CODE]print "0-59: " loop through the grades array if grades[i] >0 and <=59 print "*" print a newline[/CODE] You can repeat this for each line of the histogram or you can get smart and work out how to (a) do it inside another loop or (b) put that code in … | |
Re: Are those numbers random, or is there a pattern I can't see? | |
Re: You can use any language you want for any text you display to the user. You just need to check that the font you are using has all the necessary characters. French accented characters should be OK on any American or European operating system version. | |
Re: s1.toCharArray() is simpler. In Java a String is an object with many useful methods, and a char is a 16 bit numeric primitive which can be used to hold a single unicode value. A char array is just an array of 16 bit numbers, and it's whatever size you declare … | |
Re: Create a BufferedImage object, get its Graphics2D [url]http://download.oracle.com/javase/tutorial/2d/images/drawonimage.html[/url] use your existing paintComponent method to draw the panel on that Graphics2D save your BufferedImage to a file [url]http://download.oracle.com/javase/tutorial/2d/images/saveimage.html[/url] | |
Re: Lines 55/57 are a very bad idea. If an exception is thrown you have chosen to ignore it completely. Unless you are expecting the exception and know that it's OK, you should always start out by printing all the info related to the exception: [CODE]catch (Exception ex) { ex.printStackTrace(); }[/CODE] | |
Re: It would rather destroy the point of the policy file if you could change it from anything you download! Signing the applet is the normal solution. |
The End.