This week's book giveaway is in the Python forum.
We're giving away four copies of Python Continuous Integration and Delivery and have Moritz Lenz on-line!
See this thread for details.
Win a copy of Python Continuous Integration and Delivery this week in the Python forum!

Tony Docherty

+ Follow
since Aug 07, 2007
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Tony Docherty

Yes I believe you can do this by extending FileView to create your own FileView class that returns the appropriate icon (from the getIcon() method) or return null to use the default icon. You register your FileView object through the setFileView method in JFileChooser.
6 months ago
Just to add more detail to my suggestion, Here's 2 basic ways of solving this written in plain text.

1. Look at each letter in turn and if it's not in my results list add it to the list and then iterate across the rest of the string to count how many times that letter occurs and write down the total number of occurrences.
2. Look at each letter in turn and if it's not in my results list add it to the list with the number 1 next to it. If it is in the list add 1 to the number next to it.
6 months ago
Your code looks like the sort of code you get when you just start writing code without a real plan - it's far more convoluted and complicated than it needs to be. May I suggest you get a pen and paper and write out in plain text the steps you would take to solve the problem yourself and then look to convert that to code.
6 months ago
In what way are you stuck? Please explain exactly what you want to do and what is actually happening.
7 months ago
Not sure that this will solve your problem but it's generally bad practice to perform long running tasks on the EDT, you should use a worker thread to run the task in the background. If your task is also interacting with the GUI (as yours is) you can use a SwingWorker see this tutorial:

BTW why are you calling message.split() and then not using the returned array anywhere.
8 months ago

Leonardo Nash wrote:
- Is it bad idea to read data from same InputStream using multiple wrapper Streams (BufferedInputStream, DataInputStream, and another subclass of FilteredInputStream) ? If it is, why ?

If you mean chain wrappers together (ie wrap a FileInputStream in a BufferedInputStream which is wrapped in a DataInputStream) then this is fine but if you mean to wrap one InputStream in 2 or more different wrappers then this is not a good idea. The reason is if you read from one wrapper it will consume and return values from the underlying stream then when you read from another wrapper it will consume and return the next available values from the underlying stream and so the second read will be missing the values already read in via the first stream. Unless you are extremely careful you will have no idea what the data being read in actually means as it will be be starting from some unknown point in the stream.

Leonardo Nash wrote:
- Is it bad idea to call reset, mark methods from base InputStream that passed to wrapper InputStream (BufferedInputStream, ...) ? I think, we should call these methods from only wrapper InputStream.

The reset, mark methods from InputStream don't do anything (they are null implementations) so there is no point in calling them. As to the general principal of calling methods in base classes of wrapped classes I would say it is a dangerous policy if the methods change the state of the object. For example if you called an InputStream subclass that implemented reset() and then called the wrapping classes reset() method, if the wrapping class provides it's own implementation of reset and mark, then the result is unlikely to be resetting of the file position back to the marked point.
8 months ago
The problem with not calling flush() in the client code (assuming the android stuff works the same as standard Java) is the client is unlikely to send the string until the connection is being closed (or the buffer fills up) so the server will just sit there waiting for the message from the client.
8 months ago
Sorry I've never programmed for android so I can't give you a definitive answer to that but I would have thought you would have needed to call flush().
8 months ago
Can you show the client code as well please and does it use flush() as well.
8 months ago
Your problem is on line 42

When will this not evaluate to true?
8 months ago

Dave Tolls wrote:Sequence does not hav a no-args constructor, so cannot be serialized at all.

You can serialize it using the alternate approach I described in my earlier post provided there are getters and setters for the fields you need to serialize (or you are willing to use reflection).
9 months ago
Not sure why you are saving the state of the object but if you are trying to provide persistent storage then I would advise against using Serializable. if, on the other hand, you are implementing transient storage then Serializable is an acceptable approach, you do need a no args constructor though to deserialise an object.
An alternative approach to extending the Sequence class would be to create a wrapper class which implements the readObject and writeObject methods as stated in the API docs for Serializable. The wrapper class could then handle serialization and deserialization of the Sequence object's state through these methods.
9 months ago
Are you asking how to run the given class from the command line or are you asking how to call the given code from another class?
9 months ago
Glad to hear the advice was useful.
10 months ago