Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, you didn't ask any questions. You just posted your assignment, and certainly no one is going to just write it for you.

Post the code that you have written for the assignment and specific questions or error messages that are giving you trouble.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You have executed a new query here through your statement so the result set you obtained with that statement is no longer valid and you cannot retrieve field values from it.

stmt.execute( "DROP TABLE " + rs.getString(1));

Create a separate statement object to make your "DROP TABLE" calls with.

PreparedStatement updateStmt = conn.prepareStatement("DROP TABLE ?");

stmt = conn.createStatement();
			
rs = stmt.executeQuery( "SHOW TABLES");
						
while (rs.next()) {
    updateStmt.setString(1, rs.getString(1));
    updateStmt.executeUpdate();
}
updateStmt.close();
stmt.close();
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

In the first version you declared that the method returned a double value, but it does not return anything at all - hence that "missing return statement". If your method declares a return type, it has to return a value of that type.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You first need to create a class for the CD that stores those properties and provides methods to get and set each property.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

im doing a java project on creating a music database, i need to store an array of cd objects, each entry in the array will be a single object for a cd.
The objects are: Artist, Album, No of tracks

could sum1 point me in d right direction, thanks

There are no "sum1"s here, leave the "text-speak" at the door and ask intelligent questions if you want intelligent answers.

That said, post the code that you have so far for your CD inventory homework and specific questions about the areas that you are stuck on.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, the documentation at http://www.superwaba.com.br/en/default.asp would certainly be the best place to start. This has little to do with the standard Java APIs.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Sounds obscene :)

Yeah, it does read pretty odd. I prefer the "woohoo!" meaning myself. Old English and Chaucer can go woot themselves :P

Edit: This is getting pretty far off-topic though, I'll leave it be :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I prefer just plain "woot!", without the zeros.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The code to read into the array looks reasonable enough, though your while loop should use scanner.hasNext() to determine if more tokens are available before calling next() and you will need to guard against overflowing your array length.

The code at the top to read the text file is never going to compile for you though. There are syntax issues with your catch block declaration and you are calling method on objects that don't exist, like "out.close()". Also have no idea what IO.readString() is supposed to be doing.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

And I'm repeating my answer. I have already stated that you cannot do that with Java unless the application has a public API that allows you to make such calls like "save". Java can't just make other programs that are running do things arbitrarily.

If you have further questions, make the effort to actually write them in English instead of "text-speak" abbreviations if you want an answer. If you can't take time to write a question properly then you shouldn't expect others to take the time to respond.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Let us choose with a setting.

That seems like the best option if it is not too difficult to implement.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

BufferedReader:

try {
    BufferedReader reader = new BufferedReader( new FileReader("yourFile.txt") );
    String line = reader.readLine();
    while (line !=null){
        // do your thing

        line = reader.readLine();
    }
} catch(Exception ex) {
    ex.printStackTrace();
}

String.split()

String lineOfText = "Here is a line of text.";
// splitting on a whitespace character, you could use other delimiters
String[] words = lineOfText.split("\\s");
for(String word : words) {
    System.out.println(word);
}

Those should give you an easy place to start.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Don't use StringTokenizer, use String.split().

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ah, ok. I thought maybe what I wrote, while seeming clear to me, was far from it to anyone else :P

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

That is exactly what I was trying to say :)
Perhaps the language wasn't clear.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Perhaps she is too embarrassed that her husband stormed in to demand what is going on here.
:P

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

They're great! I find myself annoyed now at other forums that don't have them :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The thread was not yours to start with and you merely hijacked it with useless questions. Asking to have someone else's thread closed after you ruined it with gibberish is just foolish. It would have probably finished on its own 33 days ago if you had just left it alone.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Do you actually have a question then? Because every question answered in any thread in any of these forums represents someone taking some time to guide someone else.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It's perfectly fine to have return statements within if() blocks. The issue here is that there is not a guaranteed return path from the method. For instance, in the original code if inOrder.length is 0, there is no return. The compiler requires a valid return path regardless of any conditional statements and that is why you could not compile it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

help me or keep quiet i don't need your suggestions:angry:

I think you just threw all of your chances for any help here right out the window.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Unless that other application has an API that you can access, you can't make it save itself - it is a separate program.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You need to clarify that a little. Are you saying that UI updates are stopping until your button action completes? If that is the case, you need to use a separate thread to perform the button action. I don't see any connection at all to your original question about system time, so please be more specific on the problem.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, your instructions tell you to use the LinkedBinarySearchTree - so maybe that is a hint? You have read them, right?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Teacher wants us to use tokenize. I tried the split thing though and it worked, but he won't accept it.

Perhaps you should share this bit of info with your teacher. Directly from the API doc for StringTokenizer (bolding mine):

StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead.

Forcing students to learn the old way of doing something and refusing to allow them to use the new API instead is not helpful. StringTokenizer is one of the original 1.0 classes. String.split() has been in the API since 1.4, which has been out for about 5 years now. Your teacher needs to get with the times.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The entire match() function is defined within the run() function. There are enough braces to go around I believe - you just can't define functions within functions.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I know the answer on my question .

That's good - because most of us could not understand it to offer you one :P

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Does gd.getButtonValue(1) return a boolean value? Because Java doesn't evaluate such expression like C++ and some other languages where a non-zero value is true. It needs to be an actual boolean result expression.

Try to find the end of the while loop and the run() method. I think you'll find your brace problem.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yep, you are still missing the close of some block or expression. Check the braces, semi-colons, and parenthesis in the code above the public double match(String addr) line.

Strict adherence to proper indentation will help a lot in seeing structural errors like this.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I already explained the reason for that error - you have not yet initialized your panels when you call

