7,116 Posted Topics

Member Avatar for sha11e

FileOutputStream is not buffered, so each time you write a few bytes to it Java writes them to the file (although the operating system will probably do its own buffering). For real-word-sized applications you would normally wrap it in a buffered stream for performance reasons like your book said. If …

Member Avatar for JamesCherrill
0
129
Member Avatar for pavani2006

Welcome to DaniWeb. But... 1. Always post code in code tags 2. We don't do people's homework for them. 3. This post is from 2007. You are certainly not going to help the original poster. To avoid a difficult conversation with a DaniWeb administrator, check out the Member rules before …

Member Avatar for JamesCherrill
0
225
Member Avatar for Raghu_Ganapm

When you try to use a reference variable or expression that does not contain a reference to an Object - ie contains null. This may be because it hasn't been initialised, or it may be the result of calling a method that returns null following an error or other condition …

Member Avatar for hfx642
0
97
Member Avatar for danthevan

I haven't read all that code, but... it looks like waitMessages loops indefinitely, so when you call it it never returns, so nothing after it gets executed. Maybe it needs to run in its own thread and you just start it from the constructor?

Member Avatar for danthevan
0
238
Member Avatar for ilovejava

Depends on how you define/store a Deck. Ideally Deck will be a class, so you can just have an array of them: [CODE]Deck[] myDecks = new Deck[8]; // create array for (int 1 = 0; i < myDecks.length; i++) { myDecks[i] = new Deck(...); // initialise array }[/CODE] but if …

Member Avatar for JamesCherrill
0
273
Member Avatar for ilovejava

It's quite common for a beginner to put everything static - it's because they start coding in the [ICODE]public static void main(String[] args)[/ICODE] method, and immediately discover that they get compiler errors if the members they reference are not also static. More experienced Java developers tend to have a main …

Member Avatar for ilovejava
0
2K
Member Avatar for lbgladson

[QUOTE=lbgladson;1673761]Do you think this means I should have my generator in the constructor? Is this even possible?[/QUOTE] Yes to both.

Member Avatar for lbgladson
0
386
Member Avatar for programing
Member Avatar for caswimmer2011

This link [url]http://stackoverflow.com/questions/1248510/convert-string-to-keyevents[/url] includes a brute force switch to do the conversions. Not pretty, but probably your quickest & easiest option.

Member Avatar for caswimmer2011
1
1K
Member Avatar for queendaedra

Zaad gave you a good answer. Maybe you need to read it again. He's explained what you need to do, and why. If you're looking for someone to do it for you then you're in the wrong place.

Member Avatar for Zaad
0
394
Member Avatar for soham.m17

Are you confident about the isHit method? As long as isHit returns true for the first element in your list, this code will always set mutual = 0 and exit the loop

Member Avatar for soham.m17
0
222
Member Avatar for queendaedra

