JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
// pseudo code
int max (int [] v) {
   if (v has only 1 element) return that element
   int[] v1 = copy of v excluding the first element
   int maxV1= max(v1)
   if (first element of v  >  maxV1) return first element of v;
   return maxV1;
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have already defined your class Register as an ActionListener, and supplied the appropriate method (line 76) so it's a mistake to add another new listener. All you need to do is to add the current instance of Register -= as in
b1.addActionListener(this);

ps I see what you were trying to do with your new listener - call the existing listener method, but you new line 5 actionPerformed will call the version defined on line 3 (ie itself) in an infinite loop. Anyway, you don't need the new listener, just add (this)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have created an action listener, but you have not associated it with the button.
Check out the addActionListener method that JButton inherits from its supercalss AbstractButton

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, yes. I assumed the array had been sized to fit the data.My mistake.
(That's why people use ArrayLists and Vectors!)
Sorry. J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This discussion about the array size seems to have gone off in a strange direction.
Regardless of where you get the array from you can find out its length at runtime using the "length" attribute that every array has.
The following code illustrates this

for (int i = 0; i < mydouble.length; i++)
  for (int j = 0; j < mydouble[i].length; j++)
    System.out.println(mydouble[i][j]);
  }
}

Note the second line - Java 2d arrays don't have to be rectangular, so it's not always correct to use a simple ROWS/COLS size. This form of the code copes with that.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, there are many such people here.
But what you need is someone who can fix your logic error with a few hundred lines of code fragments with virtually zero useful comments stuffed full of calls to methods and variables whose definitions you have not published followed by a lengthy custom diagnostic message that presumably means something to you.

Where you mark the code you have jtp=getPane(); and you ask "why isn't the JTabbedPane from when it was create?" Allowing for English not being your first language, I guess you mean that jtp is not referring to the tabbed pane you expected it to refer to?
You have not posted the declaration(s) of jtp, and, even worse, you have not posted the definition of getPane(). It's impossible to diagnose like that.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, you have two tabbed panes and your code is referencing the wrong one?
If so, that sounds like some simple logic error (eg using the wrong name somewhere, or re-using the same variable incorrectly), but there's no way to check that without all the code.It really shouldn't be hard.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm sorry. I don't even know what that sentence is supposed to mean.

Ezzaral commented: You aren't alone in that. +14
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Does your program throw an exception when you run it?
Do you catch the exception?
Do you print the entire exception message as in e.printStackTrace(); ?

The text in your original post is not a complete exception message; the stack is there but not the exception itself.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What exactly is the error message - or are we supposed to guess? ;-)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Both those sound like straightforward logic things. I'm sure you will be able to think through them.
Maybe it's time to mark this thread as solved? Any new problems deserve a new thread.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Quickly typed in, so no guarantees, but you'll get the idea

// setup the cards at initialisation time...
JLabel card1 = new JLabel();
card1.putClientProperty("Image", new ImageIcon(cardOneImage));
card1.putClientProperty("Name", "cardOneName");
card1.addMouseListener(this);
// repeat this setup for each card

