7,116 Posted Topics

Member Avatar for nyemba

[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 …

Member Avatar for Taywin
0
377
Member Avatar for vaironl

[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 …

Member Avatar for vaironl
0
3K
Member Avatar for cse.avinash

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 …

Member Avatar for hszforu
0
110
Member Avatar for G_S

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 …

Member Avatar for ~s.o.s~
0
212
Member Avatar for jcooler

Please check the Member Rules for DaniWeb "Do provide evidence of having done some work yourself if posting questions from school or work assignments"

Member Avatar for chiiqui
0
214
Member Avatar for chiiqui

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 …

Member Avatar for chiiqui
0
233
Member Avatar for Pravinrasal

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]

Member Avatar for JamesCherrill
0
276
Member Avatar for Kamal_Java

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).

Member Avatar for peter_budo
0
256
Member Avatar for Dexxta27

} 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.

Member Avatar for Dexxta27
0
174
Member Avatar for techyworld

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.

Member Avatar for JamesCherrill
0
208
Member Avatar for sahilsinghi

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 …

Member Avatar for JamesCherrill
0
369
Member Avatar for aFACE

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?

Member Avatar for JamesCherrill
0
124
Member Avatar for jezer08

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.

Member Avatar for JamesCherrill
0
163
Member Avatar for carmzy

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 …

Member Avatar for NormR1
0
102
Member Avatar for lse123

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. …

Member Avatar for mKorbel
0
200
Member Avatar for Feriscool

[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 …

Member Avatar for mKorbel
0
197
Member Avatar for sathya88

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.

Member Avatar for NormR1
0
8K
Member Avatar for nikelin

[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]

Member Avatar for JamesCherrill
0
409
Member Avatar for Feriscool

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 …

Member Avatar for JamesCherrill
0
153
Member Avatar for lucas.ploeg

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). …

Member Avatar for JamesCherrill
0
3K
Member Avatar for simply2smart
Member Avatar for javaAddict
0
200
Member Avatar for crazins

[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 …

Member Avatar for crazins
0
324
Member Avatar for gunjannigam

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.

Member Avatar for mKorbel
0
862
Member Avatar for cse.avinash

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]

Member Avatar for JamesCherrill
0
92
Member Avatar for cse.avinash

[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 …

Member Avatar for JamesCherrill
0
163
Member Avatar for NyQii

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[] …

Member Avatar for NyQii
0
136
Member Avatar for jayyzhao

Just create a static int variable outside the method, and increment inside the method.

Member Avatar for hszforu
0
432
Member Avatar for hszforu

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 …

Member Avatar for hszforu
0
259
Member Avatar for Jessurider

[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]

Member Avatar for JamesCherrill
-1
136
Member Avatar for maroom

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, …

Member Avatar for maroom
0
160
Member Avatar for Prisms

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 …

Member Avatar for JamesCherrill
0
192
Member Avatar for MoZo1
Member Avatar for fonzi

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.

Member Avatar for 115harman
0
150
Member Avatar for chiiqui
Member Avatar for chiiqui
0
399
Member Avatar for maroom

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 …

Member Avatar for JamesCherrill
0
343
Member Avatar for maroom
Member Avatar for JamesCherrill
0
218
Member Avatar for peter_budo

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.

Member Avatar for peter_budo
2
508
Member Avatar for chixm8_49

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]

Member Avatar for stevanity
0
82
Member Avatar for harsimran05

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 …

Member Avatar for harsimran05
0
97
Member Avatar for vishalbhavsar

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.

Member Avatar for JamesCherrill
0
108
Member Avatar for ranu jain

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 …

Member Avatar for JamesCherrill
0
179
Member Avatar for jtodd

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?

Member Avatar for JavaStudent321
0
432
Member Avatar for ITHope

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

Member Avatar for ITHope
0
288
Member Avatar for java.util

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 …

Member Avatar for Taywin
0
150
Member Avatar for anuran
Member Avatar for logicmonster

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.

Member Avatar for logicmonster
0
983
Member Avatar for BobTheLob

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 …

Member Avatar for JamesCherrill
0
132
Member Avatar for hfx642

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 …

Member Avatar for JamesCherrill
1
665
Member Avatar for dennysimon

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

Member Avatar for dennysimon
0
6K
Member Avatar for denvious

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 …

Member Avatar for denvious
0
9K

The End.