7,116 Posted Topics
Re: You declare [I]int Value[][/I] so [I] value[b][/I] on line 134 represents an int. ints (like booleans and floats) are "primitives", not Objects, so they do not have methods. That's why your code [I] Value[b].equals...[/I] gives an error - yuo try to call the equals(..) method on a primitive that does … | |
Re: Assuming this error is around line 88 (and next time please post the line number with the error messages!) you define a 3-dimensional array,, but try to initialise it with data in the form of a 2-dimensional array. So when it looks inside the 2d array it expects to find … | |
Re: [QUOTE=Shubham266;1631548]you hv to take container class refernce like contaner c; // before constructor then c=getContentPane(); //in the starting of constructor c.add(start); /*after the buttons setbounds c.add(controls); c.add(credit);[/QUOTE] This code is obsolete. The need to add things to the content pane, rather than just the JFrame, was an annoyance in early … | |
Re: Google [I]java 1.5 whats new?[/I] and this is the very first hit: [url]http://download.oracle.com/javase/1,5.0/docs/relnotes/features.html[/url] | |
Re: Java has primitives, like int boolean float etc, and classes like Integer Boolean Float etc. You use the primitive when you just want a value, and the class when you want to use its more interesting methods. Before Java 1.5 you had to convert between the two explicitly, but now … | |
Re: By line 52 you have variables containing the id, name, category and price. At line 18 you have a constructor that takes id, name, category and price and creates a Products instance. So all you need to do is call the constructor passing the values.. easy peasy! ps: Each instance … | |
Re: When you subclass Tile you re-declare variables private Image tileImage; private boolean tilePassable; private int x,y; in each subclass. Now you have two versions of each variable, the subclass ones "hide" the inherited ones and you end up having to duplicate inherited methods to word with the duplicated variables. Simple … | |
Re: If I understand the question then, no. It's nothing to do with what language. If you put a new character into a file then either it overwrites an existing char or you have to move the rest up to make space for it. | |
Re: print(anyObject) automatically calls anyObject.toString() to get a printable version. All objects inherit a version from the class Object, which shows the class name and a hex reference for the particular instance, eg "Deck@6612fc02". You can override toString in your own classes to print something more useful. You did this for … | |
Re: You define a whole load of menu items on lines 16-48, but in your follwing code instead of using those items you create new local variables (lines 61-66 etc), so whatever you do with those local variables has no effect on the instance variables that defined earlier. In particular, the … | |
Re: Two ways: 1: Do some arithmetic using i and j the first row is 1,2,3,4 The second is 5,6,7,8 which is also 4+1, 4+2, 4+3, 4+4 The third is ... 8+1, 8+2 etc see the pattern? 2: you have a nested loop that you can use to access all the … | |
Re: Most people have absolutely no idea just how much optimisation is applied to code after it enters the compiler and before the actual hardware memory locations in the runtime system get updated, so trying to double-guess the impact of a small code change is probably futile (but the answer will … | |
Re: If you don't get 3 better contributions, feel free to use this. You should be able to run it. I wrote it as a quick check for how CPU usage scaled with number of sprites. I removed the comments as requested, but feel free to ask questions. J ps: It … | |
Re: You can subclass JToolTip to create a custom appearance etc, then subclass the control in question to override its public JToolTip createToolTip() method (inherited from JComponent) to return an instance of your customised JToolTip subclass. | |
Re: Cross posted [url]http://letshare.it/blog/sound-equaliser.html[/url] | |
Re: The constructor defines its parameters as a String and two ints. When you call it you pass three Strings. "1" is a String, 1 is an int. ps Next time, please post the exact error message that you get. It makes our lives a LOT easier! | |
Re: Basically you can't create a new variable name for each Person object like that. That's where the collection comes in. You need a collection of Person objects. At your stage it may be better to stick with a simple array of Persons to hold your collection; you can learn about … | |
Re: Yes, it's possible to set the exact pixel position and size of every component in your GUI, but that's not a recommended solution. Java has a choice of layout managers to help you position and size your components so that they still look right even if the system font changes, … | |
Re: That's an "enhanced for-each loop" - a new feature in Java 1.5 It uses and array or any other collection (eg List) of things, and iterates thru them one at a time. In your case closest is an array of "P" objects, and the for loop is read as [CODE]for … | |
Re: In checkCourse you continue to loop and re-set "matched" after finding a match, so it will only return true if the string matches the very last element in the array. You need to exit the loop as soon as you find a match. Assuming courseObjects[] is some kind of variable, … | |
Re: Are you sure it didn't open it? It looks like your button handler creates a new MyForm and makes it visible exactly like you do in main(...) - so the new MyForm will be identical to the existing one and sit exactly on top of it, so it looks like … | |
Re: This is a duplicate of "help with me object and methods" thread. Maybe a mod. can shut it down? | |
Re: Check the API reference. A JToggleButton is "An implementation of a two-state button. The JRadioButton and JCheckBox classes are subclasses of this class" A JButton is "An implementation of a "push" button." | |
Re: Which CharStack class would that be? | |
Re: some observations: saveStudent 4: the "true" in the FOS specifies append mode, so that's why the file keeps growing. saveStudent 5: what's arrayStudent and why do you use it? Exception (non) handling. You seem determined to ignore IOExceptions. This is always a mistake. Catch them, and printStackTrace() the exception so … | |
Re: IMHO the official Java tutorials from Sun/Oracle are hard to beat. [url]http://download.oracle.com/javase/tutorial/uiswing/index.html[/url] There are other learning resources listed in the pinned topic at the head of the main forum page. | |
Re: You'll need a loop, executed (length of string)/5 times You can use the substring method in the String class to pick out 5 chars starting from an arbitrary start point... Try doing this once by hand on a piece of paper to understand the exact sequence of steps, then convert … | |
Re: [QUOTE=abhinavM;1627027]I want to create a new variable with each run of this while loop ... like str1(for 1st run),str2(for 2nd run) and so on [/QUOTE] Short answer: you can't create new variables names like that at runtime. That's what arrays are for - str[1]. str[2] etc. Why do you think … | |
Re: In your original code insert a print statement immediately after line 88 (in.read) to print the value of ch. Then you will be able to see exactly what's happening. | |
Re: I don't see anything fundamentally wrong with your current approach.I've used it myself more than once. It's just a bit fiddly getting the network setting right. Assuming your server is on a LAN sitting behind a NAT router: Open a firewall exception on the server PC to allow incoming connections … | |
Re: things like dir are commands processed by cmd.exe - the windows command processor. You can explicitly run one of cmd's commands with the /C option, eg cmd.exe /C dir and you can use processbuilder to create a suitable process as in Process p = new ProcessBuilder("cmd.exe", "/C", "dir") | |
Re: You are OK about instance & class vars, instance variable are one per object created, class vars are one shared between all objects of that class. but the static keyword defines a class var. It's an instance var if it does NOT have the static keyword. | |
Re: I can't speak about the C++ side, but Java TCP/IP is just plain old vanilla TCP/IP. I've had no problems using it to communicate with TCP/IP-based embedded systems that certainly are not Java. | |
Re: What OS are you using? Under Windows that should be [B]echo %PATH%[/B] ps: Have a look at the ProcessBuilder class in Java 1.5 and later - it's intended as a better replacement for Runtime.getRuntime().exec() | |
Re: Firstly, "run anyway" is a waste of time - if there are compiler errors then you need to fix those before attempting to run anything. Secondly, if you comment out lines of code from your algorithm then of course it won't work. Thirdly, make sure every catch block has an … | |
Re: JavaDB is the SQL database packaged with JDK 1.6 and 1.7 It's the same database engine as Derby, but slightly differently packaged. You do [B]not [/B]need to download any part of Derby to use JavaDB under 1.6 or later; tt is automatically included and installed as part of the JDK. … | |
Re: Have a look at ByteArrayOutputStream. It's an OutputStream that writes the data directly to an in-memory self-expanding byte array, from which you can access the bytes directly. | |
Re: A JFrame consists of a Content Pane surrounded by borders etc and, as you have observed, its size includes the (system-dependent) borders. To achieve your desired result, set the (preferred) size of the JFrame's Content Pane (access it via myFrame.getContentPane()) rather than the JFrame itself. | |
Re: Override paintComponent, not paint. This restricts your (re)paint to the client area only. Do not override repaint, just call it when necessary. Do not call super.paintComponent in your paintComponent, because that's where the old content is being cleared. Just go ahead and paint the new stuff. For more details see … | |
Re: Didn't read all yuor code, but you cant do an implicit multiply with brackets, eg a(b+c) in Java. In Java that looks like a call to method a with parameter value b+c. You have to use an explicit multiply operator, a*(b+c) ![]() | |
Re: Its for advanced debugging/tuning. You probably will never need it. [url]http://www.java-tips.org/java-se-tips/java.lang/how-to-use-verbose-option-while-running-a-java-applic.html[/url] | |
Re: Short version: Storing passwords in plain text, regardless of database vs file etc is a no-no; it's just too vulnerable to exposure. A normal practice is to create the password, get its MD5 digest (easy in Java, just Google it) and store that instead. When the user next enters a … | |
Re: [QUOTE=Ezzaral;1622193]You could extend JLabel to maintain a reference to the object, in which case the listener could retrieve it directly from the clicked label...[/QUOTE] This would be the obvious strategy, but there's no need to extend JLabel to achieve it. Every swing component has a "client property" map where you … | |
Re: Suggest you have a look at the source code for ArrayList. My guess is that it allocates an array of some default size and adds elements until that's full, at which point it copies the existing data to a new larger array then releases the old one - thus giving … | |
Re: A statement like that needs to be inside a method (eg the constructor)* * yes,there are other places, but they're not in the Java 101 syllabus. | |
Re: Do you mean that you want to animate the display of the numbers so they slide down out of sight and the next number slides down from the top? If so, you need to override paintComponent for the text fields and draw the text at an x,y position where the … | |
Re: Stop thinking about 2d arrays. Java arrays are one-dimensional. It's just that the data type for a java array can itself be an array, so you can nest arrays within arrays (etc). It just so happens that a java array whose elements are arrays all of the same length looks … | |
Re: Hi, JC here again. Could you be referring to my prior post? If so. thank you. In real life people use complex tools (UML modelling) to do this kind of thing, but for starters I would recommend keeping it simple and low-tech. I've used this technique many many times when … | |
Re: I looked at your final version. Of course it won't compile, so can't be the code you actually ran. (That doesn't help diagnose you know, when the code you post isn't the code you had a problem with). Anyway, I fixed the missing semicolons and the static method references to … | |
Re: Standard OO procedure: Go through the spec underlining all the important nouns to get possible classes, eg [U]Menu [/U] 1. Register a [U]customer[/U] 2. 3. park [U]car[/U] Register a [U]vehical [/U]for a customer 3. Issue a [U]pass [/U]for the customer Some will turn out to be unnecessary, and some will … |
The End.