7,116 Posted Topics
Re: [QUOTE=nyemba;1655180]I'm having trouble sorting names in alphabetical order using counting sort[/QUOTE] Not surprising really - the counting sort algorithm is for sorting small integers (or objects keyed by small integer keys). Are you sure you are trying to do the right thing here? ps This is a cross-post, please check … | |
Re: [QUOTE=Taywin;1652886]scanner.next() return only 1 character each time. [/QUOTE] Hi Taywin - I think this must have been a keyboard error (I'm sure you know what next() does really) ;-) [QUOTE]public String next() Finds and returns the next complete token from this scanner. A complete token is preceded and followed by … | |
Re: If yo are new to Java then a full-featured IDE like NetBeans or Eclipse is not a good idea. It will overwhelm you with features you don't understand yet, and block your progress by making suggestions and corrections that you haven't learned yet. For now, just stick with a good … | |
Re: Sounds reasonable so far. Maybe you would want to pass the file name to a constructor for this class so that it's not hard coded? If you are writing this info to a file then presumably you will read it back at some point? If so all the code associated … | |
Re: Please check the Member Rules for DaniWeb "Do provide evidence of having done some work yourself if posting questions from school or work assignments" | |
Re: 1. You should know better by now. It's not good enough to say "i have an error" - you must post the full error meswsage. Anyway, you have 2 constructors that take a String as the only parameter, so there's no way for Java to tell which to use (the … | |
Re: This tutorial teaches you how to print anything that you display in a JFrame [url]http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-Printing.html[/url] | |
Re: Not sure wht's going on here, but DeadSoul's post (the first one, not the insult) is incomplete. His instrctions give you the .java file, but you need a .class or a .jar to run the program (just like chirag said). | |
Re: } on line 39 matches the { on line 4 and closes the definition of the class. Then there are more methods - but you can't have a method outside a class. | |
Re: Is this a quiz? If you have a problem with your program please explain exactly what the problem is - if there is an error message post the whole message, if the output is wrong explain what it should be and what it is. | |
Re: Every java program needs a main method like this: [CODE]public static void main(String[] args) { // your program startup code goes here }[/CODE] The code in the main method is what gets executed when your program starts. For example you could call your constructor (passing in some test data), then … | |
Re: Your data has 3 distinct components (last name, first name, birth-date) for each patient, so a simple array isn't going to be enough here. In Java I would expect to see another class called Patient that contains these fields. Is there such a class somewhere in this exercise? | |
Re: If you want the option pane to display when the user clicks the button you need to put that code in the button's action listener and not in your main GUI initialisation code. | |
Re: I assume the user enters a name/password then clicks the btnAdd button? If so: Each time he does that you just need to add one name/password, not 5; but you do need to keep count of how many he has entered. For that you need a counter that is declared … | |
Re: 1. "send an ImageIcon object as the Image argument that drawImage() expects" this will be true if and only if an ImageIcon is also an Image, ie it extends the Image class - which you can find out in less than 30 seconds by looking at the ImageIcon API doc. … | |
Re: [QUOTE=Feriscool;1652880]All you need to know is "null pointer exception on lines 17, and 22"[/QUOTE] That's a response that won't help you. You may think you know what we need to know, but if your knowledge was complete and correct then you would also know the answer to your problem. Making … | |
Re: The basic mechanism is the same for any size file. Is the data arriving too fast for the client? In that case use the same socket connection to send ready/not ready messages from the client to the server to keep things synchronised. | |
Re: [QUOTE=NormR1;1265446]One other thing about the requirement. The class file doesn't know the name/path of the jar file it is in.[/QUOTE] Here's a way to do it - I found this ages ago, so I can't remember where I saw it, but it works for me... [CODE]File jarFile = new File(this.getClass().getProtectionDomain().getCodeSource().getLocation().toURI());[/CODE] | |
Re: I don't see anything particularly illegal about the use of static and local variables here, but the code as posted is clearly wrong: [CODE]for (int[] data : ARRAY) { int numberOne = data[0]; // scope of numberOne is this for loop // totally usless loop - copies multiple values to … | |
Re: I assume you have some way of knowing where one file and and the next begins? If so, maybe you can wrap your input stream in a FilterInputStream that recognises the end of file and returns -1 from its read method(s) before consuming the EOF marker (whatever that may be). … | |
Re: Very odd. What did you do to be certain that it's null? What OS are you using? | |
Re: [CODE]for(b=list;b != null;b=b.rest) System.out.print(b.first);[/CODE] Ignoring some Java syntax details, this pseudo code looks good to me. Here's how this works: b starts out referring to the whole original list the first pass of the loop prints the first element of b, ie the first in the original list b is … | |
Re: How long is it taking? Can you post your code re the thread you set up - if that's done right it won't hold up the GUI. | |
Re: Java chars are 16 bit integers that are used to hold Unicode values. You can do arithmetic with them if you want. The type "int" is a 32 bit signed inetger. [url]http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2[/url] | |
Re: [CODE]int arr[]=new int[3].[/CODE] arr is a reference variable (like a pointer, but more like a handle) that holds a reference to an array of 3 ints that is allocated on the heap. In c terms, Java's [B][I]someType varName[/I][/B] is more like C's [B][I]someType *varName[/I][/B]. If its a local variable or … | |
Re: I don't know what you mean by "works" if you can't test it, but anyway... The normal way to use main in a single class situation like yours goes like this: [CODE]public class XXX { XXX() { // constructor(s) ... // lots of method definitions ... public static void main(String[] … | |
Re: Just create a static int variable outside the method, and increment inside the method. | |
Re: The println method takes just ONE parameter, a String expression. You are trying to pass a String and and int as two parameters (separated by a ,) so you get an error saying it can't find a println method that takes a String and an int as parameters. You can … | |
Re: [QUOTE]Do provide evidence of having done some work yourself if posting questions from school or work assignments[/QUOTE] Source: DaniWeb rules - which you should know by now. [url]http://www.daniweb.com/forums/faq.php?faq=daniweb_policies[/url] | |
Re: If you are complete beginner then forget about IDEs for now. You will learn more by working with an editor & compiler. IDEs will generate code and fix problems for you, but if you don't fully understand what they are doing and why, you will get into trouble. When, eventually, … | |
Re: Norm's right - there's a class called Map that you could use, but I suspect that this a bit advanced for your stage of learning, and that your teacher had something more basic in mind. Java has no in-built knowledge of raed letters and numbers, so there's no automatic way … | |
Re: Could be a firewall blocking the port for you? | |
Re: You use a switch to convert month number to name, which is a pretty clunky way to do it. Better to have an array of 12 Strings ("Jan","Feb" etc) and use the month number as an index to access the correct name. | |
Re: In that case GUIs (Swing) would be a good place to go next. | |
Re: You declare [CODE]ArrayList<Customer> cl=new ArrayList<Customer>(); ArrayList<Book> bl=new ArrayList<Book>();[/CODE] inside the main method, so they are local to that method. If you want to access them from all the methods of the class they need to be declared outside any one method - like the variables in your Customer and Book … | |
Re: Duplicate thread. He wants someone to do it for him. Perhaps a mod can delete this? | |
Re: The ability to use (limited) HTML comes from JLabel, which is used to render tooltips. Many other Swing components (eg JList) also use JLabels to display a line of content, so this technique can be used to format text in many Swing components. | |
Re: No so obviously. There's absolutely no reason why you can't have a Vector of Vectors. Just remember that you have to populate the outer Vector with new inner Vector(s). [CODE] Vector<Vector<String>> v = new Vector<Vector<String>>(); v.add(new Vector<String>()); v.elementAt(0).elementAt(0) ...[/CODE] | |
Re: Border layout is OK to get started, but if you're interested in good layout you soon run into its limitations. The ultimate manager is GridBagLayout, which will do anything you can dream of, although at the cost of a steep learning curve at the start. If you are going to … | |
Re: Src.zip has a zillion files, not just java source either. If you want the javadoc for the API classes you can download it from Oracle's Java site. | |
Re: It's in the doc for bufferedreader... [QUOTE]In general, each read request made of a Reader causes a corresponding read request to be made of the underlying character or byte stream. It is therefore advisable to wrap a BufferedReader around any Reader whose read() operations may be costly, such as FileReaders … | |
Re: That's a run time message generated when you try to run code that previously failed in compilation. What is the exact message that you get when you first compile it? | |
Re: Line 17 readLine returns "2 3", so parseInt throws an error. Your code would work if you typed one number on each line, or if you used an input parser that has methods like nextInt | |
Re: Line 25 you call print and pass three parameters. There is no print method in the PrintStream class that takes 3 parameters. You can concatenate those 3 params together into one String parameter, and that will print OK. ps: your method also promises a return type of int, but returns … | |
Re: It would help if you described EXACTLY what your problem is. | |
Re: Doing the calculation like that is horribly complex. It works out much easier to write a method that converts a date to int days since 1/1/1900, then you can just subtract one from the other. | |
![]() | Re: I haven't tried this, but it may contain the seed of as useful idea? Find the highest and lowest value (1 loop, 1 pass) - note the indexes of those values Repeat, but skipping the highest/lowest elements - this notes the second highest and second lowest The remaining element is … |
![]() | Re: What is the purpose of the new action listeners you are adding to the component? Are they to track when the value of the field is being changed by the buttons? If so, wouldn't it be better to implement an addChangeListener method for the whole component that will register listeners … |
Re: Yes, setBounds is useless when you are using a layout manager. You can use setPreferredSize, setMinimumSize, setMaximumSize and, depending on your layout manager and how all the components are defined, the layout manager will do its best to comply | |
Re: First: the getName method is incorrectly defined as static. That's wrong - it doesn't apply to the whole class, but to each individual instance. Ditto the variables - they [B]must not[/B] be static - each instance of Staff has its own name and ID. [CODE]for( int i = 0; i … |
The End.