Need a way to have my character jump while moving left/right
<p>I have already got the jumping on the y-axis running fine, but I want to be able to use 'dx' from jumping while pressing the left/right key (ex. if I am pressing right key to go right and jump while still holding it, the character will move in a "diagonal" way)</p>

<p>My main jumping code (timer activated when jump key is pressed):</p>

<pre><code> public void actionPerformed (ActionEvent e) {
    dy += 1;
        y_pos += dy;
    if (y_pos &gt;= 400) {
        dy = 0;
        y_pos = 400;
       timer.stop();
    }   
    repaint();
}  
</code></pre>

<p>Now my KeyEvent code:</p>

<pre><code>            if (command == KeyEvent.VK_RIGHT){
                x_pos += 5;
                right = true;
            }
            if (command == KeyEvent.VK_LEFT) {
                x_pos -= 5;
                right = false;
            }
            if (command == KeyEvent.VK_UP) {    
                if (!(timer.isRunning()))
                    dy = -20;   
                timer.start();
            }   
            dr.repaint();
</code></pre>
