JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

you hv to take container class refernce
like contaner c; // before constructor
then c=getContentPane(); //in the starting of constructor
c.add(start); /*after the buttons setbounds
c.add(controls);
c.add(credit);

This code is obsolete.
The need to add things to the content pane, rather than just the JFrame, was an annoyance in early versions of Java, but this was fixed in Java 1.5. In 1.5 and later you just add components to the JFrame, and don't need to worry about the content pane.

(LevyDee had the right answer)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Provided all your code is in one package you can use protected, or just leave the visibility blank - its the same (see the link I sent earlier). It will work for all your variables, so if it appears to be just x and y then there's something else wrong as well.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Remove the "private" and you will be able to access the superclass variables in the subclasses.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

When you subclass Tile you re-declare variables
private Image tileImage;
private boolean tilePassable;
private int x,y;
in each subclass. Now you have two versions of each variable, the subclass ones "hide" the inherited ones and you end up having to duplicate inherited methods to word with the duplicated variables.
Simple answer: get rid of the duplicated variable declarations and just use the inherited ones. Then your inherited methods will work also.

ps declaring them private doesn't help either, protected or default access will allow subclasses to see them
http://download.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Why +2 on line 41?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Because they are just updating an in-memory buffer, not reading/writing the file every time (that only happens on a Save)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Look again, compiler and runtime messages do show the line number.

Without a proper statement of what this code is supposed to do I can't comment on how to reconcile your 2d data with your 3d array. But all the following statements seem to have the third index as [0] all the time, so maybe the third dimension is not needed???

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Assuming this error is around line 88 (and next time please post the line number with the error messages!) you define a 3-dimensional array,, but try to initialise it with data in the form of a 2-dimensional array. So when it looks inside the 2d array it expects to find one more level of array, but all it finds is a String.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Add all the components to the north panel, populate the with data, then pack(). This is the call that fits things.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Its the full width of the window; just how broad did you want it to be?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

A method can have more than one return statement (eg it may return null if there is an error). You must ensure that no matter which if tests and loops are executed, it always ends up by executing a return statement.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The Java tutorials contain everything you need... look at thisone
http://download.oracle.com/javase/tutorial/java/javaOO/returnvalue.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

yes! It really is that easy!
Now you have to decide what you are going to do with that new Products instance.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Like I said, provided it's coded sensibly (esp. use buffered streams) it will be limited by your disk hardware read/write speed. The only way to improve beyond that would be a disk upgrade (SSD).
IMHO the "best" choice of language would be "the one you are most comfortable writing in". Performsnce/efficiency of the language won't be an issue.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

How big is "very large"? As long as it's under, say 100Meg, you could just read it into memory, update it there, write it back. As long as its under 2Gig you would have to read/write on the fly. Either way it's going to run as fast as your disk can read and write.

If this really is a big problem you should look at a better file structure, eg each line = 1 record, each record has a pointer to the next. Then you can update a line by writing the new version to the end of the file and updating the relevant pointer in place.

warlord902 commented: awesome answer :) +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If I understand the question then, no.
It's nothing to do with what language. If you put a new character into a file then either it overwrites an existing char or you have to move the rest up to make space for it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No, no need to do anything like that.
You have a perfectly good constructor already. You just have to call it from around line 52. Check out how to calla constructor to create a new instance of a class.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

By line 52 you have variables containing the id, name, category and price.
At line 18 you have a constructor that takes id, name, category and price and creates a Products instance.
So all you need to do is call the constructor passing the values.. easy peasy!

ps: Each instance of your class represents one Product, so your code will read better if you call it Product rather than Products.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can subclass JToolTip to create a custom appearance etc, then subclass the control in question to override its public JToolTip createToolTip() method (inherited from JComponent) to return an instance of your customised JToolTip subclass.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yay! I knew you could do it! Mark this thread "solved" so others will know.

ps: Small point: Java coding standards say class names begin with a capital letter, variable names should begin with a lower-case letter.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Correct the syntax of your method call on line 15.
You have to work this out for yourself, or you'll learn nothing.
It's not hard.

Just to make things really confusing, you have a method and an array variable with the same name. The array variable is never initialised and seems to be useless. Based on what you have posted so far, you can/should get rid of it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Method calls always have a ( and a ) somewhere...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's telling you
NullPointerException a variable isn't initialised, or a method has returned null when you expected it to return a value of some sort.
and
at sensor.sensor.main(sensor.java:15) that happened on line 15 of sensor's source code.
That line says
System.out.println(ob.getId);
getID is a method, but that's not a valid method call... (think about it)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I think you made the wrong change - it would have been better to change the calls to pass ints, rather than change the method to accept Strings, but never mind.

You have missed out the all-important first line of the error message, the one that tells you exactly what the error was.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The constructor defines its parameters as a String and two ints.
When you call it you pass three Strings.
"1" is a String, 1 is an int.

ps Next time, please post the exact error message that you get. It makes our lives a LOT easier!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Is courseObjects a static variable in the Course class? (If not, it probably should be - ie the class has a single static variable that contains all the individual instances of Course that have been created. This is a very common pattern). If so you refer to it via the class name. Creating the course[1] array is almost certainly not a good answer to anything.

Anyway, when you get value (eg null) that you don't expect then you can put loads of temporary print statements into the code leading up to that point so you can see exactly where it's coming from.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In checkCourse you continue to loop and re-set "matched" after finding a match, so it will only return true if the string matches the very last element in the array. You need to exit the loop as soon as you find a match.
Assuming courseObjects[] is some kind of variable, there's no need for the courses[0].

ps
if (courses[0].checkCourse(tempCourse) == true)
is horribly redundant. What's wrong with
if (courses[0].checkCourse(tempCourse))

Java coding standards suggest methods that return a boolean should have a name that starts "is" to make their meaning absolutely clear.
Applying all the above you could write
if (isAValidCourseName(tempCourse))

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, that clarifies it a lot.

Your loadStudent method looks like it going the right way - creating, loading, and returning an array of Students from the file.
But look at how you call it

io memory = new io();
    memory.loadStudent();

what do you do with the array it returns??? Right now you ignore it, and it gets lost. Maybe you should assign the returned array to something...?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

some observations:

saveStudent 4: the "true" in the FOS specifies append mode, so that's why the file keeps growing.
saveStudent 5: what's arrayStudent and why do you use it?

Exception (non) handling. You seem determined to ignore IOExceptions. This is always a mistake. Catch them, and printStackTrace() the exception so you know what is, or isn't, happening.

You read/write an array one element at ta time. Why not just read/write the whole array as a single object?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's an "enhanced for-each loop" - a new feature in Java 1.5
It uses and array or any other collection (eg List) of things, and iterates thru them one at a time.
In your case closest is an array of "P" objects, and the for loop is read as

for each P object "p" in the array closest...
... print p

Local variable p is set to the first element of closest, and the body of the loop is executed. p is them set to next element etc etc.
It's like

for (int i = 0; i < closest.length; i++) {
  P p = closest[i];
  System.out.println(p);
}

... or the equivalent for collections and lists.

It's generally considered to be an easier and clearer syntax, and it avoids the traps people sometimes fall into with iterators.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You'll need a loop, executed (length of string)/5 times
You can use the substring method in the String class to pick out 5 chars starting from an arbitrary start point...

Try doing this once by hand on a piece of paper to understand the exact sequence of steps, then convert that to Java code.

It's going to take about four lines of actual code, so its not hard. Just give it a try.

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

Firstly, "run anyway" is a waste of time - if there are compiler errors then you need to fix those before attempting to run anything.
Secondly, if you comment out lines of code from your algorithm then of course it won't work.
Thirdly, make sure every catch block has an e.printStackTrace(); so you can see all the details of any errors during execution.

Step one is get a clean compile of all the code.
If you need help with compile errors post the exact code that you compiled and the exact compiler error message (including line number(s)). Saying "some errors" gives us absolutley nothing to go on.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

...is it possible to change the manual port-forwarding to programmatical NAT hole punching ?.

I'm sure it is, but personally I have no idea how to do it! Perhaps someone else can step in here...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You are OK about instance & class vars, instance variable are one per object created, class vars are one shared between all objects of that class. but the static keyword defines a class var. It's an instance var if it does NOT have the static keyword.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I don't see anything fundamentally wrong with your current approach.I've used it myself more than once. It's just a bit fiddly getting the network setting right. Assuming your server is on a LAN sitting behind a NAT router:
Open a firewall exception on the server PC to allow incoming connections to the server socket's port.
Create a port forwarding rule on the router to map an incoming WAN IP/port to the LAN IP/port of your server. If necessary open the appropriate ports on the router's firewall.
Connect internet clients to the WAN IP/port.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi balajisathya88
Please be aware that there is a policy on this forum of not just giving people the code they need for their homework. People learn best if you point them in the right direction (eg a tutorial, or the name of the class/method they need), then let them practice doing their own research and developing their own code which they will fully understand. You would have helped the OP better by saying something like "check out the Random class and its nextInt() method"
ps Your code violates standard Java naming conventions by having a lower-case class name; not such a good example,

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Check out the Java Language Reference, chapter 10.
http://java.sun.com/docs/books/jls/third_edition/html/arrays.html
This is the ultimate source of answers to questions like that.
JC

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Stop thinking about 2d arrays. Java arrays are one-dimensional. It's just that the data type for a java array can itself be an array, so you can nest arrays within arrays (etc). It just so happens that a java array whose elements are arrays all of the same length looks like a 2D array, but really that's just a special case, not a starting point.
So you have an array, one element for each line of your file. Each of those elements is itself an array of the tokens from that line.
Now, with that in mind, the code goes like this:
1. Declare array of array of Strings String[][] data; 2. Get the number of lines in the file and use that to allocate the outer array data = new String[noOfLines][]; 3. Read each line and split it into an array of Strings - something like String[] tokens = inputLine.split(","); 4. Put that array into the outer array data[i] = tokens; Remember guys, Java is not C

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Correct.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Short answer: You declare
Class49 aVar;
now var49 will be constrained only to refer to instances of Class49 or subclasses (no matter how deeply nested/subclassed) of that class.
When you code
aVar.doSomething();
the compiler checks that .doSomething() is valid for Class49. Since all subclasses (direct or indirect) of Class49 either inherit or override all of Class49's accessible methods, the statement is valid, regardless of the value of aVar.

ps: Beware; different logic applies to static methods

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The way you posted the code the classes were instance inner classes, so you couldn't instantiate them from static main without an instance of the outer class.
Anyway, this is the cleaned up version that worked for me:

public class Demo {

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

   Demo() {
      superclass newobj;
      for (int x = 0; x <= 1; x++) {
         if (x == 0) {
            newobj = new class1();
            // newobj = (class1) newobj;
         } else {
            newobj = new class2();
            // 
            newobj = (class2) newobj;
         }
         newobj.testfunc();
      }
   }

   private class superclass {

      public void testfunc() {
         System.out.println("superclass");
      }
   }

   private class class1 extends superclass {

      int specialvariable;

      public void testfunc() {
         System.out.println("class1");
         specialvariable = 100;
      }
   }

   private class class2 extends superclass {

      int specialvariable2;

      public void testfunc() {
         System.out.println("class2");
         specialvariable2 = 100;
      }
   }
}

Main thing is that your final try was exactly on the right lines. I don't know why your actual code wasn't working

ps If your actual app already has those classes extending something else, you can define an interface with the common method name(s) and have them all implement that.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I looked at your final version. Of course it won't compile, so can't be the code you actually ran. (That doesn't help diagnose you know, when the code you post isn't the code you had a problem with).
Anyway, I fixed the missing semicolons and the static method references to non-static inner classes, and it works perfectly.
ps the casts are redundant.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Easiest way is to keep a list of the numbers you have already used. Check each new random number against the list and get a new one if it was a duplicate.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Here, just for fun, is runnable demo of just how easy it is to drag a JLabel around a container and log the final position. The trick is to remember that the mouse event coordinates are relative to the object being dragged, not the container, so you have to see how much the mouse has moved, and move the JLabel by the same amount.
I deliberately left out the comments to give everyone a learning opportunity ;-)

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

public class Demo implements MouseListener, MouseMotionListener {

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

   JLabel sprite = new JLabel("drag me");

   Demo() {
      JFrame frame = new JFrame("drag demo");
      frame.setLayout(null);
      frame.setMinimumSize(new Dimension(400, 300));
      frame.setLocationRelativeTo(null);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      sprite.setBounds(10, 10, 80, 20);
      sprite.addMouseListener(this);
      sprite.addMouseMotionListener(this);
      frame.add(sprite);

      frame.setVisible(true);
   }

   int startDragX, startDragY;
   boolean inDrag = false;

   @Override
   public void mouseEntered(MouseEvent e) {
      // not interested
   }

   @Override
   public void mouseExited(MouseEvent e) {
      // not interested
   }

   @Override
   public void mousePressed(MouseEvent e) {
      startDragX = e.getX();
      startDragY = e.getY();
   }

   @Override
   public void mouseReleased(MouseEvent e) {
      if (inDrag) {
         System.out.println("Sprite dragged to " + sprite.getX() + ", " + sprite.getY());
         inDrag = false;
      }
   }

   @Override
   public void mouseClicked(MouseEvent e) {
      // not interested
   }

   @Override
   public void mouseDragged(MouseEvent e) {
      int newX = sprite.getX() + (e.getX() - startDragX);
      int newY = sprite.getY() + (e.getY() - startDragY);
      sprite.setLocation(newX, newY);
      inDrag = true;
   }

   @Override
   public void mouseMoved(MouseEvent arg0) {
      // not interested
   }

}
mKorbel commented: lots of fun +1 +9
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In the mouse click handler just create a new AndGate() or whatever and add it to the "canvas" (an ordinary JPanel would do) at the mouse click coordinates (use absolute positioning and a null layout manager for the "canvas").
ps drag'n'drop really isn't that hard - certainly less hard than writing your own code to move things around.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can download the source code for the classes in the Java SE API from the Oracle web site.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

As I see it, the big advantage of the splash screen is that java.exe loads and displays it before loading and initialising your app. Any java language-based approach won't display until the application has loaded and main has been called anyway.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Can't you create the animation with flash then save it as a gif? eg:
http://www.ehow.com/how_2200108_publish-animated-gif-flash.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

My main aim is to provide a startup animation , so application before start produce a good effect on the user, like word, excel etc...

You should have said that earlier. It's easy. Java 6 has a "splash screen" capability that displays an image while your app is loading, and that image can be an animated gif.

http://download.oracle.com/javase/tutorial/uiswing/misc/splashscreen.html