7,116 Posted Topics
Re: line 4 looks the wrong way round - java syntax is variable = formula; You have formula = variable; | |
Re: Have a look at: [url]http://java.sun.com/docs/books/tutorial/uiswing/components/formattedtextfield.html[/url] | |
Re: PoNoN1=N1+"(POSITIVE)"; You declared PoNoN1 as int, but you probably wanted String. ps: Java convention is the start all variable names with a lower case letter. | |
Re: ps [CODE]if (some boolean expression) { return true; } else { return false; }[/CODE] is just the long way to say [CODE]return (some boolean expression);[/CODE] | |
Re: Probably an unmatched bracket? Re-post with code=java tags and properly indented | |
Re: It's common practice in the Java API to make "utility" methods static, so that makes it OK for me. | |
Re: Forgive me if I have misunderstood here, but it looks to me like you are trying to get an actual Object to put into the array - hence clone and new. Arrays don't hold Objects. Just like variables, they hold [B][I]references [/I][/B](pointers) to Objects. So if you have found a … | |
Re: Sorry guys, but this is a terrible example of programming. We have endles code repeated 9 times because the author dosn't know about arrays. We have if/then/else/else... constructs running on for hundreds and hundreds of lines. We have nearly 1800 lines of code with just one single comment. We have … | |
Re: The whole "enter 1 or 2" thing is part of the UI, so I would put that logic in the UI class. Ie, if the user enters 1, Main should call PoundEuro, if its 2 call the other one (or vice versa?). | |
Re: I wouldn't waste a single millisecond worrying about char/Stringdouble conversion CPU usage. Whatever you do will be a fraction of 1% of the CPU used by the OS doing the socket operations. You don't need to do the conversion to int and back; just send the double in text format … | |
Re: Probably one too many } brackets. Repost code with code=java tags and corect indentation. | |
Re: Since you can't return an error code from a constructor, you could throw an Exception if the parameter(s) are not acceptable: [CODE]class X { public X(int value) throws Exception { if (x<0) throw new Exception("Parameters must not be negative"); ...[/CODE] | |
Re: Write a small test case. If the answer's right across a few different test cases, your code is good! (It looks OK to me.) | |
Re: You declared your rectange & triange classes as "abstract". That means they cannot be instantiated. Becuase these are classes that you want to use to create rectange & triange objects, they should not be declared abstract. | |
Re: Google [I] java read text file[/I] then google [I]System.out.println[/I] | |
Re: [url]http://gafter.blogspot.com/2007/07/internal-versus-external-iterators.html[/url] | |
Re: [QUOTE]So ,it is all about convert the string into char[/QUOTE] Not exactly. charAt is about extracting a particular single char from a String. The chars in a Java String are numbered from 0 to (length of String -1). charAt(n) gives you the char in position n in the String. So … | |
Re: Are you required to use a 2D array? If not, the Java way to do this is to create a class Address, with fields for first name, second name, address. Then you just have a simple 1D array of Address objects. Even better, if you have the choice, would be … | |
Re: nomemory: Problem statement asserts ArrayList may contain non-ArrayList objects. | |
Re: Read the file into an Image, then use the PixelGrabber class to extract the pixels as an array of alpha/r/g/b ints. This gives you the image data after it has been decoded from jpeg/tiff or whatever. | |
Re: Have a look at SimpleDateFormat, it allows you to format dates according to your locale and your own format specification. It works with Date objects, rather than Calendars, so use the getTime() Calendar method to get the correponding Date. | |
Re: [CODE]Employee[] empArr = new Employee[5]; ... for( i = 0; i < empArr.length; i++ ) ... empArr[i].setEid( in.nextInt());[/CODE] You create an array of 5 elements that can be used to hold Employees, but this does not populate the array with actual Employees. So when you try to use empArr[0] there's … | |
Re: whiteyoh: Using an array is dumb. It's fixed size, and you have a variable number of CDs. You should use an ArrayList. I gave you this advice, and sample code yesterday. OK, you don't want my involvement, I'm outta here. Good luck anyway. | |
Re: Its often a good idea in a class like this to create a static Collection that holds all the instances that have been created. This allows you to loop through all the instances counting, totalling value, searching for particular artists etc. Something like [CODE]private static ArrayList<CD> allCDs = new ArrayList … | |
Re: Hi quuba: I went thru all this with him less than an hour ago - see topic "counting objects and totalling their values". He marked it solved, then asked exactly the same question. Good luck! | |
Re: toArray [B][I]does [/I][/B]work. There's something wrong with how you are trying to use it. Post your code. | |
Re: Like it says right at the top: [I]Do not use Stock.setLayout() use Stock.getContentPane().setLayout() instead[/I] and... [I]at Stock.<init>(Stock.java:50)[/I] | |
Re: I can't see where you add your fields to secondRow. One small point: when you catch an IOException you just exit. This will leave you with no information about what went wrong or where. You should do a printStackTrace for the exception before exiting so you know what happened. | |
Re: [QUOTE=masijade;1003243]... "\n" is platform specific and is not always guaranteed to get the effect you wanted.[/QUOTE] Just in case this matters: you can use [CODE]System.getProperty("line.separator");[/CODE] to get the line separator string appropriate to the current platform. | |
![]() | Re: [QUOTE]I keep getting some errors[/QUOTE] We need more information than this. [B][B]Exactly [/B][/B]what errors? |
![]() | Re: Have a look at JFormattedTextField in the API, if I understand your requirement properly, this may be the answer. ![]() |
Re: JAEquation = JAEq.getText(); JBEquation = JAEq.getText(); Is this second line a mis-type? (ditto for KAEquation = KAEq.getText(); KBEquation = KAEq.getText(); ) | |
Re: You can inherit from a single parent downwards as far as you want... A extends Object; B extends A; C extends B; etc Thus, by implication, C extends B, A, and Object. What you can't do is this: E extends F,G ie. extend from two parents at the same level. … | |
Re: [url]http://www.javapractices.com/topic/TopicAction.do?Id=82[/url] | |
Re: You can pass a reference to the main class into the constructors of the other classes, so that they can then call getter methods in the main class. Sharing the Strings themselves may be a bad idea - what happens when one of these values changes? Much better to use … | |
Re: No way will I try to plough thru your unindented listing without CODE=JAVA tags. However, from your problem description, you should be using a ThreadPool [url]http://java.sun.com/docs/books/tutorial/essential/concurrency/pools.html[/url] | |
Re: Simply: don't create a user interface. Your problem with keylogging will be getting at keyboard events when your app (which has no UI) doesn't have the keyboard focus. | |
| |
Re: ... and your question is? | |
Re: This works for me: [CODE=JAVA]qTree = new JTree(....); qPane = new JScrollPane(qTree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); contentPane.add(qPane...);[/CODE] | |
Re: Replace button.setText(some string) with button.setIcon(some icon) | |
Re: [CODE]class DatabaseObject extends javax.swing.JPanel [/CODE] This rings all kinds of alarm bells! The normal way of doing things is to have a "database object" that encapsulates the data items and provides accessors, as well as methods for saving/retrieving them (possibly delageted). You then have a GUI object that takes a … | |
Re: [QUOTE]I think I run into problems with words like "dichlorodiphenyltrichloroethane". It's the longest word I have, with 31 letters. So it has 2, 147, 483, 648 combinations by itself.[/QUOTE] This suggests that you should not be creating an array with all the combinations if you don't have to; and you … | |
Re: Of the various options proposed so far, the best to start with is quuba's to override the inherited toString() method in your class. As well as allowing you to simply say System.out.println(a); and get the expected rseult, this will also work if, for example, you want to display the value … | |
Re: This is why accessor methods are such a good idea. Your String should only be modifiable via a public set(...) method. That method can then take care of any side efects that are necessary. The "standard" Java approach is to use a Listener / Observer pattern; in this case the … | |
Re: Investigate and learn about the following: Loops, in particular loops that increment an integer variable The String class, in particular the charAt method Printing to System.out Give it a try, and when you get stuck come back here. | |
Re: array_of_rooms.room_status[i] = 0; should be array_of_rooms[i].room_status = 0; ie you index the array of rooms, not the status, which is not an array! | |
Re: [url]http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html#listeners[/url] | |
Re: Have a look at Thread Pools [url]http://java.sun.com/docs/books/tutorial/essential/concurrency/pools.html[/url] |
The End.