Hi Taywin. Don't know if you spotted the earlier thread on the same subject, but Zaad already explained all that, but the OP didn't see that as helpful. :(

Member Avatar for JamesCherrill
0
155
Member Avatar for soham.m17

I think you are going to have great difficulty doing D&D on parts of a single graphic. Maybe you should consider drawing each individual draggable thing in its own JLabel (setOpaque(false)), then it's reasonably straightforward to handle clicks & drags for each JLabel.

Member Avatar for soham.m17
0
4K
Member Avatar for Dwillich87

You are trying to define methods inside other methods, and that's not legal. You probably want to have a constructor for Circle that takes radius as a parameter and stores it. You can then create a new Circle object using the radius value supplied by the user. Then all your …

Member Avatar for JamesCherrill
0
126
Member Avatar for CKShia

After a very quick look I can see no reason why you can't just add a [ICODE]private LoadImage loadImg = new LoadImage();[/ICODE] to your class like you said - the constructor for LoadImage will do the necessary initialisation, so there's no need to add it to Brand's constructor. You will …

Member Avatar for JamesCherrill
0
2K
Member Avatar for nickliutw

Your enum is defined inside the card class so you need to qualify its name to use it. Better/easier is to move the enum declaration to be outside the card class.

Member Avatar for ~s.o.s~
0
204
Member Avatar for I<LateNupurGuha

A trawl through the JLS and posts on the more credible Java sites gives a consistent answer: If the code has entered one or more [ICODE]try [/ICODE]blocks then every associated [ICODE]finally [/ICODE]block will be executed unless the JVM is terminated, eg by calling [ICODE]System.exit[/ICODE]. (As one wag wrote "that's why …

Member Avatar for I<LateNupurGuha
0
117
Member Avatar for gahhon

[CODE]Planet[] arrayPlanet = new Planet[4];[/CODE] creates an array with slots for four Planets, but all those slots are originally empty (null). You need to initialise them with actual instances of Planet, eg [CODE]arrayPlanet[0] = new Planet("Venus", 255); arrayPlanet[1] = new Planet("Mercury", ... etc[/CODE] Now you can get rid of your …

Member Avatar for gahhon
0
130
Member Avatar for I<LateNupurGuha

Correct all you want - Peter Budo's post still stands. Did you read it?

Member Avatar for peter_budo
-1
62
Member Avatar for i2u2me

What kind of object do you think that could be? How big do you think it could be? Java 7's NIO package includes a MappedByteBuffer class that maps the contents of the file to a logical array of bytes (or other primitive types) in memory, but you do have to …

Member Avatar for i2u2me
0
75
Member Avatar for Laxman2809

[QUOTE=jassikaur;1671587]hey friends ..em new to java...Can anybody tell me..Can We store the data in array permanently?? everytime i run my java code with array as object of class...its previously entered values disappear...:([/QUOTE] You need to write your array to a file before closing your program, and read it back in …

Member Avatar for hiddepolen
0
293
Member Avatar for cgen
Member Avatar for DragoDraco

For a start I can see 5 { but only 4 } and what is [ICODE]char(++ alpha)[/ICODE] intended to be?

Member Avatar for DragoDraco
0
160
Member Avatar for mattnguyen45

That's because the print statement is outside the loop. The loop goes from line 121 to line 127, and iterates without printing anything. When it exits the loop it goes on to line 129 where it prints the last result.

Member Avatar for JamesCherrill
1
174
Member Avatar for Jfunch

The previous post answers how to do this in any version of Java. If you are lucky enough to be on the recent Java 7 (version 1.7) you could also use the new fork/join framework that was introduced with Java 7. However, it doesn't exist in any earlier version [url]http://download.oracle.com/javase/tutorial/essential/concurrency/forkjoin.html[/url]

Member Avatar for JamesCherrill
0
2K
Member Avatar for yup790

"it doesn't seem to work" gives us nothing to go on. Exactly what error messages do you get, or exactly how does the output differ from the expected output? Be as precise as possible.

Member Avatar for JamesCherrill
0
245
Member Avatar for Aviras

[QUOTE]The problem lies whenever I try to access dungeon in the DungeonRoom object the player is in[/QUOTE] What does that code look like? Is it possible you are accessing the dungeon array from your current DungeonRoom frather than that in the "parent" HostileArea? That would explain lack of error messages …

Member Avatar for JamesCherrill
0
223
Member Avatar for gedas

Yup, I think you will have to override the hashCode and equals methods for your phone number class, but that's not too hard. Eg: you could convert the number to a String in a standard format, and then use that String's hashCode (as per previous post, but return unique.hashCode();

Member Avatar for gedas
0
118
Member Avatar for buskerott

Here's nothing particularly wrong with this, as far as it goes. You may want to do something different when the user types a letter instead of a valid integer.

Member Avatar for JamesCherrill
-1
211
Member Avatar for lwisnas

String is not an exception. As for every other class == tests for two objects being the same object and equals(...) tests for two objects being equivalent as defined by the author of the class. If you are deriving Strings from an expression and comparing them with String constants in …

Member Avatar for hiddepolen
0
108
Member Avatar for solarmotion

[ICODE]Entity[] film=new Entity[100];[/ICODE] This line of code creates an array of 100 Entity references, but they all have the initial value [I]null[/I]. So when you execute [ICODE]film[i].setItemCode(scn.next());[/ICODE] film[i] is still null, and you get a null pointer exception (I assume that is the error you get. Next time please be …

Member Avatar for Prateek nandan
0
419
Member Avatar for vaironl

Short answer: yes. Longer answer: Java's GUI classes ("Swing") are more aimed at standard business applications, with a standard look and feel. Your panels will be pretty straightforward if you accept one of Java's standard looks. On the other hand you can draw shapes and images any way you want …

Member Avatar for hfx642
0
109
Member Avatar for heybunny

Line 15: Math.random returns a value >=0, <1 So when you convert it to an int the int will always be zero. Line 21 etc, the test for two values being equal is ==, not = (that's assignment). Yes, you should definitely download the JDK at home. However, the general …

Member Avatar for ilovejava
0
2K
Member Avatar for programing

equals method looks OK to me - if you wrote it why do you need an explanation of how it works? A copy constructor takes one parameter, which is an existing instance of the class (Triangle). It populates the variables of the new instance by copying the values from the …

Member Avatar for hiddepolen
0
136
Member Avatar for cse.avinash

The point it is making is that there is no guarantee about how Java will store those numbers. All that is guaranteed in the JAva language specification is their behaviour. So chosing byte, short or char to save space may be pointless because Java may chose to allocate a full …

Member Avatar for JamesCherrill
0
113
Member Avatar for naomi_01
Member Avatar for vijaykavin10

When you handle one of those events the event classes contain information about the event, eg which component was the source of the event, the x,y coordinates if it was a mouse click, which keyboard modifier keys were pressed at the time etc

Member Avatar for hiddepolen
0
84
Member Avatar for Jessurider

That's called [B][I]image steganography [/I][/B], so Google those terms. Here's a good article to start with: [url]http://mo.co.za/open/stegoverview.pdf[/url]

Member Avatar for Ezzaral
0
115
Member Avatar for ethio
Member Avatar for ethio
0
126
Member Avatar for gahhon

The equals method requires one parameter, which is the object with which the current object is being compared. You use the fields of the two objects to decide whether you consider them to be equal or not. eg You have a Person class. You consider two Person objects to be …

Member Avatar for JamesCherrill
0
224
Member Avatar for cdea06

The contents of a for loop can be a statement or a block. Either way the contents are executed as many times as the (initialize; condition; increment) specifies. [CODE]for (initialize1; condition1; increment1) for (initialize2; condition2; increment2) statement;[/CODE] Here the first for executes the following code as many times as it …

Member Avatar for JamesCherrill
0
128
Member Avatar for noXi

Parsing this is easy. Split each line at the first : and drop the " marks. That gives you a load of name/value pairs that you can do with as you wish. Unless you are really that lazy...

Member Avatar for noXi
0
257
Member Avatar for Jessurider
Member Avatar for Mideoan

Very quickly: you are trying to put raw sales data into your linked list. That's wrong. The linked list should contain instances of DivisionSales. You should create new instances of DivisionSales from the user's data and add those to the list. For the reporting you iterate through the list getting …

Member Avatar for JamesCherrill
0
191
Member Avatar for sullivan757

DaniWeb Member Rules include: "Do provide evidence of having done some work yourself if posting questions from school or work assignments" [url]http://www.daniweb.com/forums/faq.php?faq=daniweb_policies[/url]

Member Avatar for sullivan757
0
3K
Member Avatar for Java2011

[QUOTE]You are missing a critical call (the one that draws a letter) in your writeText method.[/QUOTE] That says it all really. I looked around lines 165-173 and I see you setting up array indexes etc, but you never call any method that will display/draw anything.

Member Avatar for Java2011
0
147
Member Avatar for kulpreet lkaur

If you don't have an administrator password then you can't store a file there. Why do you want to do that? What is the file? Maybe there is somewhere else you can put it.

Member Avatar for kulpreet lkaur
0
143
Member Avatar for chiiqui

Pass by reference: wrong. All Java calls are pass by value, even when the value being passed is a reference. Your code will work. Arrays are Objects, and Objects are passed to methods by passing a copy of a reference to the Object. So your parameter aTest contains a copy …

Member Avatar for JamesCherrill
0
251
Member Avatar for sidra 100
Re: java

All Java words are case-sensitive and have to be spelled exactly correctly, so Println is not the same as println. In your code you have printIn. The correct version is println

Member Avatar for vijaykavin10
0
98
Member Avatar for eziekiel123

Do you mean you want it to do the reverse translation, eg you enter "2" and it replies "ABC"? If so that's exactly the same structure as the program you already have; you just need to change the constants inside the switch, plus a couple of if tests.

Member Avatar for JamesCherrill
0
234

The End.