7,116 Posted Topics

Member Avatar for sirlink99

That looks pretty random to me. Were you expecting a perfect flat line (equal occurrences of each value)? - because that would NOT be random! And as dmanw100 said - Random has a method for random ints in a range

Member Avatar for sirlink99
0
3K
Member Avatar for sha11e

If you do a System.exit your program will terminate immediately and any unflushed buffers will be discarded, and any system resources you are holding may not be released. You should use try/catch/finally to ensure files and closed and resources released, and ideally allow your program to terminate normally by finishing …

Member Avatar for JamesCherrill
0
134
Member Avatar for CodeJava1

No, the size is the size. You can just return it, regardless of whether it's zero or more. The [ICODE]return 0;[/ICODE] is in there because the compiler will generate an error if that method doesn't return something. When you put in the correct code you can discard the [ICODE]return 0;[/ICODE]

Member Avatar for CodeJava1
0
255
Member Avatar for xxvicoxx

Maybe you can use [I]!getHireDate().equals("");[/I] because that value seems to be set during a hire, and cleared on a return?

Member Avatar for jeff-fisher
0
1K
Member Avatar for ajacintha

You can use a MouseListener to run your code when the mouse enters or leaves the frame, but I'm not sure whether that will work when the frame is hidden - you may need to have a transparent <something> in the place of the frame when it's hidden so that …

Member Avatar for JamesCherrill
0
221
Member Avatar for pseudorandom21

Yes, they are constants in the Color class. They look like this: [ICODE]public final static Color gray = new Color(128, 128, 128);[/ICODE] You can use reflection to loop through all the variables in the class and select those which are public static final Colors - this code does that and …

Member Avatar for JamesCherrill
0
586
Member Avatar for warlord902

[QUOTE=warlord902;1733570]Means unless we are updating or modifying something there is no need to make such methods synchronous?[/QUOTE] This will be true most of the time, but if you are accessing more than one value in such a method you may get inconsistent values for them when another thread modifies the …

Member Avatar for warlord902
0
190
Member Avatar for wallet123

[QUOTE]int[] arrNumbers = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};[/QUOTE] ie arrNumbers [i] == i+1 really?

Member Avatar for wallet123
0
712
Member Avatar for _neo_

The join statement won't be executed until "some heavy work" is finished anyway, so the timeout won't be useful. I think you need to start a second thread (or just a Timer) that waits for [I]timeout milliseconds[/I], and use that to terminate your work thread if necessary.

Member Avatar for _neo_
0
296
Member Avatar for mohamed moamen

You can't do drawing in Swing like that, it's not how it works. Create and use a subclass of JPanel and override its paintComponent method. When Swing needs to display your panel it will call your paintComponent, passing the correct Graphics object (actually an instance of Graphics2D) for you to …

Member Avatar for mohamed moamen
0
1K
Member Avatar for thanatos1
Member Avatar for AlexTrott

A bubble sort just needs to compare and maybe swap two consecutive members of the list a few times. Forget the sort for a minute, and write a method to compare two consecutive members of your DLL. Now write a method to swap two consecutive members of your DLL. Now …

Member Avatar for JamesCherrill
0
388
Member Avatar for JavaPrograms

[QUOTE=cOrRuPtG3n3t!x;1733782]why are you using this [icode]if (counter % 3 = 2){ }[/icode] i dont get the '% 3' and to be honest this must be the first time ive seen such an if statement[/QUOTE] Me too, but not because of the %, but because it's not Java. It won't compile …

Member Avatar for JamesCherrill
0
178
Member Avatar for CountryBumpkin

Those code fragments don't make any sense strung together like that - I assume you have just posted the bits you think are relevant. Anyway, B has int alarmId = A.getalarmId(); so class A must have a getalarmId() method, and that's how 'alarmId' gets passed from class A to class …

Member Avatar for Philippe.Lahaie
0
522
Member Avatar for rotten69

As always, it's hard to beat the official Sun/Oracle documentation for Java [url]http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html[/url]

Member Avatar for JamesCherrill
0
324
Member Avatar for cpole

@karthi.k.s: Please don't give people solutions to their homework. All it teaches them is how to cheat. Help them learn to develop their own solutions. And if you do post some code, set a good example by following normal Java naming and indentation conventions.

Member Avatar for JamesCherrill
0
176
Member Avatar for abhishek_s_n

