Win a copy of Spark in Action this week in the Open Source Projects forum!

Ben Watt

Greenhorn
+ Follow
since Feb 13, 2009
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ben Watt

Is there way to have 2 keys being pressed at the same time and be able to have the prior action along with it?

I know that if you press down both keys at the same time, the effect will occur.

But I want to be able to walk a direction for an amount of time, then press and hold down the Shift key and have the character start running.



Any help?
11 years ago
I didn't know anywhere else to post this, so I'm sorry if its in the wrong spot.

I'm currently writing out the javadoc for a project and I want to find out how to set a Class description in the index.html file.

I think it's just a matter of where I place the code, but I don't know where. Any help is appreciated.
11 years ago
All of this has been very helpful.

I am a first year java programmer and have a hard time understanding much of what y'all are saying.

Here is the code I used for my program, hopefully this is more informative than my shoddy explanation to start with.



To repeat, All I want to do is reset the Thread and have it start again each time I click the Space key.






And if there are any other general programming etiquette problems, I'd appreciate the help.
I have a thread that calls repaint() which draws a character jumping using certain images.

I press the space bar to make the character jump and whatnot.


I'm using a loop and a try-catch statement to keep track of which image I want drawn.

My problem is, I need the thread to stop going, so that when I move the character, I can jump again, but it says "IllegalThreadStateException" and highlights the "clockThread.start()" line of when I press the Space key.


It makes sense, because I never put a statement to stop it anywhere, and it can't start again.

I need to know where I can stop the thread, at what point?

And also - everywhere I put it, I get a "Supress warning for 'deprecation'"

Any help is appreciated. I can post code as well but it'll take about a day.
public FrontScreen(){
super("Start Game");
getContentPane().setBackground(Color.BLACK);
setExtendedState(MAXIMIZED_BOTH);
setUndecorated(true);
addMouseListener(this);
}

public static void main(String[] args){
FrontScreen window = new FrontScreen();
window.setVisible(true);
window.repaint();
}

public void paint(Graphics g){
super.paint(g);

Image title = new ImageIcon("Portal.png").getImage();
g.drawImage(title, 422, 200, null);

/* Get Images for menu buttons using the following method
*/
Image start = new ImageIcon("SGY.png").getImage();
g.drawImage(start, 500, 400, null);

Image option = new ImageIcon("O.png").getImage();
g.drawImage(option, 500, 500, null);

Image exit = new ImageIcon("EXIT.png").getImage();
g.drawImage(exit, 500, 600, null);

}

public void mouseClicked(MouseEvent e) {

xpos = e.getX();
ypos = e.getY();

if(xpos > 500 && xpos < 500 + 216 && ypos > 400 && ypos < 400 + 72){}
else if(xpos > 500 && xpos < 500 + 216 && ypos > 500 && ypos < 500 + 72){
System.exit(0);
OptionScreen option = new OptionScreen();
option.setExtendedState(MAXIMIZED_BOTH);
option.setVisible(true);
}
else if(xpos > 500 && xpos < 500 + 216 && ypos > 600 && ypos < 600 + 72){System.exit(0);}
}
}


(NEXT CLASS)


public class OptionScreen extends JFrame implements MouseListener{

public OptionScreen(){
super("Options");
getContentPane().setBackground(Color.BLACK);
setExtendedState(MAXIMIZED_BOTH);
setUndecorated(true);
addMouseListener(this);
}

public static void main(String[] args){
OptionScreen window = new OptionScreen();
window.setVisible(true);
}

}
11 years ago
I want to be able to:
1. click a button
2. close existing JFrame
3. run new class (which would result in opening a new JFrame)
4. bring the new class to the front.

I've tried all kind of methods, I'm kind of up against a wall right now.

I'm doing this for an independent study project so I might be on here relatively often from now till summer.

Any help is appreciated!!!
11 years ago