7,116 Posted Topics
Re: [QUOTE=hiddepolen;1686962]There is no 'printf()' in Java.[/QUOTE] Sorry, but yes there is. It was added in Java 1.5 This is from the API doc for PrintStream: [QUOTE]public PrintStream printf(String format, Object... args) A convenience method to write a formatted string to this output stream using the specified format string and arguments. … | |
Re: A Vector is like an array, except that it starts out with size 0, and grows to fit the data you put into it - you just keep using its add method. You can also have a Vector whose elements are also Vectors - like a 2 D array. JTable … | |
Re: Not that I know of - I think you just have to get down & dirty with MouseListener, MouseWheelListener, and MouseMotionListener | |
Re: You can't have a . in a name. Lab4.24 is not a valid name in Java. You could use Lab4_24 if you wanted. | |
Re: I guess you're going to have a window in which the image is displayed. You'll need a MouseMotionListener to generate MouseEvents when the mouse is moved in the window, and you'll need some data (a tag) that links a person to a rectangular area (top left and bottom right coordinates) … | |
Re: Which you use depends on whether you are processing raw bytes of data or lines of text. Efficiency won't be a deciding issue in any case, provided that use have Buffered stream of some kind. | |
Re: You probably need to keep the input number in its original string format so you can parse it according to the base/radix. Then you just need two methods double parse(String input, int base) String format(double value, int base) and you can convert from any base to any other base. ps … | |
Re: [I]Exactly [/I]what error do you get from which statement? | |
Re: The important point here is that you don't need to know the answer to that question! The author of those classes defined an interface or abstract class that defines everything you need to know. Behind the scenes he can them implement it any way he wants, and maybe change it … | |
Re: RequestDispature red = request.getRequestDispature("xyz"); What happens here is that the getRequestDispature method is called on the object request. Somewhere in that method it obtains an instance of some class that implements RequestDispature. Nothing in that line of code tells you what class is or how it gets it, all you … | |
Re: You loop through all the files in drive[]. When you hit the right one you set value = i, which is the index you want. But then you continue through the rest of the array, and set value = -1 overwriting the value you wanted (unless the one you wanted … | |
Re: Start here: [url]http://www.daniweb.com/software-development/java/threads/99132[/url] | |
Re: That's right. static methods belong to the class, not to an instance, so you call them using the class, eg Account.consolidate(etc), not account4.consolidate(etc). consolidate returns the new account, so you need to assign that returned value to an instance, eg Account consolidatedAccount = Account.consolidate(acc1, acc2); Your current code compiles because … | |
Re: Java 1.7 hasn't broken anything from 1.6, so code for 1.6 and it will run on both. When you create a thread you supply a run() method. Normally you call Thread's start() method which starts a new thread and calls run() on that thread. There's nothing to stop you calling … | |
Re: In java you can only return one thing from a method. You can't return two arrays (unless you package both those arrays inside a single object and return that, which is probably a bit excessive for this case). However, when someone passes an array into a method as a parameter, … | |
Re: new Portfolio[9] Creates an array of 9 [B][I]references [/I][/B]to instances of class Portfolio. Initially all those references are null. That's why you get a Null Pointer Exception if you try to use them. In theory the compiler could identify at least some of the cases where that could happen, but … | |
Re: When you handle a GUI event in Java there is an Event object passed to your handler. The event object has a getSource() method that returns the object that generated the event. Eg in an Action listener (responds to button presses and the like) you provide a handler method with … | |
Re: The continue statement skips the current iteration of a for, while , or do-while loop. Since yu don't have any of those, it's not a valid use of continue. Look at the second part of this tutorial [url]http://download.oracle.com/javase/tutorial/java/nutsandbolts/branch.html[/url] | |
Re: When you have a problem, please give us a complete description of it - full text of any error messages, or an exact description of what's wrong with the output. Anyway... this is a GUI program, and on line 31 you get monthNumber from the field in your GUI - … | |
Re: [QUOTE=cloris;1685167]... i get the codes but they do not attach the codes to call the class, and also the codes do not allow user input...[/QUOTE] That's normal. The code for the algorithm will be similar no matter how you use it, but how you get the input values etc will … | |
Re: IOException: Cannot run program "java -jar C:\Users\Jack\testFile.jar\" That final \ on the filename looks wrong to me. Very wrong. | |
Re: In ChessSet pubic void paint (Graphic g) should be public void paintComponent (Graphic g) // this will be called by Swing autimatically inside that method you need to access some kind of list of all the ChessPieces on the board and loop through the list calling their paint methods (because … | |
Re: Java will look for your class in the folders and file com\toedter\calendar\JDateChooser.class it will start this search from every directory in your CLASSPATH. So you need to make sure you have those directories and that file in one of the CLASSPATH locations. If you have a .jar file, java treats … | |
Re: Maybe this could be as simple as working with a few known classes that implement Shape (Rectangle, RoundRectangle2D, Ellipse2D, Polygon...), then randomly picking one of those shapes and randomly setting its parameters? | |
Re: Given the requirements, what you are doing is not bad. Obviously there are a number of little tweaks and tunings that could be done (eg there's no need to convert your chars to ints), but nothing fundamental. Some proper testing will flush out any actual mistakes. You're on the right … | |
Re: The whole point of compareTo is that it compares your object with the one passed as a parameter, and tells you which is "lower" or "higher" or "the same" (those terms depend on what the data is, and how you chose to sort it). Simply returning a value from one … | |
Re: The 4.5 at the end of the array means it's not sorted that can't help... | |
Re: The error message says you cannot cast a JButton to a JComboBox at line 185. It's hard to imagine how that could be any clearer. Line 185 says if (combo1 == (JComboBox)e.getSource()); so if the event was triggered from a JButton that cast will fail. Fortunately you don't need the … | |
Re: Every Java program must have a "main" method that looks like this: [CODE]public static void main(String[] args) { // your startup code goes here }[/CODE] (similar but different standard methods are required to start an applet) When you try to run your program Java looks for that method and calls … ![]() | |
Re: Create a File object from the string, then use its getName() method. (Plus, this works for Linux too!). | |
Re: Please mark this thread "solved" so nobody else wastes time reading through it only to find at the end it's solved anyway ![]() | |
Re: You will have to re-scale your image to to the size you want it to be. You can use the getScaledInstance method on your Image to create a smaller version that will fit your JFrame. | |
Re: You have public class Triangle { and public class Triangle implements Measurable but you can't have 2 classes with the same name in the same file ps Next time please post your code correctly indented and between CODE tags so we can read it properly. | |
Re: What part of it do you need help with... how to respond to a menu selection? how to open a new form? something else...? | |
Re: You don't an array for this program - the fact that it's there says that you are right to be learning more about recursion ;-) Assuming that n is a positive odd integer, the recursive algorithm's pseudocode will look something simple like this: [CODE]method sumOdd(n) if n==1 return 1 (n<=1 … | |
Re: This has a lot in common with your very recent thread [url]http://www.daniweb.com/software-development/java/threads/390417[/url] It depends on whether the possible text/methods are known at compile time or not. If they are known then just use a switch (Java 7) to call the appropriate method depending on the text. There is an elegant … | |
Re: Small confusion about index1 and index2 here. AFAIKS you don't need 3 indexes, ie L3[i] = L1[i]*l2[i] ... but if you do then you should be incrementing them all, not just index3. | |
Re: At the four places where you construct the question you can also calculate the correct answer, and save it in a variable so you can check the user's answer against that value when they press "submit". | |
Re: Just the tinyest clue about your code would help reduce the number of possible causes to a finite number. If you are using the standard file open dialog then it's just a bug in your following code. If you are entering the file path/name as a string then it's probably … | |
Re: The code you posted is for a class called StockTesting. Is there a class called Stock? Where is the code for that class? ps Please post code in CODE tags, it's completely unreadable without them. | |
Re: Quick answer: call textfield2.requestFocusInWindow(); Proper answer: read this tutorial to understand how Swing manages moving the focus, and how you can control it: [url]http://download.oracle.com/javase/tutorial/uiswing/misc/focus.html[/url] | |
Re: This approach to keyboard handling is always a complete pain in the * because of precisely those focus issues. Swing was enhanced back in Java 1.3 to provide a better way of doing things via two new classes: InputMap and ActionMap. Here's a good write-up on the theory behind it: … | |
Re: The goto has been known to create unreadable undebuggable "spaghetti" code since the 1960's (The seminal "goto considered harmful" paper of Edsger W. Dijkstra was written in 1968). It was a simple decision (and 100% correct IMHO) that Java would not have one. Not then, not now, not ever. Sun's … ![]() | |
| |
Re: Do you have a pack(); somewhere in your code. Do you call pack(); after adding the new panel? | |
Re: You can do access things like method or variable (reflection refers to variables as "Fields") names using the Reflection classes in java.lang.reflect eg the Field class has a getName() that returns the name of the field. Start with the Class class - that's where you get the Fields and Methods … | |
Re: That doesn't allocate any memory for ObjectL objects - it allocates memory for an array of [ICODE]int a[/ICODE] references (pointers) to possible ObjectL objects. To allocate memory for the objects themselves you need to execute [ICODE]new ObjectL(...);[/ICODE] where ... is zero or more parameters as required by ObjectL's constructor(s). Because … | |
Re: 1. Don't just give people answers to their homework - that's called "cheating", and doesn't help them learn. 2. That post was from October 2010 - your reply is a year too late! 3. Always post any code in CODE tags. | |
Re: And I want my car to warm up automatically 10 minutes before I want to use it in winter. Rather than just posting your demand here, you could have Googled - well, let me think... what would be a good search... oh! I know, how about [B]Auto Increase size of … | |
Re: die1Value = die2Value == 1 You can't string together == tests like that, the = just copes the value on its RHS to the variable on its left. You need something like die1Value == 1 && die2Value == 1 |
The End.