// single listener for all cards
public void MouseClicked(java.awt.event.MouseEvent evt) {
   JLabel card = (JLabel) evt.getComponent();
   card.setImage((ImageIcon) card.getClientProperty("Image"));
   String cardName = ((String) card.getClientProperty("Name));
   // etc
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What kind of objects are your cards? Are they JLabels or what?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In your event handler you can use evt.getComponent() to get the actual card object that was clicked, which you can then use setIcon etc on.
That way you can also use the same event handler for all the cards.
If cards are some kind of Swing JComponent then you can associate any number of arbitrary values (eg a String, or BufferedImage) with each card by using putClientProperty and getClientProperty

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, you can use all the normal if test etc so if the scores are the same you go on the compare the times.
Either you have inconsistent versions (maybe old class files etc) or an old version of Java on your desktop?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I copied the essential bits of your code and compiled and ran the following

class Score implements Comparable<Score> {

   int theScore;
   String playerName;

   public Score(int theScore, String playerName) {
      this.theScore = theScore;
      this.playerName = playerName;
   }

   public int getScore() {
      return theScore;
   }

   public int compareTo(Score sc1) {
      if (getScore() < sc1.getScore()) return -1;
      if (getScore() > sc1.getScore()) return 1;
      return 0;
   }

   public String toString() {
      return playerName + "\t" + " " + theScore;
   }
}
public static void main(String args[]) throws Exception {

      ArrayList<Score> scores = new ArrayList<Score>();
      scores.add(new Score(99, "fred"));
      scores.add(new Score(0, "joe"));
      scores.add(new Score(50, "bill"));
      Collections.sort(scores);
      for (int i = 0; i < scores.size(); i++) {
         System.out.println(scores.get(i));
      }

This compiles and runs perfectly (Java 1.6u21), so what else is there in your full code that is preventing this fromworking?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Does line 26 really say "pulbic" ????

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What is the exact error message?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm afraid you'll have to direct that question to org.lwjgl didn't it come with any documentation at all?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

check out the params for substring - you select a substring starting at 0 ending at the last \, but you want one starting at the last \ and extending to the end of the string.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You didn't give us the line number for your exception, but, if it's line 92 you will need to look at the code/doc for org.lwjgl.opengl.Display to find out what it's complaining about and why.

But - where do you create/open/display the Display window???

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The action listeners are both inner classes of your main class, so if you move the declaration of StudentDB db out to the main class class you can access it from both listeners.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

main is a static method - executes as part of the class itself.
The other methods are not static, ie they are instance methods and need an instance of the class to execute. To avoid this getting any more complex than it absolutely needs to be, just declare all the methods as static.

Now that you are returning the values properly from the methods, you no longer need these variables at line 11:
digit = 0, whitespace = 0,letter = 0, vowel = 0.
You missed the second part of my code - just replace

digits(inputLine);
System.out.println("" + digit + " digits.");

with

System.out.println(digits(inputLine) + " digits.");

(etc)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Lines 10-13 are simply wrong. Get rid of them.

You are still trying to define your methods inside the main method. You are also missing the { } on all your method definitions (see my example below)

Your methods are confused as to how then communicate their results back to the main program. You can either:
1. Access a variable (eg digit) defined in the class, and update its value, or
2. Return the answer as a return value from the method
In general approach 2 is better.
Your methods use approach 1 (which is OK), and also kind of use method 2, except that the value "count" that they return doesn't actually get set in your methods

Lines 61 onwards, where you get the data and display the results are part of the digits method, but can never be executed because they come after a return statement.
They, and only they, need to be in the "main" method.

If you stick with approach 1 for your methods then you need to call all your methods after reading inputLine but before printing digit etc.
If you go for approach 2 (better) then you need to:
1. return the correct value from each method
eg

public int digits(String inputLine) {
   int count = 0;
   for (int z = 0; z < inputLine.length(); z++) {
      if (Character.isDigit(inputLine.charAt(z))) count++;
   }
   return count;
}

and
2. use these in the …

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This sounds to me like you should be using a JTable, not a JTextArea.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Great! Mark this as solved?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Suggest you think about extracting that code into an ordinary method then calling it (1) somewhere in your initialisation and (2) in the columnMarginChanged method

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

the code with 'TableColumnModelListener' is executed successfully.

Do you mean the code where the listener is added or do you actually mean that columnMarginChanged has been executed. Have you put a print inside the columnMarginChanged method?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Are you sure that columnMarginChanged in your TableColumnModelListener has actually been called before it drops thru into the problem code - or is txtAdminTextFields initialised somewhere else?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You're confusing the array and the index. In the original code:

if(scan != null) {
while(scan.hasNext()) {
String word = scan.next();
array[index] = word;
++index; // this is also a count of the number of elements filled!
}
}
return array;

just replace the return statement with something like

return Arrays.copyOf(array, index); // returns a new array containing just the first "index" elements of "array"
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If i is the number of elements actually used - Yes.
But the syntax is String[] newArray = new String;
Or use Arrays.copyOf to do that for you.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Copy the first "n" elements of the big array to a new array of size n, and return that.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Looks like the array is big, and you just populate the first "n" elements from the data file, so the remaining elements are un-initialised, and give an NPE when anyone tries to compare them for sorting.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I feel so embarrassed that we're not able to help more. Anyway, as a parting gift, try running this code. If you study it and learn how it works, it's the solution to you current problem.

public static void main(String args[]) throws Exception {
      
 String data = "1.5, 2.99, 3, 4000";
 String[] arrayOfTokens = data.split(",");
 for (String s : arrayOfTokens) {
    Double d = Double.parseDouble(s);
    System.out.println(d);
 }
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I have absolutely no idea why you are trying to pass the whole string to parseDouble after all the work we have done on split. The latest code you posted doesn't even have a relevant line 43, so I don't know what code you are executing here.
Is there anybody who can sit with you and give hands-on help?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Line 24 you split on " " but I suggested split on the commas "," so try that.
Your file should NOT have any { or }

If you get an error you must ALWAYS post the full message, including the line number where it happened.

I'm sticking with this because you do seem to be trying, I'm hoping that when you get this working you will then understand the things that are currently blocking your progress, but Masijade has a good point.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

i know what are you saying , but i dont want this, suppose if i have two persons,
manager and Worker,
I want my program to ask for the name and the code only once and then show that name and code in the profile of both Manager and Worker, i hope you understand what i'm trying to say

These two persons both have the same name and code? Surely not!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If this were my code I would eliminate the confusing and unnecessary distinction between get() and getData() by naming both methods getData() and starting manger.getData() with a call to super.getData();
That way you have the same interface to get all the data for any member of this class hierarchy, with zero duplicated code.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Re-read cale's post.
You call getData() for Salary Experience Education
but nowhere for a manager do you call get() for Name and Code

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Keep debugging. That example is the right solution. Put lots of print statements in your code so you can see what it's doing.

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

Getting closer, but you still need to parse the split-up numbers in the string one at a time in a loop, a bit like this:

String[] temp;    // temp is an array, one element for each number
temp = str.split(",");  // split up using the commas as deimiters
for (String s : temp) {   // for each of the elemnets in temp
   s = s.trim();   // remove extra blanks
   Double d = Double.parseDouble(s); // parse the number thateremians
   // do whatever with d (print it first to see if its right)
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The 0,null print after 255,0.0 seems pretty definitive to me.
Use more print statements.
Your code wasn't indented, so its too hard to see where the loops begin and end, but line 123 has a j=0 to 4 loop which appears to surround the relevant area, and there's something funny about where you close the result set, but I don't know what that's all about.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I don't know how to make that any clearer without giving you the actual code - which is against the forum guidelines. Just re-read all the previous posts very carefully and slowly.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Looks like the loop is being executed twice, and has no data on the second execution.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OKI, that's great.
Two small suggestions:
you can initialise studentDB at the same time as you declare it (line 5), as in
private List<String> studentDB = new ArrayList <String>();
which is a bit easier to follow that declaring it there and initialising it in the constructor.
You have a String parameter on the constructor, but you don't use it - this will generate a compiler warning if you have the right compiler settings. Best to not have it of you don't use it.
J
ps: mark thread as solved?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

getData is an instance method, so you call it via an instance of the Manager class (eg "first"). You have called it via the name of the class, not an instance. You can only do that for static methods.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Duplicate definitions of studentDB on lines 5 and 10.
By defining a new one on line 10 that's the one that gets initialised, but it ceases to exist at the end of the constructor method.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your {} brackets are all screwed up. Go back to the tiny sample prog I gave you and fix the {} so that match the example. Start with line 13 - you have the main method's signature but the opening { for its definition is missing. Line 33 has a { that seems to be attached to nothing. Your code ends with three }}}, but the example has only two }}

Getting your indentation right is the best way to get your {} right. Indent each line when you pass a { and un-indent when you pass a }. If you get a programmer's editor or a proper IDE they will do it for you 100% correctly.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The code within a method is executed top-to-bottom. But you can define the methods in any order you like. The compiler will process them and build a .class file where they can be accessed directly as needed at runtime.