7,116 Posted Topics
Re: You can pass an array as a parameter, ie declare the method as public void Sort(Transport[] arrayOfTransportsToBeSorted) then in the method sort that array. and call it like this Sort(metro); | |
Re: I suggest you create a method to do the user interface - ie display the menu, get the input etc. That will keep your code neat and organised = easy to read and undersand. At this stage it's fine to put that in the main class. "if the answer is … | |
Re: You can use the following classes: 1. File - this handles the name/path of the file 2. PrintStream - this allows you to use the print() method to send your text to the File 3. FileReader - this allows you to read in the file that you printed earlier 4. … | |
Re: Just a guess, but since these are running on the same machine the server may be sending the response before the client has opened its input stream? You could try opening both the input and output streams before starting to write anything. | |
Re: If your methods etc are all static then you can declare your variables as public static [I]outside the methods[/I] which (a) makes them available to all methods in that class and (b) makes them available to other classes by referring to them using the class name, eg ObtainKey.SearchWord This will … | |
Re: Like the comments in the code suggest, you need an array of Enemies, not the hard-coded enenmy1-3. The array can then be a big as needed in each run. | |
Re: In order to be able to sort instances of some class (such as Scores) you need to be able the compare two Scores to see what order to sort them in. Scores is a class you define, so there's no sensible guess that Java can make about what order you … | |
Re: In your event handler you can use evt.getComponent() to get the actual card object that was clicked, which you can then use setIcon etc on. That way you can also use the same event handler for all the cards. If cards are some kind of Swing JComponent then you can … | |
Re: There isn't a "Directory" class. Both files and directories are represented by the File class, so all you need is is an ArrayList<File> | |
Re: You can draw your image anywhere in your JFrame using drawImage(...) in the paintComponent method (you should normally override paintComponent, not paint). eg see: [url]http://www.particle.kth.se/~lindsey/JavaCourse/Book/Part1/Java/Chapter06/images.html[/url] Divide your JFrame (conceptually) into a grid of element size equal to the size of your image, then use the text file to determine which … | |
Re: Do you mean the file is empty, or is there no file at all? After line 9 try System.out.println(Arrays.toString(Reg)); to help locate the problem. | |
Re: If you want to exit the app you don't need lines 3-7, you can just do that directly on line 13 If you don't want to exit, you don't need lines 3-7 So in the end it's 3 lines of boilerplate (excluding {}). | |
Re: The action listeners are both inner classes of your main class, so if you move the declaration of [I]StudentDB db[/I] out to the main class class you can access it from both listeners. | |
Re: You didn't give us the line number for your exception, but, if it's line 92 you will need to look at the code/doc for org.lwjgl.opengl.Display to find out what it's complaining about and why. But - where do you create/open/display the Display window??? | |
Re: check out the params for substring - you select a substring starting at 0 ending at the last \, but you want one starting at the last \ and extending to the end of the string. | |
Re: I haven't studied the code, but it looks like you have an array of names, slaes etc in the scanner constructor, but the getName, and the print don't loop thru that, they just access a single string? I would have expected to see a SalesPerson class, each instance representing a … | |
Re: [CODE] // determines whether each indiviual character of the user entered string is a letter (is counting cumilative for each string still) for (int x = 0; x < inputLine.length(); x++) if (Character.isLetter(inputLine.charAt(x))) letter++;[/CODE] This little piece of your code examines the String inputLine and sets the variable letter to … | |
Re: How much time have you been given for this? - it will help us get a feel for how much detail is expected. | |
Re: This sounds to me like you should be using a JTable, not a JTextArea. | |
Re: Please post the full NPE message with all the line numbers and the actual lines they refer to. Indenting the code properly will also help to identify problems. | |
Re: Have a look at this recent thread on exactly that subject [url]http://www.daniweb.com/forums/thread316225.html[/url] | |
Re: It would help if the code you posted corresponded to the error messages. Line 149 is for(i=0;i<256;i++) - no NPE there! After that you loop thru all 256 elements of the array, but you previously populated only as many elements as there lines in the data file, so if there … | |
Re: Can't tell without the your code, but if you're trying to parse that "{" at the beginning of your input string, that could be the cause of your problem. | |
Re: What problem exactly are you having - please give expected vs actual results. ps: Shouldn't tax depend on the quantity * price, not just the unit price? | |
Re: Are you sure that columnMarginChanged in your TableColumnModelListener has actually been called before it drops thru into the problem code - or is txtAdminTextFields initialised somewhere else? | |
Re: Looks like the array is big, and you just populate the first "n" elements from the data file, so the remaining elements are un-initialised, and give an NPE when anyone tries to compare them for sorting. | |
Re: Following normal conventions, the constructor for the new window does everything except make it visible. Where you have NewContact n = new NewContact(); you need to follow that with a n.setVisible(true); | |
Re: Re-read cale's post. You call getData() for Salary Experience Education but nowhere for a manager do you call get() for Name and Code | |
Re: [url]http://www.java2s.com/Code/JavaAPI/java.lang/ThreadjoinUsingjointowaitforthreadstofinish.htm[/url] | |
Re: this(...) calls another constructor for the same class. So the constructor on line 15 starts by calling the default constructor (no args). The constructor on line 22 starts by calling the constructor sphere(double xcentre,double ycentre,double zcentre) to deal with x,y,xcenter before going on the handle the extra r2 parameter Since … | |
Re: [QUOTE]i searched over google but didn't find the suitable answer...! [/QUOTE] The technical OO terminology is "accessors and mutators" - googling these will give you lots of good info. Here's a good article to start with: [url]http://java.about.com/od/workingwithobjects/a/accessormutator.htm[/url] | |
Re: I just Googled it and found loads of examples etc. Google is your friend. | |
Re: This question doesn't quite make sense - the actionEvent is created by Swing normally. Can you please explain exactly what you want to achieve? | |
Re: It's a mistake. It should read byte[] b=new byte[255]; byte is a numeric type - an 8 bit integer. This declares an array of 255 bytes. Because b was incorrectly declared, the methods that have it as a parameter also don't compile. The method that was supposed to be used … | |
Re: ParkedCar.minparked ParkedCar is the class, so this is a reference to a [B]static [/B]variable. But minparked is (correctly) an instance variable. You have to refer to it using an instance of the ParkedCar class, not the class itself, as in ParkedCar car = (something) if (car.minparked (etc) | |
Re: This [url]http://download.oracle.com/javase/tutorial/uiswing/components/table.html[/url] is a very good intro, and includes a section on how to sort a table. | |
Re: Within the face's drag event handler you can get the new mouse coordinates. If you kept a copy of the previous coordinates you know what the move was (change in x, change in y) and you can explicitly move the hat by that same amount. | |
Re: You just need an int to hold the number of entries already in the array(s) - initial value 0. This is also the correct index to use for the first available array element. Increment it each time you add something to the array. [CODE]int numEntries = 0; while (user is … | |
Re: Duplicate definitions of studentDB on lines 5 and 10. By defining a new one on line 10 that's the one that gets initialised, but it ceases to exist at the end of the constructor method. | |
Re: getData is an instance method, so you call it via an instance of the Manager class (eg "first"). You have called it via the name of the class, not an instance. You can only do that for static methods. | |
Re: Sorry Dupron, but no cigar. Windows file names are not case sensitive. The message was about cmis141Student1.participationGrade(); There is no such method in that class, so the symbol is undefined. | |
Re: Read the documentation. Java Language Reference section 4.2.1 | |
Re: You can use a boolean to tell you which letter to use. Instead of line 23 test the boolean, assign the appropriate char, then toggle the boolean true -> false or false -> true so that next time thru the loop you will print the other char. Or Get a … | |
Re: It looks like the coords are loaded into the x/ycoordinates arrays - so each element of the array-pair represents a different point. In which case you already have access to all the points, you don't need any new variables. Eg - to connect the first two points by a line … | |
Re: Yes, gameLoop looks like the main method here. It's normally considered bad practice to put too much code in main() because this hinders any possible re-use. The ideal main() just instantiates an instance of the class, and calls an instance method that does whatever needs to be done. So, the … | |
Re: A safe way to check for a "blank" line is to trim() the String then test if its length is 0. | |
Re: By printing the right number of blank lines before it starts, then printing the right number of spaces before the *... on each line. | |
Re: I assume this is a continuation of the recent thread? In that, you said scores should be in an integer array, and I told you how to convert the strings to integers. If you make it an array of ints it will sort numerically. However, if you want to sort … |
The End.