JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Follow the list until you get to the specified ID then insert the new node after it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Apparently Intel processors from Ivy Bridge onwards have a hardware random number generator instruction that is as near quantum-mechanical noise random as you can be...

http://software.intel.com/sites/default/files/m/d/4/1/d/8/441_Intel_R__DRNG_Software_Implementation_Guide_final_Aug7.pdf

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Can't you just clear the contents of rects?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I have considered eventually hiring an experienced programmer to fine tune everything...

Software quality (no matter how you measure that) starts with the specifications and is more or less fixed by the design. If the design is good you can deal with any rough code later, if the design is poor no amount of clever coding will fix it.
Conclusion? If you want to involve someone experienced, do it sooner, not later.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'll try that for you, but it won't be for a couple of hours now...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That all looks OK, no problems there.
Are you using an old or slow machine? That code gives no visible flickering on my Core i3 2125 (not specially fast by 2012 standtads!), in Eclipse or running from a jar.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Did you run the code I posted? Did that flicker?
What version of Java are you running?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Thread sleep isn't a good way to go, the Java API includes Timer classes that you can use to schedule updates to your animation at regular intervals. The paint looks OK. Here's the simplest possible runnable example of a good approach

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Animation0 extends JFrame implements ActionListener {
   // absolutely minimal example of how to structure animation in Swing.
   // One method that steps the simulation model through time
   // One method that updates the screen with the latest data
   // close window to exit.

   public static void main(String[] args) {
      new Animation0();
   }

   Animation0() {
      // build a minimal working window ...
      setTitle("Animation 0 (close window to exit)");
      setMinimumSize(new Dimension(400, 150));
      setLocationRelativeTo(null);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setVisible(true);
      // start Timer to call actionPerformed every 30 milliseconds...
      new Timer(30, this).start();
   }

   // this is the "model" - just a single object moving L-R at constant speed
   private int xPos = 0; // current position(s) of animated object(s)

   public void actionPerformed(ActionEvent arg0) {
      // reliably called by Timer every 30 milliseconds
      xPos += 1; // update position(s) of object(s)
      repaint(); // notify that screen refresh is now needed
   }

   // this is the GUI - draws the model on the screen

   @Override
   public void paint(Graphics g) {
      // screen refresh - called by Swing as needed
      // Never update positions etc here because there are no
      // guarantees about when or how many times this will be called.
      super.paint(g); // ensure background etc is painted
      g.fillOval(xPos, …
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

A small point:
although the declaration syntax int arr[] is perfectly valid, most standards prefer the form int[] arr That's the form you will find throughout the Java API source code.
The reason is that arr is an array of ints, as implied by the second form. The first form seems to suggest that there is an array of arrs that is an int.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Also you can define null value with String s =""; //declares a variable refers to String class,having initialised with null string..so its value is null..

You can also define like Strinf s1 = NULL; //It's also java's reserved keyword..

Wrong, wrong, wrong.

"" is a String object containg a string of zero characters. The variable s refers to that object, it is NOT null.

Java is case sensitive, NULL is not the same as null

null is not a Java reserved keyword, it is a literal (J.L.S. 3.9)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There are lots of people here who will freely give their time to help you become the best Java programmer you can be. There's nobody here who is interested in helping you cheat or doing your homework for you.

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.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In Java you have variables and expressions that refer to objects or arrays.
"null" is the special value for those variables or expressions that have not been initialised to refer to a real object or array - it means that they refer to nothing.
eg
String s; declares a variable that refers to a String, but it has not been initialised, so its value is null

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Suppose you have a line
a = b.toString() + array[i];
then you would try
System.out.println("b is " + b + " array[i] is " + array[i]);
ie print the specific variables that are used on that line.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, deep breaths.
Check the lines in question, add print statements to see which variable on that line is null. Once yo have identified the problem, trace the code backwards to see where it started.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Ahhh - I just read a bit more of the code and saw that all your variables are static, so everything I previously said about constructors is irrelevant!
Static vars and methods belong to the class itself, and have no access to instance methods or variables. You can use static members without ever creating an instance of the class. Constructors are specifically used to initialise instances when they are created, and that's all.

With all static variables you just need to be careful to initialise before you use. In this case that's as simple as putting things in the right order in your main method.

ps: Java is an object-oriented language, and so instances and instance methods and variables are what it's all about. Static methods and variables are only used in specific cirumstances. What you're doing here is not necessarily wrong, but it's not the way you will be doing things in future.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I must be mad to have waded through all that code in German, but...

Lines 64... you call addButtonListener.
The last line of that method calls KI_Test1.Vergleich();
Vergleich() accesses elements of the Kaestchen1 array
then, finally, around line 119 you initialise the elements of Kaestchen1

... so when you call KI_Test1.Vergleich(); from addButtonListener the array is still unitialised, so you get null pointers.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Daniweb member rules include
"Do ensure that all posts contain relevant content and substance and are not simply vehicles for external links"
We also discourage people from simp/ky posting complete solutions.In future please help by pointing people in the right direction.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can't "replace it with null string" in an int array.
For int arrays all you can do is to chose some value to represent elements that do not have a user value in them. Integer.MIN_VALUE could be a good choice.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hello salasah
Welcome to DaniWeb, and thank you for taking the time to contribute.

Here are a couple of things to think about before your next post:
1. This thread is 2 years old, nobody is still waiting for the answer
2. More important:
Here at DaniWeb we try to help people learn Java and develop their Java skills. We do NOT do people's homework for them. Your post explains and teaches nothing. In future please help by pointing people in the right direction - eg tell them which classes and methods they should read about. If you feel you should correct someone's code then that's useless if you don't explain what you changed and why you changed it as you did. If you need to explain with actual code then explain why you coded it the way you did. Don't just spoon-feed them a solution to copy and paste.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Animation in Java is pretty straightforward, good fun, and can work really well, at least in 2D. There's great scope for modelling physics - gravity, friction, things bouncing off each other...
See also http://www.daniweb.com/software-development/java/threads/430542/java-projects-for-learners

jalpesh_007 commented: good suggestion... +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Welcome, and we all wish you great success with your project.
Without knowing more about your current level of expertise its hard to offer relevant advice, but maybe these two mantras will add to the obvious O.O. stuff...
Test early and test often. Depending on your experience level try to test every 10-40 lines of code. 10% extra work on early testing will save you 50% work trying to debig big blocks of new code with mutiple bugs hiding each other.
Its all about method signatures. If you get the method signatures right (right parameters, right return type, name exactly describes what it does) then your whole application will hang together properly. The code inside the methods may be incomplete, buggy, slow... but those are easy to fix one at a time.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

new Random() creates a new instance of Random, then we use that to call nextInt. So nextInt is an instance method.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Did you look at http://www.jthink.net/jaudiotagger/ - it looks pretty good and seems to support setting artwork. (I haven't tried it myself)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Try javax.xml.bind.DatatypeConverter (Java SE 6 or later)
That has printBase64Binary and parseBase64Binary methods to convert byte[] to printable String and back again, eg

      byte[] b = {(byte) 99, (byte) -101};
      String s = javax.xml.bind.DatatypeConverter.printBase64Binary(b);
      System.out.println(s);
      byte[] b1  = javax.xml.bind.DatatypeConverter.parseBase64Binary(s);
      System.out.println(Arrays.toString(b1));
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You could convert them to Strings (eg in hex) then there's no problem with properties files.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

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.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can use the printf method instead of print. That allows you to specify formatting, eg how wide numeric fields should be.
http://www.homeandlearn.co.uk/java/java_formatted_strings.html

Kronolynx commented: thanks +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There are lots of people here who will freely give their time to help you become the best Java programmer you can be. There's nobody here who is interested in helping you cheat or doing your homework for you.

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.

deceptikon commented: Well said. Maybe we should use this as a boilerplate response to homework. :) +11
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, there's a pretty standard way of doing it. One Timer that calls each Ball's method to update its posiiton at regular intervals, and paintComponent delegates painting to a method in each Ball. Here's a little runnable tutorial program that shows the principles in action.

import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.TimerTask;
import javax.swing.*;

public class Animation1 extends JPanel {
   // Basic architecture demo for multi-sprite animation

   public static void main(String[] args) {
      // create and display the animation in a JFrame
      final JFrame frame = new JFrame("Animation 1 (close window to exit)");
      Animation1 animationPanel = new Animation1(600, 400);
      frame.add(animationPanel);
      frame.pack();
      frame.setLocationRelativeTo(null);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setVisible(true);
   }

   private ArrayList<SimpleSprite> sprites = new ArrayList<SimpleSprite>();

   final static int TIMER_MSEC = 30; // mSec per clock tick

   Animation1(int width, int height) {
      setPreferredSize(new Dimension(width, height));
      sprites.add(new SimpleSprite(Color.blue, 0, 35, 2, 1));
      sprites.add(new SimpleSprite(Color.red, 0, 250, 2, -1));
      startTimer();
   }

   void startTimer() {
      // use java.util Timer rather than javax.swing Timer
      // to avoid running intensive simulation code on the swing thread
      java.util.Timer timer = new java.util.Timer();
      TimerTask timerTask = new TimerTask() {
         @Override
         public void run() {
            updateSimulation();
         }
      };
      timer.scheduleAtFixedRate(timerTask, 0, TIMER_MSEC);
   }

   public void updateSimulation() {
      // called by Timer every 50 milliseconds
      for (SimpleSprite s : sprites) {
         s.update(); // update position of the sprite
      }
      repaint(); // request Swing to schedule re-paint of screen
   }

   @Override
   public void paintComponent(Graphics g) {
      // screen refresh - called by Swing as needed
      Graphics2D g2d = (Graphics2D) g;
      paintBackground(g2d);
      for (SimpleSprite s …
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It would probably llok like this:

 public void addPerson(Person p){
    files.add(p);
 }
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It will not be executed becuase it cannot be compiled.
counter -
is not valid Java

Nutster commented: I saw that too. Good catch. +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Where do lines 1,2 fit? You're obviously missing some of the code in that listing

OK, nevermind, heres the problem:
When you execute lines 1,2 you create new Main and call its createAndShowGUI() method, which, on line 56 creates a second instance of Main and displays that in the JFrame. NOw you have two instances, only the second one is visible, but both are executing

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's line 44 that's worng.
When you init your VectorGraph instead of adding that VectorGraph to the JFrame you create a second VectorGraph (with default values of 0) and add that instead. Your correctly constructed VectorGraph never gets displayed.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If I understand the question properly...
If your objects just store the value of c, then the information about whether it was a+b or b+a will be lost, and can't affect anything afterwards. On the other hand, if your objects store the two input values (eg arg1 = a, arg2 = b for the first case, arg1 = b, arg2 = a for the second) then they can make that info available to other classes.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Woahthere! You misundertand me! I meant no insult, nor did I mean to discourage you. I was not offended, nor did I want to offend you. In no way was I suggesting that you shouldn't ask questions. I was just trying to alert you to a problem that's pretty common with people who are at just starting with Java. I was just trying to help you get the best out of DaniWeb.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK!
If you don't mind a bit more advice...
please be very careful about how you use Java terminiology, otherize you will confuse people and therefore possibly get completely misleading answers. For example:

have a separate constructor for each String type

I honestly don't know what meaning you intended with this. There is only one String type and that is String. String is a final class with no subclasses, so there can never be any other types of String. In any class definition you can only have one constructor with any given list of parameter types, so you can only have one constructor that takes a single String.

I'm noy trying to be picky here, just trying to ensure that you get the right answers to your questions.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I think the change you made is going in the wrong direction. If you have 2 objects each should have its own string, and doesn't need to know about the other object's string. What will happen when you have 3 objects, a thousand objects? Will you have a thousand string constructor?
Normally you would have a String variable defined in the class. The constructor would take one string as a parameter and use that to set the variable. That way every time you create a new object it automatically has its own new string.

A suggestion: If you use a real-life example rather than just abstract class names it will be a lot easier to see what makes sense and what doesn't. Eg: just change the name of your class to Computer and the name of the String to manufacturer. Now which makes more sense:

Computer a = new Computer("Apple");
Computer b = new Computer ("Dell");

or

Computer a = new Computer("Apple", "Dell");
Computer b = new Computer("Apple", "Dell");
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If your program only uses the console for input and output then this is a problem. The standard setup for running a jar is to use javaw.exe, which does not display a command window or console. Try running your jar from a command prompt with java.exe instead of javaw.exe That will confirm tha the jar is OK.
To run a jar normally you will have to use something other than the console, eg simple Swing dialog boxes.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

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 is installed on the machine).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The text from an empty field is "" - a string of zero length.
You can't test the contents of a string with = or ==, you need equals(...).
The safest test here is to trim off any blank chars and see if anything is left, ie
s[1].trim().length() == 0

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you understand that then you will already know that whatever names you want for the columns just put those names in Vector columnNames
It's as easy as that.

columnNames.addElement("Column 1");
columnNames.addElement("My name for col2");
columnNames.addElement("This is col 3");
etc
shihab2555 commented: mmake crystal clear +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I think you lost count somewhere.

First let's count the ref vars:
Every instance of a Swanky has one var s.
main has two local vars, s1 and s2.
go has one local var, gs, which is created each time you enter go, and destroyed at the end of go's execution. A copy of this reference is returned from the method; the caller can ignore this (line 6) or keep its own copy (line 7)

Now let's count the objects:
main calls new Swanky twice - two new Swankys, containing two new vars.
go calls new Swanky once each time it's called - each Swanky has one new var.
Instances of any class are garbage collected when there are no remaining references to them

Aermed with that, and a sheet of paper, you should now be ble to draw all the objects and references in a single diagram and update that as you step manually thru the code... after which the correct answers will be obvious to you. :)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

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.
o is a ref var that can hold a reference to any object, including an array of ArrayLists. It can also hold a ref to a String, Integer, URL etc, which is why o[i] won't compile - unless it happens to be refering to an array at that particular time its wrong, and there's no general way for the compiler to know what it will be referring to at runtime.
In your first two cases you explicitly cast the ref to be a ref to an array, so the compiler believes that you can index it, but will compile in a runtime check, just to be sure.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

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 an instance of Stats as part of its attributes. I can't comment on whether thats one Stats class or 3 classes, or subclasses because I don't know how they work.

Shouldn't I try to minimize my access to the database since it will probably cause a page fault each time?

This is far far far too early to be talking about page faults! The time to optimise Java is when the functionality is basically complete and you can benchmark different solutions to any problems that actually arise. There are few developers experienced enough to identify real-life performance problems before the code is running.
What you should do is to ensure that your classes encapsulate the domain data fully, so you can adjust or change the data storage/buffering etc entirely within the class, without affecting in any way their public interface.
(Yes, maybe I'm overstating the case, but that's better then premature optimisation)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

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?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

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 / cannot know that you want the calls on lines 9 and 11 to be synchronised as one block.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

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

Kronolynx commented: thanks for the help +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

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 drawing - and here's the bit you were waiting for - a negative scale factor reflects the image in the correwsponding axis, eg g.scale(1.0, -1.0) keeps the size the same but reflects the drawing vertically. You will probably have to shift the origin of your Graphics2D to keep the reflected image in the right place.
See the Graphics2D API doc for details, the AffineTransform API for the maths behind it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Here's the kind of thing you would do in an O.O. design.

 class Operator {

   public Operator(String symbol, int precedence) ...
   // eg  new Operator(">=", 5);

   public String getSymbol() ... 
   public int getPrecedence() ...

   public List<Operator> getOpsWithSamePrecedence() ...

   public static Operator getOperator(String symbol) ... 
   // returns the Operator with that symbol, or null if symbol is not valid

   // could use subclasses to implement evaluate methods for each operator...
   public int evaluate(int arg1, int arg2) ...
   public boolean evaluate(boolean arg1, boolean arg2) ...
   ...