Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.KeyEvent;
  3. import java.awt.event.KeyListener;
  4. import java.awt.event.MouseEvent;
  5. import java.awt.event.MouseListener;
  6. import java.util.concurrent.TimeUnit;
  7.  
  8. import javax.swing.*;
  9.  
  10. public class graphics extends JFrame implements KeyListener{
  11.  
  12.  
  13. static int x=10, oldx=0;
  14. static int y=10, oldy=0;
  15. int length = 100;
  16.  
  17. public graphics(){
  18.  
  19. super();
  20. }
  21.  
  22.  
  23. public void paint(Graphics g){
  24.  
  25. g.drawLine(x,y,x+length,y+length);
  26. //g.setColor(Color.WHITE);
  27. //g.drawLine(oldx,oldy,oldx+length,oldy+length);
  28.  
  29. }
  30.  
  31. public static void main(String arg[]) throws InterruptedException{
  32.  
  33. graphics frame = new graphics();
  34.  
  35.  
  36. frame.setSize(1000,1000);
  37.  
  38.  
  39. frame.setVisible(true);
  40.  
  41.  
  42.  
  43. frame.repaint();
  44.  
  45. //TimeUnit.SECONDS.sleep(1);
  46.  
  47.  
  48. frame.addKeyListener(new KeyListener(){
  49.  
  50. @Override
  51. public void keyPressed(KeyEvent arg0) {
  52.  
  53. x++;
  54. y++;
  55. frame.repaint();
  56. }
  57.  
  58. @Override
  59. public void keyReleased(KeyEvent arg0) {
  60. // TODO Auto-generated method stub
  61.  
  62. }
  63.  
  64. @Override
  65. public void keyTyped(KeyEvent arg0) {
  66. // TODO Auto-generated method stub
  67.  
  68. }
  69.  
  70. });
  71.  
  72.  
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement