7,116 Posted Topics
Re: getActionCommand returns a String - the name of the command. You try to assign that to actionevent - a parameter whose type is ActionEvent, and you can't assign a String to an ActionEvent. You probably want to define a new String here, as in String actionEventName = actionevent.getActionCommand(); then use … | |
Re: That's because nowhere in that code do you define args. Do you have a main method with args as its parameter? That version of artgs is only available inside main. You'll need to copy them to somewhere else to use them in other methods. | |
Re: What errors exactly - if there's a message please quote it in full - if its a wrong result tell us what the actual and expected results are. | |
Re: Just take it one step at a time Pick a button. What does it do? Which method in Calculator does that correspond to? Now code a call to that method inside an if test in actionPerformed for that particular button. Pick another button (etc etc) | |
Re: You define: Scanner input = new Scanner(System.in); You use this to read input from the user: guess = input.nextInt(); But then for the next input you have: answer = scan.next(); It looks like you have forgotten that the scanner is called "input" and have mistakenly typed (or copied?) the name … | |
Re: A proper answer could take one or more complete books, so this is just a snippet: [QUOTE]in a C style and used classes to make a new data type [/QUOTE] In java you use classes to provide services - data is usually hidden inside the class, and the public interface … | |
Re: It's easy. Just highlight all your code (click once before the fist line, hold down the shift key while clicking once after the last line) and click where it says CODE in square brackets at the top of the message box. Try it! | |
| |
Re: Do you mean cannot find symbol, method [I][B]next[/B][/I]Char()? If so, check out the API for Scanner - there is no nextChar() method in Scanner (there also isn't a Char() method either) A char is a single character, and I guess your department names are longer than 1 char, so you … | |
Re: Re-read kvass's post. It contains exactly the info you need, and gives you exactly the instructions you need. | |
Re: Are you referring to the fact that Console input does not work in Eclipse (or other industrial-grade IDE's)? If so, you can use a reader on System.in like this: [CODE] try { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Type name: "); String name = reader.readLine(); System.out.println("Hello " + name); } … | |
Re: You try to define isBoolean [B][I]inside [/I][/B]the main(...) method - probably because you are missing a } to close the definition of main. However, unless you correct the indentation, it's hard to see clearly. | |
Re: 19. Because the user of this class doesn't need to know about it, and if they did get access to it they would probably screw up the list. 28. When the return statement is executed 32. This stops execution of the method immediately and returns to the wherever the method … | |
Re: siand s2 are not objects, they are [B][I]reference variables[/I][/B] - like a pointer - that can hold references to a StringTokenizer object. StringTokenizer st1,st2; declares two reference variables, both [I]null [/I]at this stage. new StringTokenizer(quote1) creates an Object of class StringTokenizer - this is where the meory for that object … | |
Re: No, one is push(int) the other is push (float), unlike your pops which are both pop(). Check Serena5's post again, it's the answer you needed. | |
Re: Seems odd. Have you tried printing the array values after the update to confirm that they really are what you expect? | |
Re: What kind of crap exactly? Code looks sensible to me | |
Re: Stuff in red seems unnecessary. In the print you can use the number to get the corresponding name and print that out as well. ps: Make sure your code is properly indented, and use CODE tags when posting. | |
Re: Looks like the final display screen is deeply buried in the nested if tests when maybe it needs to be after all those - without proper indentation it's hard to tell | |
Re: Normal method is to use a javax.swing.Timer (not java,util.Timer, which is different) to call back after "a few minutes". In the callback you change the shape etc then call repaint() to trigger Swing to call your paint(...) method. ps: It's advised to override paintComponent, rather than paint - you can … | |
Re: [QUOTE]the line 23 @Override should be deleted.[/QUOTE] Why? It's perfectly valid and very useful. [QUOTE]In the class InnerEx7 foo2 (the instance of the class Inner) is created as an instance of Foo's subclass. If the class Inner does not inherit Foo, in the class InnerEx7 there is no way to … | |
Re: You say you are doing something wrong - but what symptoms do you have - a compile error, and exception being thrown, program produces the wrong results etc? Without an exact description of the problem you are unlikely to find the right solution. But in the meantime, where is the … | |
Re: I think these packages are part of JavaEE, so if you have Java SE you need to upgrade. And if you are really still on 1.4.1 you [B][I]desperately [/I][/B]need to update! | |
Re: JavaMail allows you to receive and process mail from a POP or IMAP source. [url]http://java.sun.com/developer/onlineTraining/JavaMail/contents.html[/url] | |
Re: You have to use an if test in some form or another. If you really want to use catch/finally to handle it you can throw a new Exception, as in [CODE]if (somethingIsWrong) throw new Exception("Something went wrong");[/CODE] (although some writers think you shouldn't use exceptions for ordinary user errors) | |
Re: Some suggestions: line 17 - use Integer not Double - no fractions of shirts here! lines 39/40, 44 - these calculations overwrite the values you calculated earlier. If the answer was Yes you need to add some extra discount, and take something off the already-calculated total. | |
Re: line 1: ArrayList planes_array[] = null; line 10: planes_array[i]=null; // since planes_array is null, planes_array[i] is null You need to initialise planes_array on line 1 | |
Re: Is line 2 part of a method? (it should be) the dreaded serialVersionUID is because the API says any Serializable class should declare a version number so that if serialization changes you will know which version was serialised when you try to de-serialise it. Eclipse is just picking up every … | |
Re: Maybe change the Counter methods to return the count rather than just a boolean. Then in your main loop you can just add up those counts. VowelsCounter seems unneccessary, since vowels don't score anything. You code will be easier to read & debug if you indent it properly. Mostcode editors … | |
Re: You create an account a and deposit $1000, and print the balance of $1000. You then create another account c with the default balance of $0, withdraw $500, and print a balance of -$500. What's the problem? It's working perfectly. | |
Re: You inherit the variable "balance" from the Account class, so it's not a good idea to declare a new one in CheckingAccount. Just use the inherited one, as in [CODE] public void setBalance(float Balance) { this.Balance = Balance - transactionFee; }[/CODE] Normally one would expect deposits to be done via … | |
Re: If you are just starting to learn Java don't start with something too hard. Spend a day doing the simplest game possible (eg scissors/paper/rock or Tic-tac-toe) first. You'll have to learn to code the same basic elements (input/some logic/output) that any game needs, and I promise it will save more … ![]() | |
Re: This is possible, but Java is designed to be platform independent, and what you are describing is totally platform-dependent. I'm sorry to say this, but that's a job I would never recommend java for. Why not use one of the various tried and proven installers that are out there - … | |
Re: students is an ArrayList of Student objects, so of course you can't cast them to Strings. the toArray method returns an array of Students in this case. Why are you converting an ArrayList to an array anyway? | |
Re: Thread.getAllStackTraces() returns a map of stack traces for all live threads. You could ignore the stack traces and just look at the keys in that map for a list of all live threads. | |
Re: Line 22 is missing something ;). Just compare it with the other 3 showInputDialog lines and I'm sure you will see it. | |
Re: Java and Swing if you want platform independence, C# and .NET if you want Windows only | |
Re: I think your tests for invalid input should be || not && - ie it's invalid if either criterion is not met. And maybe you should put these tests before the accept/reject tests, so that a gp of 9 and a ts of 200 is shown as invalid rather than … | |
Re: Three questions: How many lines are typically read from yahoo each time? Why do you close the in stream [B]inside [/B]the loop that's trying to read it? Have you used task manager to see what CPU utilisation you are actually getting - what is it in %? | |
Re: You can use anything clickable (JButton, JLabel etc) and respond to the click by opening the URL. Or, if you want clickable links embedded in the text, use a JEditorPane in which you can display HTML and handle hyperlinks via a HyperlinkListener. Have a look at [URL="http://www.coderanch.com/t/345547/GUI/java/Making-clickable-links-HTML-JLabel"]this[/URL] then head on … | |
Re: The normal convention is that a set... method sets a single value, so when you call it repeatedly in your loop you are overwriting the the value you just set. There is only one value to get..., which will be the last one you set. If a bean has an … | |
Re: Please re-post code in code tags so we can read it. | |
Re: I think you have misunderstood the purpose of this forum. We are here to help you do your homework, not to do it for you. | |
Re: Is x an instance variable (ie not static)? If so, every instance of Class1 has its own value for x. You can do whatever you like with x in one instance of Class1, and this will have no effect on the value of x for any other new instance of … | |
Re: Hold on a minute here - tong1 - are you sure you are answering the original requirement here? Wootens: go back to the version in your post that starts "Cheers, it compiles now", that's almost perfect, its just that you increment count OUTSIDE the loop when, obviously, it should be … | |
Re: [QUOTE]For converting a link list to binary tree, I'll have to dig a bit[/QUOTE] It's just like tree to list, ie iterate thru the list and add each element to the tree. [QUOTE]is it useful to remember how to convert a binary to link list?[/QUOTE] You certainly do not have … | |
Re: I guess that's Binary Search Tree, not British Summer Time? Wikipedia has a good intro, Google will find you everything you need. |
The End.