Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Your super.paint() call is causing to paintComponent() to get called again, hence the infinite loop and stack overflow.

You shouldn't really need a super.paint() call in your paintComponent() method if you are just painting the background. If anything, it would be a super.paintComponent() instead of paint(), since that is the one you are overriding.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ok, it's a JApplet

GameApplet extends [B]JApplet[/B]

.
I'd recommend changing

public void paint( Graphics graphics )

to

public void paintComponent( Graphics graphics )

so that you're only overriding the paint behavior of the panel itself and not affecting the the rendering of the other components.

In paintComponent() all you really should need are these

if (app.end)	{
  graphics.setColor( Color.BLACK ) ;
  graphics.fillRect (0, 0, 800, 600);
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The general form would be

DELETE FROM [tableName] WHERE [expression]

You need to fill in your own table name and WHERE expression to specify the rows to be deleted.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Your panel doesn't have the focus, so it's not receiving your key events. Add

content.requestFocusInWindow();

after the setVisible() call.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The query in your "remove" string is a select query - not a delete query.

Select queries return result sets and are called with executeQuery().

Delete/update queries return the number of rows affected and are executed with executeUpdate().

Do you know how to delete rows from a table? You need to re-write that query to be a delete statement instead of a select.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No one can tell unless you post some code. Are you using JApplet or the old AWT Applet?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Make sure that your fillRect call is being made before the other UI components are being rendered. Typically that would mean making it the first statement in your paintComponent() method.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

"It doesn't work" is not a description of the difficulties you're having. How can anyone know what it was that you tried? What errors occurred?

Post the code. Post error messages or specific questions.

I'm not going to guess what it was that you did that did not work and I won't just write the code for you.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can could also create a Path2D instance and add points to it if you have a specific formula that you need to plot.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

As I already said above, you need to subclass JDesktopPane and override paintComponent()

class ImageDesktopPane extends JDesktopPane {
  public void paintComponent(Graphics g){
    g.drawImage( ... )
  }
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Create a subclass of JDesktopPane and override paintComponent(Graphics) to draw the image.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Take a look at this quick tutorial from someone who was trying to do something similar: http://www-personal.umich.edu/~lsiden/tutorials/signed-applet/signed-applet.html

I think that should get you running. I'm on my way out the door as well. Good luck.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It looks like the default applet access controls aren't happy with the URL.openStream() call you're making. You'll probably need to sign the jar file

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ok, the IDE put in a package declaration for you

package expirement1;

so you will need to call the class with expirement1.NewJApplet Change your "code" attribute to that.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The name of your applet class.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Try changing your applet tag to

<applet code = 'NameOfYourClassHere' 
    archive = 'NameOfJarHere.jar', 
    width = 300, 
    height = 300 />
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You are somewhat right that it is exiting at "random" times - it's your generator for the computer choice that is causing the exit. The nextInt(int) function is specified

Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive),

So it is giving you a value from 0 to 2. You don't account for a value of 0 in your if() statements, so it will fall into your else() block where you are exiting.

Note that the computer will also never choose Scissors with that generator either.

Knowing why it's exiting, you should be able to figure out how to fix it quite easily now.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

See the section on Deploying the Applet

You need to Build the project to create the jar file, upload the file to your server, and create an HTML page that has your <applet> tag in it.

Edit: You'll find the jar file in your project's "dist" directory after you perform the Build.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

In many cases it can be as simple as putting the initialization code that you had in main() into the init() method for the applet. You can read about developing applets here: http://download.oracle.com/javase/tutorial/deployment/applet/subclass.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can use the getSource() method of the ActionEvent to get a reference to the button that was clicked. You will need to cast it to JButton yourself to use it, since getSource() returns Object.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If it is a standard Java Swing application, your friends will need to download the jar file from you and run it themselves.

You could convert it to an applet if you wanted to, but that would require a little bit of work converting the main JFrame to JApplet. Mostly it just involves moving a bit of code into specific methods required by the applet life cycle.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It can be. Did you create it as an applet? I have no idea what you built there based upon the fragments of code that you posted.

Edit: Looks like a standard JFrame swing form in your screen shot.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Applets can run from a web page. Jar files are standalone Java applications. If your application is not an applet, your friends will have to download the jar and run it themselves.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can build an executable jar from Netbeans. Search the help content for "Building a Jar File".

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

> You ruined my whole happiness now. Do you enjoy ruining peoples' lives like that?
Ok, I think it's nap time.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Using a small data structure for each entry would make it much easier

class ScoreEntry {
  int rank;
  int level;
  int xp;
}

and using something similar to this to read them

List<ScoreEntry> scoreList = new ArrayList<ScoreEntry>();
while ((str = in.readLine()) != null) {
   counter++;
   String[] values = str.split(",");
   ScoreEntry score = new ScoreEntry();
   score.rank = values[0];
   score.level = values[1];
   score.xp = values[2];
   scoreList.add(score);
}

You would need to make an allowance for the "Activities" portion that only has 2 values. Those may need to be a separate collection of different objects depending on how you intend to use them.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This is what I was talking about in your reading code

statPullerData = statPullerData + str;

It is glomming together each line, so the last number of one line is get concatenated to the number beginning the next. If you want a space to separate them, you would need to use

statPullerData = statPullerData + str + " ";
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Post the code that you used to aggregate the data string. It looks like you're not adding any separation between the lines that it reads. The actual file content looks like this

2804,2433,346650470
41659,99,17647169
26563,99,17308353
16960,99,25179548
25046,99,26034685
32347,99,15709510
...

Each score is on a separate line. The readLine() call will strip the line break, so if you're just adding each line read to a single string variable it will get output like you posted above 2804,2433,34665047041659,99,1764716926563 To remedy that, you could add a separator character between them such as "|", but really you'd save yourself the effort of re-parsing the string later if you created a small data object to hold each score entry. Add them to an array list as you read and create them.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Even if you don't have long-term code as a consideration, using clear and meaningful variable names is useful in maintaining focus and understanding of what any section of code is doing.

As already explained above, using a name like "hours" instead of "X3" makes the logic a lot easier to follow - even for the person writing it.

And let's give this thread back to the OP now. We've interjected more than enough on variable naming.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

> I want an answer for your reason.
And I want you to cease this completely useless and off-topic hijack of the thread. This isn't the place to discuss your hurt feelings.

Get it back on topic.

peter_budo commented: Thanx for stepping in, I was on bus and mobile is bad for moderator needs +16
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

> And give me any one reason, big or small, as to why I'd leave code sitting for one year and not use it, delete it or work around with it?
Any working programmer is going to have plenty of code around that they haven't looked at in over a year. I have production code that I probably haven't looked at in over five years.

I can absolutely guarantee you'll understand why meaningful variable names are not just a trivial nitpick suggestion if you have to work on some code you wrote years ago.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Did you try the example? It really doesn't get much more straightforward.

You can append each line as it's read to a single string if you wish. readLine() is going to strip the newline from each line of text as it is read, so you'll have to put in your own separator between lines.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Signatures are only visible to logged in users.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Here's a basic example on getting text from a URL:
http://www.exampledepot.com/egs/java.net/ReadFromURL.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

> Not sure how to flag as answered!!
Just click the link "Mark this thread as solved" at the bottom where it says "Has this thread been answered?"

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If it's not being returned as part of the InetAddress then I don't know that you can. That's a question of your local set up and name resolution.

As far as the splitting though, you don't really need to split the toString() representation of the address. You can use the methods to get them directly

System.out.println("host: "+IP.getHostName());
            System.out.println("ip: "+IP.getHostAddress());
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

That's not really the point. It was just an address to test with.

The split works just fine in your println() statements. Your file writing code is another story because you are writing totally different things there. I'm not sure why you're trying to write the "Name" array as your host name, but that obviously won't work.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I suppose it's possible that someone could.

Not sure why they would want to really, but yeah, it's possible that they could.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This part works just fine here for me using InetAddress.getLocalHost() as a test address

System.out.println("The IP addres is: " + Name[1]);
        System.out.println("The Hostname is: " + Name[0]);
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Try using just getInsets() instead of getMargin()

String label = "Really Super Extra Long String Here";
int len = jButton1.getFontMetrics(jButton1.getFont()).stringWidth(label);
jButton1.setSize(len + 2*jButton1.getInsets().left, jButton1.getHeight());
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you demonstrated the slightest bit of effort, or even bothered to ask specific questions about what you are having trouble with, perhaps someone would offer some assistance with this.

You merely posted your interview question and asked others to solve it for you - and that's why no one answered you. This forum is about helping people solve their problems - not doing their work for them.

(Read the rules about using "chat speak" as well.)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Not seeing an inconsistency. Listing shows the thread was created 1 day ago. Replies are within that time frame, with the last being 12 minutes ago.

"strange error in MySQL query" is the one you mentioned up above though and that's not the thread you're looking at.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Slipknot - "Sulfur"

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

> This is an Interview question.
If you can't figure it out without asking others to do it for you, you should not get the job.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

> send me sources code and i can help you solve problem
Please keep it on the forums where everyone can assist and benefit from the answer.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, OpenGL only gets you bare-metal 3D graphics rendering capabilities. I mention it only as an alternative to Java3D.

Engines like jMonkey provide a lot of extra built-in API functionality for a game.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

JOGL is a fairly straight-forward wrapper for OpenGL.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It occurs because of the order you are checking the relative locations once they have intersected.

You first check the x values and update them +- 100, so consider how that affects the intersects() check in the two blocks that check the y values.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I'll second the suggestion on H2. We are using it and it's great.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Use a Swing Timer to update the line coordinates and call repaint. You will need to make "y" a class variable and paintComponent() just needs to draw the line.

public void paintComponent (Graphics g)  
    {
       super.paintComponent(g);
       g.setColor(Color.RED);
       g.drawLine(y,40,380,30);
    }