topPanel.setLayout(new GridLayout(4, 4, 10, 10));
		bottomPanel.setLayout(new GridLayout(3, 3, 5, 5));

The code that creates those panels is several lines below those calls

topPanel = new Panel();
		bottomPanel = new Panel();
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You have to cast them to the appropriate type if you wish to call methods on them. To call ArrayList methods on an Object you retrieved you would do this

ArrayList retrievedList = (ArrayList) otherBigList.get(0);
retrievedList.someListMethod();

That's the technical aspect of it. The bigger question is why are you storing a mixed bag of stuff in a single ArrayList? Generally it's more useful to put things that share some specific interface into a collection. The nature of that interface depends on what you expect to do with them. While you can throw all kinds of things into a collection as just Objects and sometimes there are reasons to do that, you really should consider what you expect to do with them first and type the collection to the interface you need to work with.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I tried

remove(myButton);

but it says that the the method remove JButton is undefined for the type Runnable

This error is likely a result of where you located the inner class BoomThread. Inner classes have access to the methods of their enclosing class, so if it were in the class extending Frame it would be able to call that method.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I don't know what all you are swapping around there after the pause, but basically I was showing that you could swap out the game panel for the sad face panel and then swap them back. Any variations on that will depend on how you have specifically organized your components. Putting those UI changes on the event queue in separate Runnables with

EventQueue.invokeLater(new Runnable(){ ... });

allows the UI to be responsive to repaints, because those are processed on the same thread.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I think that would depend upon how long pondering the question held you up.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I am unsure of the author because it didnt state it, but anyway here it is.

Nope.
It was lame.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, the only piece of the code you wrote that will be of any use for that assignment at all is the Scanner (though a BufferedReader would be my own choice for that). The instructions are pretty clearly laid out and does tell you what you need to use from that jss2 folder.

You need to read the file line by line. The first line is the input to create the BST. For the rest of the lines you will need to parse and match the command token to the appropriate action to take on the BST. String.split() will be useful for that part to separate <command> <parameters>.

So time to crack the books and get a start on it. Post specific questions if you run into trouble. Good luck!

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you do not understand a part of his suggestion ask for clarification, but don't expect someone to write your code for you.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I tried what you suggested to no avail. When I remove the static modifiers my IDE lights up like a christmass tree with compile errors, and when I actually run the program it runs but it doesnot store the data. I recieve a print format of count = 1, null, null, 0.00. Any advice?

Of course it shows many errors, because you are also accessing all of them statically in your methods

public void setName1(String name1) {
Employee.name1 = name1;
}

You need to use them as instance variables

public void setName1(String name1) {
this.name1 = name1;
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Use String.split(), which will return an array of Strings that result from the split on your expression. You can then work with the characters in the string from that portion separately.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The null pointer error (with line number noted) indicates this is the problem

topPanel.setLayout(new GridLayout(4, 4, 10, 10));

NullPointerException indicates you tried to call a method or access a variable on an object reference that has not been initialized (it's still null). Your initialization of "topPanel" occurs 6 lines below that code, so the solution should be apparent.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You just used the wrong method call for the Frame sizing - easy to fix. setSize() will take either a (width,height) or a Dimension argument. There is another method setBounds() that takes (x,y,width,height), which is probably the one you are trying to use.

darkagn commented: As always your advice is good :) +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, since the stack trace tells you the exact problem and the line on which it occurs, this should be easy to correct with some very basic debugging. There is very little casting going on there.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, you need to create a method on the Employee class that uses the info it contains to calculate and return the weekly pay.

Your main() method should create a new Employee with the info that you are getting from the keyboard and then call the calcWeeklyPay() method that you added.

Also note that the variables in your Employee class should not be static, they should be private.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Guess I won't worry too much about Christmas shopping that year.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

and Y do u say it so...?

Because it's the truth. A quick review of your post history is confirmation.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It's the swap, pause, and replace operations all occurring within a single event on the AWT dispatch thread that is causing your problem. If you want to fiddle with the UI, wait a bit, and then fiddle with it some more you need to spawn a new thread to manage that so the AWT dispatch thread is free to respond to your UI changes.

The following will work, though since you did away with the panel to contain the buttons you will have to remove all of them and add them again. It would be easier to put them back into a panel you could swap out. I'll call it "gamePanel" in the code below

public class ButtonListener implements ActionListener {

    public void actionPerformed(ActionEvent buttonEvent) {
        // start the swap thread
        BoomThread boom = new BoomThread();
        boom.start();

        int answer = JOptionPane.showConfirmDialog(null, "BOOOoooM!!! Would you like to play again?", "", JOptionPane.YES_NO_OPTION);
        // reset or whatever
    }
}

class BoomThread extends Thread {

    public void run() {
        // replace game panel with sad face
        // this queues your update onto the 
        // thread that handles UI events.
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                remove(gamePanel);
                add(sad);
                validate();
                repaint();
            }
        });
        // pause this thread
        try {
            Thread.sleep(3000);
        } catch(InterruptedException e) {
            Thread.currentThread().interrupt();
        }
        // swap game panel back in
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                remove(sad);
                add(gamePanel);
                validate();
                repaint();
            }
        });
    }
}

You will also need to create the "sad" panel in your initialization and have the reference …

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I think most of us do care about the animals, its just that we don't care about online petetions.

++ this

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It looks like you are trying to execute that from the command line directly ("java Draw"). Applets cannot be run like that. They need to be embedded in a web page or run through the AppletViewer. You can find more info in the Applet tutorial: http://java.sun.com/docs/books/tutorial/deployment/applet/deployindex.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I cannot make the least bit of sense out of that.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Oh, hehe, I was actually just teasing - I didn't know there was ever such a function :)