Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, you are showing two different file names there, so that might be a problem. If you are having difficulties with specifying a relative file path, make sure that path resolves correctly against the current user directory, which can by checked with System.getProperty("user.dir").

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you don't even have any idea how to start, you don't really have a project. You have a name of a project.

If you don't have any idea what you want to accomplish, how do you expect anyone to help you accomplish it?

It sounds like you need to flesh out exactly what you want to do and then come back with some concrete questions that someone might actually be able to answer.

(And "every1" isn't a word - please read the forum faq and rules regarding proper English)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ok, that is because you are stuck right in the middle of things that Netbeans does to organize files in a project, which you do not yet understand, and you are trying to follow the simple notepad and command line tutorial. Either use the Hello World tutorial for Netbeans http://java.sun.com/docs/books/tutorial/getStarted/cupojava/netbeans.html or stick to the steps in the basic tutorial for Windows that you linked. Mixing the two of them is just going to cause you confusion at this point.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Are you using an IDE to create your files or just notepad? If you are using an IDE, it looks like it has placed a "package helloworldapp" statement at the top of your source file. Packages are basically directories to group sets of classes together. Because of that package statement, Java expects that class to reside in the "helloworldapp" directory. It would need to be run from the directory above "helloworldapp" with the following command:

java helloworldapp.HelloWorldApp
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ok, it actually looks you may just have a case-sensitivity issue with your names. If the class is called HelloWorldApp, it must reside in a file of that exact case-sensitive name. You must use the same case-sensitive name when you run it. "helloworldapp" is not the same as "HelloWorldApp".

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Are you running that command from directory which contains that class? Is there a package declaration in that class?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This is a class path problem. The class path let's Java know where to locate classes for your file. Post the command that you are using to run the program and a bit of directory information on where that class file resides.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you have added println statement to verify str, start, and end then you should know exactly what string input is returning a -1 for which indexOf() call. You have all of the variables there leading to that error, so you just need to figure out why that particular string input is yielding the -1. Are you certain that the final value of "str" is not an empty line or one which has improper quotation marks?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Did you read the api on indexOf() and the conditions under which it will return a -1? Have you added System.out.println() statements to verify your parameters to indexOf() and substring().

You keep posting "I can't figure it out", but do not say what you have tried to do to solve this on your own. There is a point to learning how to debug things like this for yourself and we have tried to guide you towards this as much as possible without simply giving you the answer.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Carefully read the API documention on the indexOf() method you are calling and the reason for the -1 should be quite clear. From there it is a matter of determining why that is the value you are receiving.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

String.indexOf throws a StringIndexOutOfBoundsException when either the index parameter is < 0 or > than the length of the String. Hence, make sure to check the indexes before sending them to the indexOf method.

indexOf() does not throw StringIndexOutOfBoundsException.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Also, consider you can use a switch in applyOperation()

switch (op){
    case '+':
        // stuff
        break;

    case '-':
        //stuff
        break;

}

Another possibility is to define your own Actions for each of those buttons

class PlusAction extends AbstractAction{
        public void actionPerformed(ActionEvent e) {
            System.out.println("do plus action");
        }
    }

and set that action on the button with

button2.setAction(new PlusAction());

(edit: You still really need to ditch the "button2", "button_3" variable names and make them "btnPlus" or "buttonPlus" or something. Meaningful variable names go a long way towards making your code easier to understand - not just for others, but also for yourself)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You cannot declare a method within a method like that, which is what this line is trying to do

public void actionPerformed_Plus()
nljavaingineur commented: Promply helpful +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Have you looked up what StringIndexOutOfBounds means, the method call that is throwing it and which line it is occurring on? The stack trace will tell you the last two of those. This is just basic debugging that you need to learn to do on your own. The exception message even tells you the index value that was out of bounds and some adding some basic System.out.println() statements can help you know the string and indexes that are causing the problem.

If you continue to have difficulties with it, post back the code, the exact exception message, and exactly what you do not understand about it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You may also want to consider using the Scanner class with regular expressions.

And once again I'll request:
Please use [ code ] tags to format code in your posts so indentation is preserved.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The problem is that here

if(itemCount == item.length)
Doll [] temp = new Doll[item.length * 2];

you are just declaring a variable - not performing any useful operation. That variable will go out of scope immediately after it's declaration. I think what you actually want is this block

private void cpyArray()
{
    if(itemCount == item.length){
        Doll[] temp = new Doll[item.length * 2];
        
        for(int i = 0; i < item.length; i++)
            temp [i] = item[i];
        item =temp;
    }
}

(And please use [ code ] tags whenever you post code to the forums.)

Edit: Also, consider that you can use System.arraycopy() or Arrays.copyOf() to copy arrays without having to loop and copy every element.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Take a look at the following re: equals() and hashcode()
http://www.ibm.com/developerworks/java/library/j-jtp05273.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Correct, you want to set liste = new ArrayList(). Until you set the liste reference to point to a new ArrayList, you'll be operating on the same one as before.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You may want to update to 1.6.0_04 and see if that solves the JVM crash. I assume you are running the latest JACOB build.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You need ArrayList<Long>. Long is the wrapper class for the primitive long. Autoboxing will convert your long values to Long for you when you add them to the ArrayList.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Relatively speaking, no, your code is not "quite large". Post it here if you have questions about it. Forum rules dictate that requests for help should remain in the forums so all may participate.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

With x++, the value of x is evaluated before the increment. With ++x, it is evaluated after.
So

int x=0;
System.out.println(x++); // prints 0, x now = 1
System.out.println(++x); // prints 2, x now = 2
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Read the API link. There are a few examples right there in the class description.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Use Scanner to readInt() input after printOptions() and you will be all set.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

hej i am an good student but i am on the first year and in ouer country this an experimental class we have no books no materials nothing thats why i dont have any idea about the project so if some one helps me would be very kind

ps: I m not stupid at all

You have not even asked a question yet. You merely posted an extremely vague description of an assignment. Do you expect us to just start coding whatever we think a solution might be and post it here for your inspection?

If your class has no books or materials, how is it a class at all? Do you not have notes from a lecture at least? Those are materials. Did your instructor walk in the first day and exclaim "make a matrix in which a number moves some kind of snake"? If so, perhaps you should have left the class?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

C++ or Java will be the most useful to learn for future coursework, though PHP, Ruby, and Python are fine for getting your feet wet in a scripting language.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Bah, my bad, that should be a period - not a slash - to denote the package of the class. This is what it should be

F:\DCTM_WORK>java FlightReservationDesktop.Reservation
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Try

F:\DCTM_WORK>java FlightReservationDesktop/Reservation
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Instead of extending MouseAdapter, you could just have that class implement ActionListener and put the code in mouseClicked() into the actionPerformed() method. Then use a new instance of the class instead of "this" for the argument to button[index].addActionListener().

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If the program would crash if you used the base class on it's own, then it sounds like some required function of the class remains unspecified. If child classes provide that necessary functionality then the methods to do so should be abstract. Without knowing what additional functions the child classes are providing it's difficult to give a definitive answer.

If the base class can be used on it's own then it does not need to be abstract at all, as AD pointed out.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Check your spelling. The correct class is "ArrayList".

The last error means that you've extended a class that has an abstract method in it, which requires you to implement that method, but you have not written that method in your class.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, I don't see that you have declared "prylar" anywhere, yet you are using it as a class-level variable.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You still haven't posted the code here.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

As I've indicated twice now, you need to post the code here and specific questions about what you are having trouble with. "Having trouble with case menu" isn't all that specific. What piece do you not understand about it?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Try to narrow the relevant code section if it is overly large or provide a skeletal portion of it as needed and post it here. Questions should generally be kept on the forums so that all can participate or view the suggestions offered. Personally I never provide code help via PM.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Post the code that you have and what problems you are encountering. Please put [ code] tags around any code you post.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Not from the ChangeEvent supplied by columnMarginChanged() unfortunately. In most case, the resize affects more than one column at the same time, so it's up to you to handle a particular column on your own. I fiddled with a few things but didn't come up with a clean way of avoiding that circular cascade in the resizing and still have it resize to fill the pane after they are done trying to make it smaller. That's to be expected though since they are actually fighting against the listeners with the mouse to drag it smaller and the code is just trying to respond the way you want it to.

This change

if (diffWidth > 0) {
    int newWidth = tc.getWidth() + diffWidth - 3;
    tc.setPreferredWidth(newWidth);
    tc.setMinWidth(newWidth);
}

does prevent them from making it too small to fill the pane, but if the min size gets larger from a panel resize, it can't be set back to a smaller size later. It becomes a one way street in that respect.

A relevant question might be though, if the user intentionally makes that column narrower and it doesn't fill the pane, should you care enough to prevent it?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Try this

Component c = evt.getComponent();
int viewWidth = c.getWidth();
int tableWidth = libraryTable.getWidth();
int diffWidth = viewWidth - tableWidth;

if (diffWidth > 0) {
    TableColumn tc = libraryTable.getColumnModel().getColumn(libraryTable.getColumnCount()-1);
    tc.setPreferredWidth(tc.getWidth() + diffWidth - 3);
}

The magic number 3 is just there to keep it from being just a tiny bit wider than the internal display area and forcing an unnecessary scroll bar (I didn't spend the time to find out which component width was causing it - probably just a border or inset on one of them).

That does still allow them to manually make the last column narrower than the scroll pane. If you really want to avoid that you would need to call this when a column is resized as well.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No, sorry, it won't. I should have checked it before suggesting.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Have you tried setAutoResizeMode(int) using AUTO_RESIZE_LAST_COLUMN ?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you just want to return an element if a certain value matches either of two fields, all you really need to do is this

public KasseInterface søgVare(String value) {
    for( KasseInterface elem : varer ) {
        if (elem.getVarenummer().equals(value) || elem.getVarenavn().equals(value)) {
            return elem;
        } 
    }
    System.out.println("fandt ikke nogen vare!!!");
    return null;
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you take a look in your JDK installation folder under "demo\jfc\TableExample", there are several table example programs, including a TableSorter.

I've also attached a zip file containing a JSortTable implementation from Java Pro magazine. I was going to link to it in the archives, but it seems Java Pro got swallowed up by another company and I can't locate the archives.

Edit: Oops, guess you found something hehe. Didn't know they had rolled that into the api in 1.6.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

@Ezzaral..

thanks...it was a silly mistake..it worked...

well i want to ask one more question ...i m using jCreator for this...if i want to run it using command prompt i have to change the directory to bin folder of jdk everytime i run cmd...

how can i set path for this forever...

Add your Java /bin folder to the system path in your environment variables. This is described in more detail here if you need it: http://java.sun.com/javase/6/webnotes/install/jdk/install-windows.html#Environment

@Ezzaral
well one more thing i wanna ask
why didnt it give a compile time error...

It did not complain because your method was still a valid one - just not the one that you wanted to override. You supplied an new method called pain() and the compiler was just fine with that.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

> public void pain(Graphics g)

I think you meant to type "paint" here instead of pain. :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Thank u for helping me.
I knew this is sorting , but I didn't know how we wrote it .

Can u explain for me that, please?

Thank u.

You have the code right in front of you, just read it. Trace the loops if necessary to see how the elements are being compared and sorted. Add more println output to show you what is going on in the inner loop. You'll learn more if you walk through and understand it on your own.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Coding every little thing from scratch is useful when learning the language. When you are employed developing an application with 800+ classes, anything that saves time is very beneficial. Things such as code completion, auto-generation of getters/setters and overriding methods, automated refactoring, GUI builders, debugging and profiling tools, and many more. At that level, it's a matter of productivity and if you aren't using the tools available then you're wasting time.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I use Netbeans. Eclipse is just fine as well, but I never really took to the Perspectives thing. Also, ctrl-k for word completion is very addictive for a lazy typist like me :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

As far as the score, it will depend on how you wish to delineate the class responsibilities. Should Saucer report its score to the menu when the game is finished or should the menu have to ask Saucer what the score was after the games is ended. This leads to the question: does SaucerMenu know when a game is running and when it ends?

Deciding upon clear responsibilities for the entities (classes) in your program and ensuring that those entities maintain that contract of separate responsibility in their interactions is an important part of program design.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You seem to have misunderstood my suggestion to incorporate the Saucer game class into the SaucerMenu. I was implying that you really only need a single frame for the menu and game. Just moving the Saucer class definition to be an inner class of SaucerMenu doesn't really help you much as you are still managing two frames and now you have even more nested class levels to keep straight.

Of course, Saucer does have direct access to the internal methods and state of SaucerMenu now, but it probably shouldn't from a design standpoint if you intend to keep it as a separate class and you are still using it as such. If you wish to keep the menu and game frames separate, you may as well put Saucer back into its own file for clarity and to avoid the unnecessary scope nesting of multiple inner classes.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ok, here are some basic changes to get you started in the right direction. Saucer now takes a reference to its SaucerMenu from the constructor, so it can interact with the menu. I've put a returnToMenu() function in that is called when the Saucer frame closes and from showScore().

showScore() was always getting called regardless of whether (lives==0) because you had a semi-colon after the if() condition - essentially an empty statement and what should have been a conditional block was just a regular nested block.

I've put a couple of comments in where I altered things. Now you will need to create some method in SaucerMenu that Saucer can call to report the game score when it closes. That method can also check against a collection of high scores and update it if needed. You'll probably want to write that to a file when the program closes and read it on start up.

Another consideration is just making the game panel be part of the SaucerMenu class instead of a free-standing JFrame, which would do away with the need to interact between the two altogether.

I see that you still have game logic in your paint() method as well. That really should be moved to it's own method separate from the rendering. Your game loop (the animation thread) needs to evaluate the game logic each iteration, update game state, and then trigger repaint. Clean separation of these responsibilities will make your code easier to manage.