JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

DaniWeb Member Rules:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/forums/faq.php?faq=daniweb_policies

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 coding your homework for you.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Got more time now - so a better answer:
You are trying to create a Vector of Vectors, the "inner" Vectors representing individual rows. This means you MUST create a new Vector for each row. If you add the Vector for the first row, then clear its contents, you will lose the data for the first row.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You didn't declared it. just declare it in the main method

No no no. You haven't followed the whole conversation here.
The program needs one variable in the main method PLUS a local variable in the getPayment method. The original problem came from trying to pass the main method's var in as a parameter rather than creating a local var in getPayment.

BaldingEar commented: very helpful +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You still have those myXXX names where you should just have the names of the parameters in the methods, and you have not declared the variables you use for the return values. Compile your code before posting it - the compiler will tell you about errors like those.
Because all your methods are static you don't need to create any objects.
Every Java program needs a "main" method. You must have seen this in your course so far. In your main method you can call your other methods, passing in test data, and print the results they return.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You add two panels to your window, which appears to have the default (ie Border) layout. You don't specify where to place them so you get the default value, and they are both placed in the same place, so you only see the second one.
Two better ways to do this:
1. Have 1 panel with a paintComponent that paints the background and the player (which could be delegated to the player class)
2. Have the background as a panel, and make the player a JLabel placed in the panel. You could either override paintComponent for the label, or maybe make your player graphic an ImageIcon and use JLabel's normal painting. This solution is also easier if you want to do things like clicking on the player, or dragging it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your methods need some work:
You should do the calculations using the values that are passed in as parameters
You should return the answer via a "return" statement.
So - you don't need any of the variables you declared on lines 3-9

When you have fixed these you can write a main method that calls your methods with some test values and prints the returned values.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You may need to setFocusable(true); on your JPanel followed by requestFocus();

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Simple way: create the object as a JLabel with an ImageIcon. Put it in a JFrame. In response to keyboard input use the JLabel's setLocation method to move it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, good luck.
I'll check in on this tomorrow morning.
J.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Here's the first

javax.swing.table.DefaultTableModel defaultTableModel = new javax.swing.table.DefaultTableModel();

and this creates a second new one for your JTable

Object rows[][] = { { "AMZN", "Amazon", "67 9/16" ,"DELETE","UPDATE"},
{ "AOL", "America Online", "68 3/4" ,"DELETE","UPDATE"},
{ "BOUT", "About.com", "56 3/8" ,"DELETE","UPDATE"},
{ "CDNW", "CDnow", "4 7/16" ,"DELETE","UPDATE"},
{ "DCLK", "DoubleClick", "87 3/16" ,"DELETE","UPDATE"},
{ "EBAY", "eBay", "180 7/8","DELETE","UPDATE" },
{ "EWBX", "EarthWeb", "18 1/4" ,"DELETE","UPDATE"},
{ "MKTW", "MarketWatch", "29" ,"DELETE","UPDATE"},
{ "TGLO", "Theglobe.com", "4 15/16" ,"DELETE","UPDATE"},
{ "YHOO", "Yahoo!", "151 1/8" ,"DELETE","UPDATE"} };
Object columns[] = {"Sr.no", "Book Title", "Author Name", "Delete", "Edit"};
JTable table = new JTable(rows, columns);

You need to put all that data into defaultTableModel then do a

jTable1.setModel(defaultTableModel);
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You still have two models. You need to put all that data into defaultTableModel

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Please read my first post. You have two table models in your program. You should have only one. The data is is the one you display, but you try to remove from the other one, which has no data.
Norm - I don't know how to make this clearer - can you help?

sohiabmaroof commented: 1 +1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, well, I didn't see any code to put any data in defaultTableModel, so I'm not surprised that trying to delete a row gives an error.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have to do the same thing - subclass them with a custom paintComponent.
BTW, if you're on Java 7, take a look at the new shaped/translucent window support.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

After that input you call the method at line 30 which will drop thru to the while at line 47. Which is a very interesting loop
while (tallPosisjon <= famousFinalFour.length())
neither tallPosisjon nor famousFinalFour seems to change inside the loop, which means if it executes right thru once it will loop infinitely - isn't that your symptom?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

First pass thru the loop i is 0, Data[i-1] is Data[-1] -> ArrayIndexOutOfBoundsException: -1

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

args is declared in your code, but it is inialised at run time with copies of the arguments that were entered on the command line. If there were no arguments it's initialised to an array of length zero (not null, just an empty array). So an attempt to reference the first element of the array [0] is an index out of bounds error.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Did you mean BigDecimal? That would certainly be an appropriate class for currency.

mKorbel commented: correct +9
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm having trouble sorting names in alphabetical order using counting sort

Not surprising really - the counting sort algorithm is for sorting small integers (or objects keyed by small integer keys). Are you sure you are trying to do the right thing here?

