So, I've been learning Java and I'm still pretty new, so bear with me. My latest goal is graphical programs, and this one is a test on keyboard control. For some reason, this program won't display a rectangle. Normally paint() runs on its own, but for some reason it isn't. I've looked at other programs that I made that work, and others on the web, and I still can't figure it out.
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
public class App extends JFrame{
public static int keyVal = 0;
public static void main(String[] args) {
new App();
while(true){
System.out.println(keyVal);
Wait.ms(50);
}
}
public App(){
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setTitle("Pong");
f.setSize(300,400);
f.setLocationRelativeTo(null);
f.addKeyListener(new KeyListener(){
public void keyPressed(KeyEvent e){
keyVal = e.getKeyCode();
}
public void keyReleased(KeyEvent e){
keyVal = 0;
}
public void keyTyped(KeyEvent e){}
});
f.setVisible(true);
}
public void paint(Graphics g){
g.setColor(Color.orange);
while(true){
g.drawRect(20, 20, 100, 60);
}
}
}