Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Use English, not "text-speak", and first make your own attempt at your homework. Please read the rules and FAQ for the terms of the forum.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You need the mysql-connector jar in your class path. http://java.sun.com/javase/6/docs/technotes/tools/windows/classpath.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Trying to Find the imp in the system that has been Needlessly Capitalizing Words and stealing Punctuation

Whats Up With You

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Hi guys...

This is a petition against the live skinning of cats,dogs and other animals in China.

Of course it's live skinning - the dead have a hard time handling knives.

Please be aware if you click on the video it is VERY GRAPHIC - the most disturbing,graphic video ever

Ever? or EVVAAAARR?

Please take a few minutes and help try to make a difference.....

I could see helping to make a difference or trying to make a difference, but to "help try" seems rather lame... like the petition itself.

Thank you and god bless all

Not garnering much support from the atheist corner here. ;)

scru commented: Not ganerning support from the Cristian corner either. He didn't captialise "God". +3
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, I guess that depends on what you have covered in class so far. My guess would be simple file I/O with a BufferedWriter.

Review your class notes.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It won't work for you like that because you are trying to execute the frame display and the pause all on the AWT event dispatch thread. I'd recommend either swapping out the panel that displays the buttons with the sad face panel or use an icon for the sad face and set the bomb button icon (or the Boom! dialog icon) to that icon - unless you want to get into the threading issues that are preventing that code from working.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can't set the system time in Java without making system-specific calls through a Process or with JNI.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

"test" is your HashMap. It is not an object of the class that has the getDesript() method. That is why my example showed the cast of test.get(key) to (WhateverClassThoseAre) before making the call to getDescrip(). The value stored by HashMap is Object. You have to cast that to the appropriate type before you can call methods provided by that type (If you are using generics to type the HashMap that cast is essentially made for you).

The "set up" I showed

hash2.put("elephant", ((WhateverClassForAnimal)hash.get("elephant")).getDescrip());

will allow you to call that getDescrip() method if you cast it appropriately - which I cannot show explicitly because I have no idea what class that value is.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

On a side-note, change your class name and variable names to something less meaningless. Descriptive names for classes, variables, and methods are immensely helpful to both you and others who read the code.

Also, after 22 posts here you should get familiar with [code] [/code] tags and use them.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Post the "MySadFace" code as well.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Then perhaps you are not searching very effectively because a simple search on JAI edge extraction or jai edge detection located the following information easily:

Using JAI's built-in GradientMagnitude operation for edge extraction
and
An example of a simple ColvolveOp with the Sobel operator.

This site seems to have a ton of JAI stuff including template matching and segmentation algorithms:
https://jaistuff.dev.java.net/algorithms.html

(Note: Future questions with "u", "plz", "abt" and other such IM-speak will not receive any response. If you are too lazy to use proper words in your question than I'll choose to be too lazy to answer.)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

And what problem would that be? The JVM manages the memory allocation when an object is created and the garbage collector frees that memory when there are no more references to the object. What exactly is your question?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ok, here is what is causing that

add(cpanel,BorderLayout.CENTER);
add(fpanel,BorderLayout.CENTER);
add(btnConvert,BorderLayout.CENTER);

You are adding all of those components to the center. BorderLayout does not stack those in sequentially like FlowLayout does. You are placing them on top of one another. If you change it to this you will see that is the case

add(cpanel,BorderLayout.NORTH);
add(fpanel,BorderLayout.CENTER);
add(btnConvert,BorderLayout.SOUTH);

The rest of that code is fine. You probably want to apply a DecimalFormat to limit the number of decimal places displayed and you could tweak the layout a bit more, but the code itself works.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you passed the animation reference to the Timer as a final reference (which would have been required for an anonymous inner class for the ActionListener), then you can't re-instantiate that reference and have it still work in the Timer.

Have you tried recreating the Timer?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Then post what you tried, because there is no attempt at that in the code you posted above and we can't just look over your shoulder.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

So just have your listener set the text on that field. What are you finding confusing about it?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I would guess their policy does not extend to personally installing keyloggers for the purpose of intercepting passwords though.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Problem resolved. It seems my supervisor thought it would be funny if he put a keylogger on my computer and kept giving the passwords to this kid so that it would confuse me.

I would be looking to get a new job if my supervisor "thought it would be funny if he put a keylogger on my computer".

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You could use a while loop, but with arrays a standard for() loop or a foreach loop is usually preferred.

A do while loop is seldom used to loop an array because a do while always executes at least once before the test and you would have to make sure there were elements in the array before the first iteration. It would just add extra unnecessary code.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Not sure what you are doing with the "hash.t..." stuff there and the whole operation seems odd, but this will put "elephant" and it's value from "hash" value into hash2

hash2.put("elephant", ((WhateverClassForAnimal)hash.get("elephant")).getDescrip());

If you typed the HashMaps with generics then you can drop the cast to WhateverClassForAnimal.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

See the api for DecimalFormat.

Also, after 50 posts, you should be familiar with [code] [/code] tags - use them.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

JAI offers plenty of functions for your task, but if you are expecting to find some "MatchImage" API you are probably out of luck. You have to code such algorithms yourself because there are many ways to go about it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Your question is not clear on what you want to do with the extra text field, but you are already manipulating two fields just fine. Why can you not just add the third and do whatever you want with it? What is giving you difficulties?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Move the code that creates the buttons into the init() method and add the listener after you create the button. Leave the variables at the instance level where you have them, but put the myButton1 = new JButton("1"); part in init() so it only gets executed once.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

As far as managing the entire game state, here are some things to consider that would make it much easier on you if you wish to tackle them.

1) Use an array for all of the buttons

