7,116 Posted Topics

Member Avatar for adesexy

DaniWeb Member Rules (which you agreed to when you signed up) include: "Do provide evidence of having done some work yourself if posting questions from school or work assignments" http://www.daniweb.com/community/rules Post what you have done so far and someone will help you from there.

Member Avatar for JamesCherrill
0
77
Member Avatar for javaprog200

KeyListeners are always problematical, particularly in respect of which component has the keyboard focus. The answer is don't use them. Oracle's own tutorials recommend key bindings instead: http://docs.oracle.com/javase/tutorial/uiswing/misc/keybinding.html

Member Avatar for javaprog200
0
254
Member Avatar for jamesperkins0

`72: nextStudent++;` You have the code to update nextStudent correctly, but there ate two related problems that prevent that working as you expect: 1. Every time you enter your actionPerformed the first thing you do is to set nextStudent back to 0 2. You declare nextStudent inside the actionPerformed method, …

Member Avatar for jamesperkins0
0
393
Member Avatar for JamesCherrill

I'm curious. Why is so much code in this forum formatted like this [CODE]if (something) { do something } else { do another thing }[/CODE] rather than [CODE]if (something) { do something } else { do another thing }[/CODE] The first version is harder to read and takes up more …

Member Avatar for JamesCherrill
0
379
Member Avatar for challarao

The original question seems flawed. As you say, square and circle each require one numeric parameter, triangles and rectangles both need two, so there's no way to distinguish those method signatures without resorting to highly artifical solutions like the one you show. Are you certain that you were not asked …

Member Avatar for stultuske
0
203
Member Avatar for rahul.ch

> When we assigned ls to o, didn't Object o become an array? Don't lose track of the difference between objects and **reference** variables. Nothing you can do in Java will change the actual type of an object. ALl you can change is what references are known to refer to. …

Member Avatar for rahul.ch
0
292
Member Avatar for PriteshP23

Yes, you already said that in your first post. The code you have posted in not valid Java. It won't compile, and therefore cannot be executed. So how about posting the actual code that gave you the error?

Member Avatar for PriteshP23
0
187
Member Avatar for Consuela94

Hello alastair That was a very clear and helpful post, but it did spoon-feed the OP a lot of code. There's always a danger that someone will copy/paste those blocks without understanding how they work, and thus learn nothing. If you use pseudo-code to illustrate the logic then the OP …

Member Avatar for Consuela94
0
5K
Member Avatar for Ubi2073

If you are using ordinary random numbers then its hard to see how you can possibly decode the resulting randomised content. Maybe what is intended is that you use the seed value to seed the random number generator. The Java Random class guarantees that "If two instances of Random are …

Member Avatar for NormR1
0
296
Member Avatar for alastair1008

Without actual error message(s), the code in question, and a listing of the jar contents it's very hard to identify where you have gone wrong! One likely area is that some classes are missing from the jar, or are not in the correct folders within the jar, but the error …

Member Avatar for alastair1008
0
222
Member Avatar for Tomi1988

When you pass a value (primitive or reference) to a method Java creates a copy of that value, and that's what you are accessing inside the method. (Note that the value of a reference variable is a reference, not the object that is referred to, so only the reference is …

Member Avatar for JamesCherrill
0
242
Member Avatar for julm

dansm88 Please don't just ask people to give you code. If yuo have a Java question, or there's some aspect of Java you want to learn about, please start your own thread and explain what you have done already.

Member Avatar for dansm88
0
922
Member Avatar for Aninda

The NPE message tells you the exact line where it happened. Unfortunately the message you posted doesn't match the code you posted, so we can't see which line is the problem. Print the variables or methods that are used on that line to see which is null. Then use more …

Member Avatar for NormR1
0
190
Member Avatar for hwoarang69

It looks like you created the transform OK, but missed the bit where you associate the AffineTransform with Graphics, as in `g.transform(tx);`, before drawing. Once you have that working you will be able to see how different transforms affect your image. I suggest just starting with one at a time, …

Member Avatar for JamesCherrill
0
118
Member Avatar for KRUX17

You have defined the ArrayList as an ArrayList of Orders. That means the only thing you can add to that list is an Order. You can't add a String (line 18) and you can't add nothing (line 19). You didn't post the code for the Order class, but presumably it …

Member Avatar for KRUX17
0
174
Member Avatar for hwoarang69