Without a long look at there whole thing it's hard to be very specific, but in general: If you divide your application into smaller and smaller components (classes, methods etc) then each of those components becomes simpler and easier to understand (which is good) until eventually you reach a point …

Member Avatar for JamesCherrill
0
167
Member Avatar for sirlink99

I suspect there is no way in pure Java to prevent it, but you could have a WindowStateListener and immediately restore it to normal when it's minimized. On the other hand if you are choosing to ignore the user's decision to minimize your window, then you should have a very …

Member Avatar for dmanw100
0
96
Member Avatar for 03hasnam

[url]http://www.bank-holidays.com[/url] have a comprehensive database of world-wide public holidays. You get free access to view current info, but if this is a real app you can get the data in machine-readable form for a very reasonable price: [QUOTE]Receive your data in Excel format, with customized presentation, and including update alerts …

Member Avatar for dmanw100
0
2K
Member Avatar for subone

That's what happens when you print an object that doesn't have its own toString() method defined. It's the class name followed by its hash code. To print the contents of an array, convert it to a String by using [B]Arrays.toString(list)[/B]

Member Avatar for Traps
0
8K
Member Avatar for enterpise

1. Print out both those values after they are input so you can see exactly what values you are trying to use. 2. In your catch blocks don't just print "there was a problem", use ex.printStackTrace(); to see all the info related to the problem. ps: The server name may …

Member Avatar for enterpise
0
176
Member Avatar for sarah49

You have code to split out the RGB values from each pixel, so now you need some similar code to combine RGB values into a single int pixel. Between splitting them and re-combining them you can set r, g, and/or b to zero. Or, you can use bi.getRaster().getDataBuffer(); to get …

Member Avatar for JamesCherrill
0
208
Member Avatar for kamboz200
Member Avatar for coding101

Don't confuse string variables with Strings. In C terms, a String variable is a pointer, and its initial value is null. You can only create a string via [I]new String(some parameters)[/I] or as a String literal [I]"some string"[/I]. In both cases the size of the string is known when it …

Member Avatar for dheaven
0
238
Member Avatar for Bladtman242

If your tabs are all different then there's no point doing anything other than simple JPanels. If they all conform to certain style or content standards (eg a background image, or certain controls always in the same place) then its worth creating a subclass of JPanel with all the common …

Member Avatar for Bladtman242
0
204
Member Avatar for vb.net_beginner

This is the forum for the Java programming language, which isn't the same thing as the JavaScript scripting language. You'll find the JavaScript forum here: [url]http://www.daniweb.com/web-development/javascript-dhtml-ajax/117[/url]

Member Avatar for vb.net_beginner
0
82
Member Avatar for stevanity

According to [url]http://compilers.iecc.com/comparch/article/01-03-037[/url] it's LL(1), recursive descent

Member Avatar for stevanity
0
214
Member Avatar for Morley93

To clarify: You have a JFrame with a JPanel subclass that displays a menu. When one of the menu items is selected you want to display another JPanel subclass that contains your board (and this replaces the menu panel?). If so, I don't see the need for anything more than …

Member Avatar for Morley93
0
113
Member Avatar for aiwasen

The general consensus here is that beginners should stay with the simple command prompt applications (code editor, javac, java) until they have a solid base of understanding of Java. IDEs such as Netbeans or Eclipse provide a toolset that gives experienced users a huge increase in productivity, but if you …

Member Avatar for stultuske
0
254
Member Avatar for kyriacos1986
Member Avatar for Nordijac

[QUOTE=David Kroukamp;1730160]... in.read() method returns a string ...[/QUOTE] Absolutely wrong. You are advising a beginner here, so it's essential that you get your facts right. It's unacceptable to create this kind of confusion. You should check your code and your facts before posting. You should also read the previous entries …

Member Avatar for JamesCherrill
0
170
Member Avatar for mehnihma

The problem may be in the Boat class - did you declare colour and length as static by any chance?

Member Avatar for mehnihma
0
643
Member Avatar for JavaPrograms

Hi David, welcome to DaniWeb. I know your intentions were good, but we're here to help beginners build their own Java expertise. By posting complete pieces of code you run the risk that people will copy/paste without fully understanding, thus learning nothing (except maybe that it's easier to cheat than …

Member Avatar for David Kroukamp
0
427
Member Avatar for crbsathy