JButton[] buttons;

Your setup code just needs to loop that array and create a new button for each element.

2) You only need one button listener for all of the buttons. The only part of the code that differs is the response for a bomb or a win.

public class ButtonListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            boolean gameOver = false;
            JButton clickedButton = (JButton)e.getSource();
            if(clickedButton==bombButton) {
                // you got the bomb - see #3 on this
                ...
                gameOver = true;
            } else { // for you to figure out

The part for you figure out is how to tell a win. Hint: The number of plays (button clicks) will equal the number of buttons if you only count clicks on buttons that haven't been played before.

3) A single reference for the current bomb button. Since you have all of the buttons in an array, you can choose a random number against the array length and assign that button to a reference for that game

JButton bombButton;

On a new game, choose a new random array index and set the bombButton to that button.

bombButton = buttons[ yourRandomInt ];

If you do those things, you don't have to randomize the actual buttons at …

jasimp commented: You are the main source of accurate help in the Java forum +6
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ok, several small things. In the setupGame() method, after you add the panel to the container, you need to call validate() for it to update it's component layout (this will also cause a repaint so you don't have to worry with that)

add(p1, BorderLayout.CENTER);
validate();

Second, you are setting the background colors on the buttons to white or black in the ActionListeners, but you don't set them back in setupGame(). Those will need to be reset to their default color. Additionally, you add the button listeners to the buttons in setupGame(), which means they get added each time you call that method. If you call it three times you end up with three listeners, all doing the same thing, on the buttons. This means the action will fire three times for a single click - not what you want. Add the listeners to the buttons just once in some other method. Perhaps a setupButtons() method or in init() for the moment.