ps This is a cross-post, please check the DaniWeb Member Rules.
http://stackoverflow.com/questions/7564973/name-sorting-using-counting-sort

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Looks like you keep adding all the data to the vector v, but you need to clear that down (or start a new vector) for each line.
Also you are creating the table inside your read loop, so you create new one each time ou read a line, but you should do this just once, after the loop

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

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 has a constructor that takes a Vector of Vectors as a parameter to supply all the data in the table. Each "outer" Vector represents on row, and the "inner" Vectors have the individual cell values for that row.
So instead of reading your data into an array, read each line and and add it to a new Vector<String>, then add that Vector to a Vector<Vector<String>> which you can pass directly to JTable.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If yo are new to Java then a full-featured IDE like NetBeans or Eclipse is not a good idea. It will overwhelm you with features you don't understand yet, and block your progress by making suggestions and corrections that you haven't learned yet.
For now, just stick with a good editor and the standard JDK compiler.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

My (version 7) javadoc for AudioClip has three methods in it. How many has yours? What are their names?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's right. One array holding lots of Animals. Each Animal has its own name, weight etc with methods to get those values when you need them

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

All you need to know is "null pointer exception on lines 17, and 22"

That's a response that won't help you. You may think you know what we need to know, but if your knowledge was complete and correct then you would also know the answer to your problem.

Making something static won't cause an NPE.
The lines you refer to contain no object references, and are therefore most unlikely to cause an NPE.
The lines you refer to DO contain undefined variables (as I explained in a post to your earlier thread on exactly the same subject), but these will produce a "cannot be resolved to a variable" compiler error message and prevent you executing the code, thus making it impossible for you to generate any NPEs.

If you would like any more help, please post the exact complete error message and the exact complete code that caused it. We can then decided what we need to know to answer your problem.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Very odd. What did you do to be certain that it's null? What OS are you using?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You declare

ArrayList<Customer> cl=new ArrayList<Customer>();
ArrayList<Book> bl=new ArrayList<Book>();

inside the main method, so they are local to that method. If you want to access them from all the methods of the class they need to be declared outside any one method - like the variables in your Customer and Book classes.
ps Please write your posts in normal English, especially for the benefit of the majority of DaniWeb users for whom English is a foreign language.
pps: having variables called c1 and cl, b1 and bl is probably the most ingenious stupid idea I have seen in a long time!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Eclipse/NetBeans - very similar in capabilities etc, so either will do, but I agree with your instructor who says "yes, but not yet".
(If you are already used to Eclipse then that's OK, but don't try using any GUI builder/code generation tools yet).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No so obviously. There's absolutely no reason why you can't have a Vector of Vectors. Just remember that you have to populate the outer Vector with new inner Vector(s).

Vector<Vector<String>> v = new Vector<Vector<String>>();
v.add(new Vector<String>());
v.elementAt(0).elementAt(0) ...
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Border layout is OK to get started, but if you're interested in good layout you soon run into its limitations. The ultimate manager is GridBagLayout, which will do anything you can dream of, although at the cost of a steep learning curve at the start. If you are going to do more layout-critical work in the future I would advise getting to grips with gridbag sooner rather than later, and don'w waste time on the simpler ones that you will outgrow anyway. If this is just a one-off throw-away projectthen maybe ignore layout managers and use absolute positions.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Line 17 readLine returns "2 3", so parseInt throws an error. Your code would work if you typed one number on each line, or if you used an input parser that has methods like nextInt

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

First: the getName method is incorrectly defined as static. That's wrong - it doesn't apply to the whole class, but to each individual instance. Ditto the variables - they must not be static - each instance of Staff has its own name and ID.

for( int i = 0; i < array.length; i++) {
    System.out.println(array[i].getName());
}

Each element of the array is an instance of Staff, so you can call Staff's methods directly on the array elements.
You don't need to convert to an array - the for-each loop wprks well with your arraylist

for (Staff person : staff) {
   system.out.println(person.getName));
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK hfx.. I've just been made "member of the month", so I'm in a really really good mood. Here's some code as a free gift from me (non-commercial use only).

// ChangeListener implementation
   
   ArrayList<ChangeListener> listeners = new ArrayList<>();
 
   public void addChangeListener(ChangeListener listener) {
      listeners.add(listener);
   }
   
   public void removeChangeListener(ChangeListener listener) {
      listeners.remove(listener);
   }
   
   void notifyListeners() {
      // call this whenever data is changed
      ListIterator<ChangeListener> iterator = listeners.listIterator();
      while (iterator.hasNext()) {
         iterator.next().stateChanged(new ChangeEvent(this));
      }
   }
mKorbel commented: heheheh good one :-) +9
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can simplify this to two cases as follows:

NB: keep track of how much space is remaining on the current line at all time
split input into array of words
print the first word
for every remaining word:
  if it fits print " " + the word
  else print "\n" + the word

