7,116 Posted Topics

Member Avatar for lele07060

[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. …

Member Avatar for JamesCherrill
0
527
Member Avatar for skywire_

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 …

Member Avatar for mKorbel
0
2K
Member Avatar for Erlendftw

Not that I know of - I think you just have to get down & dirty with MouseListener, MouseWheelListener, and MouseMotionListener

Member Avatar for Erlendftw
0
209
Member Avatar for lele07060

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.

Member Avatar for JeffGrigg
0
83
Member Avatar for spades0001

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) …

Member Avatar for JamesCherrill
0
100
Member Avatar for slasherpunk

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.

Member Avatar for JamesCherrill
0
157
Member Avatar for ITHope

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 …

Member Avatar for JeffGrigg
0
115
Member Avatar for asmsycool
Member Avatar for rushi3311

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 …

Member Avatar for JamesCherrill
0
166
Member Avatar for rushi3311

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 …

Member Avatar for JamesCherrill
0
221
Member Avatar for slidepuppy1

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 …

Member Avatar for stultuske
0
168
Member Avatar for pavangajula2007

Start here: [url]http://www.daniweb.com/software-development/java/threads/99132[/url]

Member Avatar for stultuske
0
107
Member Avatar for cdea06

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 …

Member Avatar for JamesCherrill
0
244
Member Avatar for selma_ter

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 …

Member Avatar for JamesCherrill
0
196
Member Avatar for loupgarou

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, …

Member Avatar for JamesCherrill
0
204
Member Avatar for logicmonster

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 …

Member Avatar for JamesCherrill
0
777
Member Avatar for danthevan

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 …

Member Avatar for danthevan
0
273
Member Avatar for sasikrishnasamy

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]

Member Avatar for sasikrishnasamy
0
179
Member Avatar for jhamill

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 - …

Member Avatar for jhamill
0
233
Member Avatar for cloris

[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 …

Member Avatar for JamesCherrill
0
98
Member Avatar for jackmaverick1

IOException: Cannot run program "java -jar C:\Users\Jack\testFile.jar\" That final \ on the filename looks wrong to me. Very wrong.

Member Avatar for hiddepolen
0
247
Member Avatar for ricedragon

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 …

Member Avatar for JamesCherrill
0
639
Member Avatar for dennysimon

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 …

Member Avatar for JamesCherrill
0
274
Member Avatar for lbgladson

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?

Member Avatar for JamesCherrill
0
160
Member Avatar for torkolort

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 …

Member Avatar for JamesCherrill
0
169
Member Avatar for lbgladson

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 …

Member Avatar for lbgladson
0
138
Member Avatar for herstein

The 4.5 at the end of the array means it's not sorted that can't help...

Member Avatar for herstein
0
114
Member Avatar for grako84

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 …

Member Avatar for grako84
0
256
Member Avatar for applejax77

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 …

Member Avatar for hfx642
0
2K
Member Avatar for Jessurider

Create a File object from the string, then use its getName() method. (Plus, this works for Linux too!).

Member Avatar for JamesCherrill
0
102
Member Avatar for ashsailesh

Please mark this thread "solved" so nobody else wastes time reading through it only to find at the end it's solved anyway

Member Avatar for hfx642
0
127
Member Avatar for canarian

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.

Member Avatar for mKorbel
0
620
Member Avatar for Sbing

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.

Member Avatar for Sbing
0
160
Member Avatar for n1_razz11

What part of it do you need help with... how to respond to a menu selection? how to open a new form? something else...?

Member Avatar for JamesCherrill
0
269
Member Avatar for TheComputerGuy

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 …

Member Avatar for JamesCherrill
0
2K
Member Avatar for geekman89

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 …

Member Avatar for JamesCherrill
0
188
Member Avatar for onyx112

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.

Member Avatar for JamesCherrill
0
123
Member Avatar for je5ter461

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".

Member Avatar for je5ter461
0
208
Member Avatar for jackmaverick1

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 …

Member Avatar for jackmaverick1
0
9K
Member Avatar for Ibanez1942

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.

Member Avatar for Anyday
0
342
Member Avatar for dennysimon

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]

Member Avatar for JamesCherrill
0
121
Member Avatar for Erlendftw

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: …

Member Avatar for Erlendftw
0
151
Member Avatar for pikalife

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 …

Member Avatar for hfx642
0
8K
Member Avatar for dave013
Member Avatar for bbman

Do you have a pack(); somewhere in your code. Do you call pack(); after adding the new panel?

Member Avatar for JamesCherrill
0
166
Member Avatar for geekman89

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 …

Member Avatar for geekman89
0
498
Member Avatar for Joey_Brown

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 …

Member Avatar for Joey_Brown
0
127
Member Avatar for Yutxz

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.

Member Avatar for JamesCherrill
0
219
Member Avatar for Pravinrasal

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 …

Member Avatar for JamesCherrill
0
87
Member Avatar for ashley808

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

Member Avatar for JamesCherrill
0
761

The End.