These posts are confusing variables and Objects. Remember that variables are either primitives (ints etc, not Objects) or reference variables (contain a reference to an Object); a variable is NOT an Object. Object's toString() is not defined to return anything related to the address of the object, nor does it …

Member Avatar for JamesCherrill
0
1K
Member Avatar for gourav1

Is writing [B]what [/B]one thing many times? Please try to explain exactly and precisely what is happening. You create your FilWriter in append mode (second parameter is [I]true[/I]), so every time you run the application you get another copy of the data added to your file.

Member Avatar for gourav1
0
270
Member Avatar for Mr.BunyRabit

I guess you'll have to write a small method that splits the String into its components, retrieves the actual Objects represented by those sub-strings, then start with an empty TreePath and use pathByAddingChild(Object child) to add all those objects to build the fill path. It's only the step of retrieving …

Member Avatar for Mr.BunyRabit
0
881
Member Avatar for morred

Sorry, this is nothing to do with copy constructors. You create an array and give it a size (30), and initially all those elements are null. You have a method to populate the array with data, but unless you call that 30 times, there will still be null elements in …

Member Avatar for morred
0
157
Member Avatar for MrBillyUK

Every time you read a line you call displayText, in which you create and add a new TextArea. You should create the frame etc with a single text area when the application starts, and just add the String to that existing text area in displayText.

Member Avatar for MrBillyUK
0
147
Member Avatar for Karlwakim

Short answer: Java is very widely used in commercial and corporate applications. It runs at least as fast as any other serious programming language except hand-tuned C code.

Member Avatar for Karlwakim
0
379
Member Avatar for abhishek_s_n
Member Avatar for rotten69

return printer(s); calls printer(s) again, which executes down to the last line where it executes return printer(s); etc infinitely

Member Avatar for rotten69
0
124
Member Avatar for J.S.AlKatheeeri

That's an extraordinary question to ask like that. If you were a complete beginner you would get a flood of replies introducing you to Google. But you seem to be in a programme for a Master's degree, so no excuses. This is on a par with someone doing a Master's …

Member Avatar for karthi.k.s
-2
139
Member Avatar for R32@

Anything(eg arrays) you create in your Java app is lost when the app terminates. To save data for later use you need to write it to a file or a database. Probably the easiest is to write in in text form (same as printing) to a text file. Google will …

Member Avatar for R32@
0
3K
Member Avatar for chixm8_49

The first code fragment you posted will definitely throw an NPE if it executes - do you have a try with an empty catch somewhere? Your inner loop has i++ where it should have j++ so it would loop infinitely if you ever managed to execute it. The fact that …

Member Avatar for NormR1
0
3K
Member Avatar for vaironl

Are you certain that the file is being broken into long lines, or is it possible that whatever viewer/editor you are using to look at the file is displaying it like that? If you read the file back into your Java program one line at a time, are the descriptions …

Member Avatar for JamesCherrill
0
709
Member Avatar for sieuwe

What is the point of the "Spelling" class? It's just an ArrayList, with some stuff for the "length" (current size) that is, as SasseMan said, totally redundant. Your main problem comes because you have two ArrayLists of words, and updating one doesn't update the other. Fix this by not having …

Member Avatar for JamesCherrill
0
225
Member Avatar for torkolort

If you are just selecting 5 random elements from a collection of 26 then frankly you are wasting your time worrying about efficiency, either for CPU or memory. Maybe with optimal coding you could save a microsecond of CPU, and a few hundred bytes of temporary memory. Unless you plan …

Member Avatar for JamesCherrill
0
331
Member Avatar for Armanious

It is apparently possible by using JNA to hook the native Windows mouse events... [url]http://stackoverflow.com/questions/3590226/working-example-of-jna-mouse-hook[/url] Please report back if you have any success with this.

Member Avatar for JamesCherrill
0
237
Member Avatar for ocw91
Member Avatar for puppycrazy

[QUOTE=zeroliken;1725523]use .equals() when comparing strings rather than == try to read this link for more info [URL="http://www.ensta-paristech.fr/~diam/java/online/notes-java/data/expressions/22compareobjects.html"]Java: ==,.equals()[/URL][/QUOTE] Good advice, yes, but in this case the code is comparing chars, not Strings [CODE]char oo = xx.next().charAt(0); if (oo == 'y')...{[/CODE] so .equals cannot be used in this situation. Maybe the …

Member Avatar for puppycrazy
0
357

The End.