where "it fits" is a function of the length of the word vs the space remaining
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's what I suspected. Just take a pace backwards and look at this from a higher level. You don't want to know about the individual buttons firing - that's just part of the internal implementation of your new component. You want to know when the value of the variable in the component has changed, and don't care if that was from a button, an up or down arrow key, mouse wheel scroll, or any other user interface you may implement now or later. You just want a ChangeListener on the component.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Aviras is right. The OP's code includes
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
so this looks like Swing, in which case it's already double-buffered unless you have explicitly turned off double buffering.
It's almost always a mistake to override paint, you should override paintComponent instead.
Overriding update(Graphics g) is futile, as update is never called for a Swing component.
http://java.sun.com/products/jfc/tsc/articles/painting/#swing_summary

Finally liones 10-12 in your latest code

catch (Exception e) {
 
}

is a terrible mistake. Put the printStackTrace back and don't remove it!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Because your dates are in a known fixed format, it's easy to use the SimpleDateFormat class to convert the String to a Date, and vice-versa. Java Dates are essentially millisecs since some arbitrary zero point, so you can do arithmetic on them. For more interesting date manipulation convert to a GregorianCalendar object, which gives you methods for adding numbers of days/weeks/months to a date while automatically dealing with the variable number of days in a month, leap years etc.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

AFAIK there's no sensible way to merge cells. The only work-around is to use a custom cell renderer and work out what to display in each of the individual cells so it looks like they are combined into one. - not easy or elegant, but possible.

Setting background color for individual cells is also a custom cell renderer thing, bit this time it's fairly straightforward.
http://download.oracle.com/javase/tutorial/uiswing/components/table.html#renderer

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hint:

if(numstreet == 1)street = "Port Washington Boulevard";
else if(numstreet == 2) street = "Main Street";
etc

You should use an array of Strings for this:

String[] streets = {"Port Washington Boulevard", "Main Street" ...
street = streets[numstreet-1]; // first element is number 0

Simple way to save the number is to print it to an ordinary text file, and read it back in with a Scanner (not necessarily the "best" way, but it leverages knowledge you already have for printing and reading from a scanner). You need to create a File object referring to the file where the info is stored. Create a PrintStream to that file so you can print to it, or create a FileInputStream using the same file so you can create a Scanner to read from that stream. You'll find complete documentation on all these classes in the Java API documentation, and/or you can Google for examples.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

(Norm: am I going bonkers here? Why no NPE's?)

TVShow[] myShowArray = new TVShow[TV_MAX];
..
for(d = 0; d < TV_MAX; ++d)
..
  myShowArray[d].setShowName(tvInput);

This shouldn't work. Have you been ignoring null pointer error messages?
Line 1 creates an array of TVShow pointers, initially all null
Line 3 tries to call a method on an array element BUT the array still just contains null pointers. This should throw an Exception.
You need to add a new TVShow to each array elements before using it, as in

TVShow[] myShowArray = new TVShow[TV_MAX];
...
for(d = 0; d < TV_MAX; ++d)
   tvInput = JOptionPane.showInputDialog(null, "Please enter a television show: ");
   myShowArray[d] = new TVShow(...);  
   myShowArray[d].setShowName(tvInput);
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

@soham.m17: How about an update on this? What did you do in the end? How did it work?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Create an array of doubles.
loop quite a few times 
  generate two random ints 0 to (array.length-1)
  swap the array elements at those two indexes

result: a shuffled array of doubles.
What's so hard?

ps Or use Collections.shuffle with your doubles wrapped in Doubles

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

... or, since this is 2011, you can use the enhanced for loop from Java 1.5

A common solution to this problem is to make a copy of the original list and iterate thru that while updating the original.

ArrayList<Mouse> master = .....
ArrayList<Mouse> copy = new ArrayList<Mouse>(master); // copies references from master
for (Mouse m : copy) {
  // access Mouse m, do anything with master
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

@slasherpunk
Do you have any authoritative source for that claim?
Do you want to consider the difference between a character reading stream and byte-oriented reads in terms of localisation and non-english character sets?
Do you want to explain how to do character-oriented parsing on a byte array?

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

You can use any language you want for any text you display to the user. You just need to check that the font you are using has all the necessary characters. French accented characters should be OK on any American or European operating system version.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Create a BufferedImage object, get its Graphics2D
http://download.oracle.com/javase/tutorial/2d/images/drawonimage.html
use your existing paintComponent method to draw the panel on that Graphics2D
save your BufferedImage to a file
http://download.oracle.com/javase/tutorial/2d/images/saveimage.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You could use the transform(AffineTransform at) method on your Path2D star1, with an AffineTransform obtained from AffineTransform.getRotateInstance(double theta, double anchorx, double anchory) to rotate it by any desired angle

AffineTransformations look very scary, and often they are, but in essence they take a shape and change it by stretching, skewing, sheering, rotating etc. All you need is a simple rotation, which the method I suggested will give you.

API documentation is in the usual place.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sleeping in a Swing GUI usually stops everything from working by blocking the Event Dispatch Thread ("Swing thread") on which Swing handles everything. Its never a good idea. Use a javax.swing.Timer to implement delays and repeated processes.