SHARE
TWEET

Untitled

a guest Apr 18th, 2019 144 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.company;
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.KeyEvent;
  6. import java.awt.event.KeyListener;
  7. import java.awt.event.MouseEvent;
  8. import java.awt.event.MouseListener;
  9. import java.awt.image.BufferStrategy;
  10.  
  11. public class Main implements MouseListener, KeyListener {
  12.     static final int screenX = 1024;
  13.     static final int screenY = 768;
  14.  
  15.     public static void main(String[] args) {
  16.         JFrame jf = new JFrame();
  17.         jf.setDefaultCloseOperation(jf.EXIT_ON_CLOSE);
  18.         jf.setSize(screenX, screenY);
  19.         jf.setUndecorated(false);
  20.         jf.setVisible(true);
  21.         jf.createBufferStrategy(2);
  22.         Main m = new Main();
  23.         jf.addMouseListener(m);
  24.         jf.addKeyListener(m);
  25.  
  26.         long lastFrame = System.currentTimeMillis();
  27.         while (true) {
  28.             BufferStrategy bs = jf.getBufferStrategy();
  29.             Graphics2D g = (Graphics2D) bs.getDrawGraphics();
  30.             g.clearRect(0, 0, screenX, screenY);
  31.  
  32.             long now = System.currentTimeMillis();
  33.             double dt = (now - lastFrame) / 1000.0;
  34.             draw(g);
  35.             update(dt);
  36.             lastFrame = now;
  37.  
  38.             bs.show();
  39.             g.dispose();
  40.         }
  41.     }
  42.  
  43.     //袙小袝 袛袗袧袧蝎袝 袠袚袪蝎 孝校孝
  44.     static double x = 100f;
  45.     static double y = 100f;
  46.  
  47.     //袙小袝 袪袠小袨袙袗袧袠袝 孝校孝
  48.     static void draw(Graphics2D g) {
  49.         g.drawString(x + "", 100, 200);
  50.         g.fillOval((int) x, (int) y, 20, 20);
  51.     }
  52.  
  53.     //袠袟袦袝袧袠袝袧袠袝 小袨小孝袨携袧袠携  袦袠袪袗 孝校孝
  54.     static void update(double dt) {
  55.         x += dt * 10;
  56.  
  57.     }
  58.  
  59.     @Override
  60.     public void mouseClicked(MouseEvent mouseEvent) {
  61.         if (mouseEvent.getButton() == MouseEvent.BUTTON1) {
  62.             x = mouseEvent.getX();
  63.             y = mouseEvent.getY();
  64.         }
  65.     }
  66.  
  67.     @Override
  68.     public void mousePressed(MouseEvent mouseEvent) {
  69.  
  70.     }
  71.  
  72.     @Override
  73.     public void mouseReleased(MouseEvent mouseEvent) {
  74.  
  75.     }
  76.  
  77.     @Override
  78.     public void mouseEntered(MouseEvent mouseEvent) {
  79.  
  80.     }
  81.  
  82.     @Override
  83.     public void mouseExited(MouseEvent mouseEvent) {
  84.  
  85.     }
  86.  
  87.  
  88.     @Override
  89.     public void keyTyped(KeyEvent keyEvent) {
  90.  
  91.     }
  92.  
  93.     @Override
  94.     public void keyPressed(KeyEvent keyEvent) {
  95.  
  96.     }
  97.  
  98.     @Override
  99.     public void keyReleased(KeyEvent keyEvent) {
  100.  
  101.     }
  102. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top