7,116 Posted Topics
Re: * is a meta-char in a regex (matches 0 or more repetitions). To use it literally you must precede it with a backslash. To use a backslash as a literal in a Java String literal you need to enter 2 backslashes. So you regex should be "\\*.txt". (Probabaly, I didn't … | |
Re: [QUOTE]I get alot of errors[/QUOTE] What errors exactly, at what line(s). | |
Re: Yes (There are cleverer ways of structuring it, epecially when the number of dice is variable, but they still all come dowm to n nested loops). | |
Re: Are grades really just a Double precision number - ie (a) why Double - how precise are they? and (b) don't you care what the subject was, when the grade was awarded etc? If there is more to it than just a vastly-precise number, then maybe a Grade class that … ![]() | |
Re: Not sure exactly what you mean by "add flash content", but the DJ Project includes a Swing flash player component that you can embed in your app. [url]http://djproject.sourceforge.net/ns/index.html[/url] | |
Re: The SwingWorker class [url]http://download.oracle.com/javase/tutorial/uiswing/concurrency/worker.html[/url] is designed to run long tasks in the background and to report back to the caller when finished [I]"SwingWorker implements java.util.concurrent.Future. This interface allows the background task to provide a return value to the other thread. Other methods in this interface allow cancellation of the background … | |
Re: [QUOTE]don't expect quick solutions to your homework. We'll help you get started and exchange algorithm ideas, but only if you show that you're willing to put in effort as well.[/QUOTE] I guess you missed this at the top of the forum main page? | |
Re: This is a good explanation: [url]http://download.oracle.com/javase/tutorial/java/javaOO/nested.html[/url] This is a good example of one use for static classes: [url]http://www.javaworld.com/javaworld/javatips/jw-javatip106.html[/url] | |
Re: Beware the array "solution". It can be made to work, but its as un-Java as you can imagine. Youcan stuff anything into an array of Objects, but then you have to do unchecked casts to get them back and use them. There's no opportunity to hide the data behind a … | |
Re: I guess you missed this on the main forum page: [QUOTE]don't expect quick solutions to your homework. We'll help you get started and exchange algorithm ideas, but only if you show that you're willing to put in effort as well[/QUOTE] | |
Re: Small point: although both forms are legal, most Java coding standards prefer [CODE]int[] numArray[/CODE] rather than [CODE]int numArray[][/CODE] the logic being that its an array of ints, not an array of numArrays | |
Re: It has two possible values: [B]true [/B]and [B]false[/B]. What exactly do you want to know? eg: If I add a single boolean variable to my class how much bigger is each instance I create? or If I write a single boolean to a file how big is the file? or … | |
Re: Looking at your code there seems to be an asymmetry between the encode and the decode. The encode stores an 8 bit value from an int into the red pixel. There's no messing about with individual bits. The decode gets an 8 bit value from the red pixel, but then … | |
Re: It's very unlikely to be a problem with IE. It's almost certainly your code and/or the way you deployed it. Without the code and the exact error message there's nothing anyone here can do to diagnose it. | |
Re: Absolutely yes. Read the values from the file (depends on how the file is formatted, but you know that already) and put them into the text fields. After that it's exactly the same as the program you've already got - ie user changes the values in the text fields and … | |
Re: Where do you push into the stack? Exactly what "error"s do you get? | |
Re: You can use Regex "lookarounds" to split at the <> delimiters while retaining the delimiters. For example: [CODE]String s = "<A><B>cde</B></A"; String[] a = s.split("(?=[<>])");[/CODE] gives the following array elements [CODE]<A > <B >cde </B > </A[/CODE] Which is 90% of the way there (ie you have <tag, </tag, or … | |
Re: I want to suggest a different answer - I really don't like the repeated logical expression, and overall I don't think its any easier to understand. IMHO a major reason why it's hard to understand is the silly choice of variable name, and the use of the EOF code value … | |
Re: Where is the { to match the } on line 9? Presumably its before line 1 somewhere, in which case the declaration of m in line 1 will go out of scope on line 9, which means there is no "m" defined at line 10. | |
Re: Norm is right - that's a C-based language, probably just raw C. ciali: You have posted this in the worng forum - this one is for Java | |
Re: You can use the Runtime and Process classes in Java 6. You will find tutorials and code on the web. | |
Re: 1. THis is an old thread, July 5th - 7th. 2. Most of the thread is a discussion about why you should not post solutions to other people's homework. So why did you post a solution? It's not even a good example of Java code. | |
Re: You can find the answers to many of these questions if you use Google and a bit of intelligent work. But here's the answer to two that are not so easy to find... System.out is the Java console, which is the window where you ran the program if you're using … | |
Re: No, it's not the only way, but it's the way that people use 99% of the time. You will find some excellent tutorials on the web for using Java with a database. I recommend this one: [url]http://download.oracle.com/javase/tutorial/jdbc/index.html[/url] It's quite a lot to understand and learn, but its an essential basic … | |
Re: Static methods can access staic members of the same class, or instance members via an instance of the class. Instance methods can access static members of the class, instance members of the same instance, or instance members of another instance via that instance. Where "member" is a variable or a … | |
Re: "its doesn't work as it should" gives us absolutely nothing to work with! How/why/where doesn't it "work"? Put more System.out.println statements at strategic points in your code so you can see exactly what is being executed and what isn't, and what values the variables have. | |
Re: do you mean something like: [CODE]public int askUserForChoice() { // do all the stuff with the dialog box as above return choice; } ... int chosenOption = askUserForChoice(); switch (chosenOption); // etc[/CODE] | |
Re: [QUOTE]Check your XML to make sure it is correct. The markup in the document following the root element must be well-formed.[/QUOTE] Did you? | |
Re: I assume your Google and Wikipedia are both broken at the moment? If you tell me what search you would like done I can Google it for you and post the results back here. | |
Re: If you absolutely must use a switch then you can code this with 26 cases each for upper & lower case chars: case 'a': case 'b': ... case 'z': // convert to upper case; break; case 'A': case 'B': ... case 'Z': // convert to lowercase; break; | |
Re: Yo nick, norm is right. the O/P needs tough love; teach him, don't just fix this one problem. | |
Re: Sorry Norm, it looks OK to me. There is a constructor that takes an Image, and ImageIcon is appropriate. | |
Re: When the user clicks the button you call init() (with a flag set), which always creates a new window from scratch. Rather than keep on adding & removing buttons, why not add panop2, but set its visibility to false. Then in the button handler you just have to make panop2 … | |
Re: this [url]http://download.oracle.com/javase/tutorial/uiswing/components/icon.html[/url] explains how to do it. | |
I have a problem involving Generics. Here's a simplified version: Suppose I have a generic method to add a new element to a (possibly empty) ArrayList, like this: [CODE]<T> void addNewTo(ArrayList<T> list)[/CODE] What I need to do is to determine the correct class for the ArrayList elements so as to … | |
Re: Both classes need to be in the same package, OR you have to import class A at the start of B.java | |
Re: Sounds like you should use a Collection (eg ArrayList) of textfields. OR maybe a HashMap to link the textfields to the corresponding "stuffs". Either way, these classes are more flexible and easier to work with than arrays. | |
![]() | Re: If you ensure that you have no remaining references to the "old" data, then it will definitely be garbage collected before the JVM runs out of memory and throws an "out of memory". (In a complex program it's all too easy to leave an object in a List somewhere which … ![]() |
Re: If a variable is null, you can't test its length - it hasn't got a length!. Use var == null | |
Re: [QUOTE]StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead.[/QUOTE] Source: JDK 6 API [url]http://download.oracle.com/javase/6/docs/api/java/util/StringTokenizer.html[/url] String's split method will return what you … | |
Re: The reason for this is that when you instantiate a subclass its constructor automatically calls the constructor(s) of it superclasses, so all the variables etc associated with the superclasses are initialised properly. However, when you instantiate the superclass none of the subclass contructors are called, so none of the subclasses … | |
Re: JButtons, kike all JComponents have a really useful but much neglected property called "clientProperty", which is a hashtable into which you can put whatever key/vlaue pairs you want with putClientProperty(key, value), and retrieve the values with getClientProperty(key). Depending on how your buttons are supposed to behave you can use this … | |
Re: Specifying a full path guarantees that your app won't run on another machine, and using the class path won't work if multiple users are running the same app. Much better to use [CODE]System.getProperty("user.home")[/CODE] to get a reference to the user's home directory, and put the file there, eg [CODE]new File(System.getProperty("user.home") … | |
Re: Why are you getting the values from System.in when you have an InputDialog? JOptionPane.showInputDialog returns a String (the user's input), but you are ignoring it. | |
Re: 1/2 If they are all on the same subnet youy may be able to use UDP broadcasts, otherwize you will need a shared server of some sort. | |
Re: It just creates a File object that refers to the file with that path & name, but it doesn't actually do anything with it (not even check if the file exists!). You can then call methods on that File object to test if it exists, open it and read it … | |
Re: ^ like he said. But remember that the map actually contains references to the key and value objects, not the objects themselves, so even if your key or value objects are enormous, you can still create a hashmap with millions of references to them. In practice you will nromally run … | |
Re: [QUOTE]Recompile with -Xlint:deprecation for details. [/QUOTE] did you? | |
Re: HashMap (look it up in the API). Add the 3 letter codes as keys and the 1 letter codes as values. HashMap then does the lookup for you, value = map.get(key). |
The End.