It might reflect the program flow a little better if you had a setupButtons() method to build the buttons and attach the listeners. You may want a resetButtons method that changes all the background colors back to the start color. Then rename setupGame() to startGame() (yes, I'm picky on naming methods according to exactly what they do). Remove the code that adds the listeners from that code and place a call to resetButtons() before you place the buttons on the panel.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

All of this portion could go into a method called setupGame()

JPanel p1 = new JPanel(new GridLayout(3, 3));
		int randomNumber = (int)(Math.random()*9)+1;
		
		if(randomNumber == 1){
			p1.add(myButton1);
			p1.add(myButton2);
			p1.add(myButton3);
			p1.add(myButton4);
			p1.add(myButton5);
			p1.add(myButton6);
			p1.add(myButton7);
			p1.add(myButton8);
			p1.add(myButton9);
		}
		
		if(randomNumber == 2){
			p1.add(myButton2);
			p1.add(myButton1);
			p1.add(myButton3);
			p1.add(myButton4);
			p1.add(myButton5);
			p1.add(myButton6);
			p1.add(myButton7);
			p1.add(myButton8);
			p1.add(myButton9);
		}
		
		add(p1, BorderLayout.CENTER);
		
		myButton1.addActionListener(new ButtonListener1());
		myButton2.addActionListener(new ButtonListener2());

Keep an instance-level reference to the panel which is to contain the buttons. Before the statement that creates the panel, place a call to remove that panel first like so

if (gamePanel != null){
          remove(gamePanel);
      }
      gamePanel = new JPanel(new GridLayout(3, 3));

(Yes, I renamed the panel "gamePanel" because "p1" means absolutely nothing. Use meaningful names for variables so you remember what they are for.)

As for the button code, they really could share the same listener since they do the same thing. Also, you can just create an array of JButton[] to hold them and randomize the index selection to place them on the screen instead of hard-coding all of that.

majestic0110 commented: This guy is the best! +2
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You have both DieDisplayInterface and DisplayDieInterface shown there - which is it?

The fact that the confusion arose at all is a clear sign that you should consider a better name for the interface. Is there more than one class that implements the interface? If not, will there be? If both answers are no then you don't even need a separate interface definition.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Because you are calling nextLine() on the scanner and that method returns a String, not a char

char chars = scan.nextLine();

Capture a String instead and use String.charAt(0) to get the first char.

String input = scan.nextLine();
char choice = input.charAt(0);
switch (choice) { ...
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

That depends entirely on the constructors you have written for DisplayDie and DisplayPanel.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Doing your own homework would benefit you more. Give it a try.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Take the code that is in main() and place it into a method in the ReadImg class. Create an instance of ReadImg in main and call the appropriate methods on it as needed. The main() method is nothing more than a static access point to set up the object(s) needed to run the program. All other operation should occur inside those objects.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Also, this piece of code is not doing anything useful at all

for (int count = 1; count < 360; count ++)
{
	if (count == 15) 
	 break;
};

It just counts from 1 to 15 - nothing more.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It's an invalid method signature. You have no type for the parameter and you have a semi-colon between the parameter list and the brace that begins the block.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Just put the common code into it's own method separate from the code that creates and adds the components to the container.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Like I said - it depends on your initialization code. There is not anything like a "reset()" method. You simply set your panels and controls back to whatever state they should have at the beginning of your game. If you post the code for "myFrame" we may be able to offer some more specific advice.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Just waiting till Google comes out with their neat no nonsense (NNN) OS.

Named HAL...

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The code has numerous issues with empty blocks, misplaced semi-colons, missing braces, etc.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It doesn't need to be reloaded - it just needs to be reset. How to do that depends upon how you have structured the code that initializes it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This is your third thread on the exact same issue and this has been answered in the other two already.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The demo class needs to create "Ages" objects and use the methods you have defined. As written your demo just defines some variables and prints the "avgAge" - which is still 0 because you haven't done anything with it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

"nam" and "pas" are both still null at the class level because you re-defined these variables locally in your constructor when you added them to the panel.

TextField nam = new TextField();
        JPasswordField pas = new JPasswordField();

This should instead initialize your instance-level variables

nam = new TextField();
        pas = new JPasswordField();
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The file just needs to be inserted as a blob data type if you wish to store it directly in the database. You can find an example of using JDBC to store a Blob here: http://www.java2s.com/Code/Java/Database-SQL-JDBC/BlobJDBCdealswithBinaryData.htm

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The stack trace clearly indicates that in your actionPerformed method on line 99 that you are attempting to call a method on an object that is null. Examine the call that is being made on line 99 and examine why it might be null.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Your question is too vague. By "upload" do you mean with a JSP page or from a desktop Java application? (This is the Java forum by the way. There is a separate JSP forum here:http://www.daniweb.com/forums/forum24.html)

Without more information no one can really help you.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you cannot understand the answers on this then what you are attempting is beyond you. You need to start from the beginning with some basic Java tutorials such as those listed in the Read Me post "Starting Java" at the top of the forum.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

What problem? You need to clearly state the problem and what you do not understand.

You also need to place [code] [/code] tags around that wall of text if you expect anyone to try to actually read it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No, it does not compile. This portion here is undecipherable

for(int i=0; i<3; i++) // starts loop
{
for (months<360); months++)

Also, the end code tag needs to be [/code] for the code to be formatted correctly.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The error message should also include the name of the class that is not found. Check that method for classes you may have missed on the class path and if it is a third-party library check that those runtime dependencies are also in your classpath.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Having the sleep() in main() after you have called the mortArray() method will not cause your output to pause. The loop will continue to run until complete and then return to execute the rest of your code in main() - which is your pause code.

You need to place the sleep() code into the mortArray() method inside the loop that is generating the output.