7,116 Posted Topics
Re: 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 … | |
Re: 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 … | |
Re: 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 … ![]() | |
Re: 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? | |
Re: 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 … | |
Re: 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 … | |
Re: [QUOTE=lbgladson;1673761]Do you think this means I should have my generator in the constructor? Is this even possible?[/QUOTE] Yes to both. | |
Re: nth term looks like 4/(2n-1) to me. | |
Re: 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. | |
Re: 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. | |
Re: 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 | |
Re: 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. :( | |
Re: 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. | |
Re: 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 … | |
Re: 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 … | |
Re: 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. | |
Re: 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 … | |
Re: [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 … | |
Re: Correct all you want - Peter Budo's post still stands. Did you read it? | |
Re: 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 … | |
Re: [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 … | |
Re: For a start I can see 5 { but only 4 } and what is [ICODE]char(++ alpha)[/ICODE] intended to be? | |
![]() | Re: 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. |
Re: 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] | |
Re: "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. | |
Re: [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 … | |
Re: 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(); | |
Re: 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. | |
Re: 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 … | |
Re: [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 … | |
Re: 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 … ![]() | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
![]() | |
Re: 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 | |
Re: 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] | |
Re: Did you ever try to create an object from an abstract class? | |
Re: 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 … | |
Re: 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 … | |
Re: 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... | |
Re: What do you mean "the summary of a file"? | |
Re: 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 … | |
Re: 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] | |
Re: [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. | |
Re: 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. | |
Re: 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 … | |
Re: 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 | |
Re: 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. |
The End.