You can do it easily in Eclipse. Select your project then go to File -> Export... -> Runnable jar file That takes you into a Wizard that will help you create a runnable jar file. You can double-click the jar file on the desktop to run your program (assuming Java …

Member Avatar for JamesCherrill
0
279
Member Avatar for shihab2555
Member Avatar for tingwong

for(int i = 0; i < cookies.length; **i++**){ for(CookieFlavors c : CookieFlavors.values()){ cookies[**i++**] = new Cookie(c); You increment i twice on some passes of this loop, so some indexes get skipped and are left as null.

Member Avatar for JamesCherrill
0
1K
Member Avatar for javaprog200

You increment count by 2 on each loop, so its values go 0, 2, 4, 6, 0, 2 ... that's a four value cycle ps you have a redundntt loop lines 41/50 - flad g is always set false, so its only ever executed once. pps `while (flag == true)` …

Member Avatar for javaprog200
1
145
Member Avatar for adams161

Macify looks interesting as a packaged solution: http://simplericity.com/2007/10/02/1191336060000.html or here's a load of info for doing it yourself: http://alvinalexander.com/apple/mac/java-mac-native-look/ ... lots of other info is at the end of a very small Google query. In either case you can use the same jar for both environments, and you can compile …

Member Avatar for JamesCherrill
0
244
Member Avatar for Ricky116

The default font for a JLabel is porportionally-spaced, so , for example an "i" or a space (" ") will be lot narrower than an "M" or a "W". If you want all characters (including " ") to be the same space specify a fixed-width font for your JLabel, eg …

Member Avatar for Ricky116
0
933
Member Avatar for shihab2555

Lines 14-16 create the Vector of column names from the result set (did you write that code yourself, or just copy it?). If you want some other name(s), put them into the Vector instead of the current value(s).

Member Avatar for shihab2555
0
2K
Member Avatar for challarao

The "other person" is not helping you. Line extends Point makes no sense. A Line is not a "kind of" Point. The Line class makes no use of the variables or methods it inherits. It's just wrong. Your Line class, with two Point instance variables to define its ends makes …

Member Avatar for jalpesh_007
0
196
Member Avatar for anand01

Vectors own methods are synchronised on the Vector instance, so if you call add on a Vector from one thread while another thread is executing a remove yhou should be OK. Vetor knows nothing about your callMethod method, so it can do nothing about synchronising that. It does not / …

Member Avatar for anand01
0
188
Member Avatar for Monkey101

> How many Pixels are copied when the Picture is mirrored along the vertical line through its middle? Isn't the answer just "all of them" (H*W)? Or am I missing something?

Member Avatar for NormR1
0
114
Member Avatar for coolbeanbob

The easiest way to to decide on classes is to go back to the English description of the domain. Being English I have no idea about baseball, but if *Stats* are things that a *Player* ***has***, then the obvious implementation is that Stats are a class and a Player has …

Member Avatar for JamesCherrill
0
196
Member Avatar for riahc3

Since you're a bit past the beginner stage, how about Netbeans? It's the one that the Oracle Java tutorials use. http://docs.oracle.com/javase/tutorial/uiswing/learn/index.html

Member Avatar for ~s.o.s~
0
300
Member Avatar for minimee120

Put a load of print statements into your code, printing the values of the key variables at each stage so you can see where it's going wrong, eg at line 23 print command and name, when adding entries to the directry print them, so you know for certain what's in …

Member Avatar for NormR1
0
249
Member Avatar for kristenw17

When reading the file how do you know how many scores there are for each student?

Member Avatar for JamesCherrill
0
348
Member Avatar for caswimmer2011

Your listener will be called once for each key, so you can't look fr both keys in just one call. You need to create one or more variables outside the listener that you can use to keep track of what keys have already been pressed

Member Avatar for JamesCherrill
0
230
Member Avatar for hwoarang69

Graphics2D (the actual class of the Graphics you draw on) supports a huge set of transforms that modify how subsequent draw operations work. So, for eaxmple the g.rotate method causes all subsequent draws to be rotated by the specified angle. Similarly you can set a scale transform that scales subsequent …

Member Avatar for hwoarang69
0
137
Member Avatar for kadambari.nalavade.1

DaniWeb Member Rules (which you agreed to when you signed up) include: "Do provide evidence of having done some work yourself if posting questions from school or work assignments" http://www.daniweb.com/community/rules Post what you have done so far and someone will help you from there.

Member Avatar for JamesCherrill
0
33
Member Avatar for Malymieczek

I have to disagree with Taywn. This is absolutely an integer problem that needs an integer solution. The positions are described as in the middle of a 1 foot section, but that's irrelevant. YOu don't need to know where the step comes to the nearest inch. There are only 7 …

Member Avatar for Taywin
0
947
Member Avatar for leffects

DaniWeb Member Rules (which you agreed to when you signed up) include: "Do provide evidence of having done some work yourself if posting questions from school or work assignments" http://www.daniweb.com/community/rules

Member Avatar for JamesCherrill
0
40
Member Avatar for georget1011

That looks like you're setting that cell before you create the GUI, and when you create the GUI you set a new model. Try setting the cell *after* creating the GUI

Member Avatar for mKorbel
0
1K
Member Avatar for Kronolynx

java.lang.NullPointerException at AppletMetodos.actionPerformed(AppletMetodos.java:96) One of the values on line 96 is null (ie not initialised). Print all the variables used on that line to see which one is null, then you can back-track to find out why. The array "user" would be the prime suspect...

Member Avatar for Kronolynx
0
311
Member Avatar for vjjohnson04

Don't confuse methods and variables. The compiled code for all methods will be loaded along with the class some time prior to the class's first use. The memory for static variables ditto. The memory for instance variables is allocated when a new instance is created. All this is true of …

Member Avatar for Taywin
0
311
Member Avatar for anonb

indexOf for ArrayLists looks for the search object in the ArrayList. The search object is the String "Java". There is no object in the ArrayList that is equal to the String "Java". You will have to loop thru the ArrayList testing each String in turn to see if it contains …

Member Avatar for stultuske
0
346
Member Avatar for UNDER-18 FG

You need to import the Scanner class. ps DaniWeb Member Rules include: "Do not hijack old threads by posting a new question as a reply to an old one" http://www.daniweb.com/community/rules Please start your own new thread for your question

Member Avatar for jalpesh_007
0
703
Member Avatar for jalpesh_007

It's really hard to understand your requirement, but is this what you mean (pseudocode)?... valuesToSkip = new ArrayList<Integer> for (r ... if (valuesToSkip.contains(r)) continue; ... valuesToSkip.add(anotherValueThatYouWantToSkipNextTime)

Member Avatar for jalpesh_007
0
186
Member Avatar for Tomi1988

The Java Language Spec section 12,5 is the definitive refernce on instance initialisation, but briefly, in simple cases like that there's no difference. In your first example the initialisation of the int happens after all superclass constructors have been called but before the remainder of the constructor executes. It's possible …

Member Avatar for ObSys
0
94
Member Avatar for jamesperkins0

Debugging by re-reading your code and thinking hard is very ineffective. Put a load of print statements into your code, printing the values of the key variables at each stage so you can see where it's going wrong.

Member Avatar for jamesperkins0
0
232
Member Avatar for subrat_p

What exactly is the question? You can clear a text field by simply setting its text to "", but remember that will create another call to your DocumentEvent listener, which you may need to handle.

Member Avatar for JamesCherrill
0
551
Member Avatar for pooran.c

Loop with an index variable that starts from 2, but then when you increment it test if it is >= (length of the array), in which case set it back to 0.

Member Avatar for stultuske
0
372
Member Avatar for aravind326

1. You can't assess "efficiency" unless you have a reasonable list of the various ways in which the data needs to be accessed and a rough count of how often each of those will happen. Do you need to find the priority for a given operator? Do you need a …

Member Avatar for aravind326
0
455
Member Avatar for hwoarang69

They could ask you about sorting arrays - various algorithms and their advantages/disadvatages

Member Avatar for jalpesh_007
0
188
Member Avatar for Kathy0410

If it completes one pass thru the data without having swapped any elements, then the list is sorted, so all you need is a simple boolean for that.

Member Avatar for JamesCherrill
0
93
Member Avatar for OsaidAz

You need public accessor methods such as getName, getID that simply return the values of those private variables. That way you allow other classes to get the values in a controlled way, but not to change or corrupt them. Similarly you can create public setID etc methods if you want …

Member Avatar for OsaidAz
0
238
Member Avatar for IcyFire

A grid layout is just an algorithm for placing GUI objects in a container. The "cells" are just an abstract geometrical concept, so there's no meaningful way to "mainipulate" them. What you can do is create a 5x5 array of some real objects, eg JButton[5][5] or JLabel[5][5], then use the …

Member Avatar for IcyFire
0
218
Member Avatar for rahul.ch

Case 1 every element is an Integer or a subclass of Integer. All subclasses of Integer are Integers (can be cast to Integer), so the implicit cast to Integer is OK Case 2 every element is an Integer or a superclass of Integer. Not all superclasses of Integer are Integers …

Member Avatar for rahul.ch
0
2K

The End.