Zevcore 20 Maja 2020 20 Maja 2020 Nie ma podforum dla Javy dlatego postuje tu, mam taki program import javax.swing.*; import java.awt.*; import java.awt.image.BufferStrategy; public class Game extends Canvas implements Runnable { private Thread game; private boolean running; private JFrame frame; private final int WIDTH = 1080; private final int HEIGHT = 720; private final int SCALE = 1; private final String TITLE = "CAR SIM"; public Game() { frame = new JFrame(TITLE); setPreferredSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE)); setMinimumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE)); setMaximumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setResizable(false); frame.add(this); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } @Override public void run() { long lastTime = System.currentTimeMillis(); long current; long delta = 0; int frames = 0; //int ticks = 0; while (running) { current = System.currentTimeMillis(); delta += current - lastTime; lastTime = current; frames++; if (delta > 1000) { delta -= 1000; System.out.println("FRAMES " + frames); frames = 0; } try { Thread.sleep(2); } catch (InterruptedException e) { e.printStackTrace(); } render(); } } public synchronized void start() { game = new Thread(); game.start(); } public synchronized void stop() {} public void init() { } private void update() { } private void render() { BufferStrategy bs = getBufferStrategy(); if(bs == null) { createBufferStrategy(3); } Graphics g = bs.getDrawGraphics(); g.setColor(Color.DARK_GRAY); g.fillRect(10, 10, 10, 10); g.dispose(); bs.show(); } } próbuje narysować kwadrat i kompletnie nic się nie dzieje, a błędów nie ma, nawet przy kompilowaniu z debugowaniem Odnośnik do komentarza Udostępnij na innych stronach Więcej opcji udostępniania...
FrageN 20 Maja 2020 20 Maja 2020 Na twoim miejscu jeżeli już musisz pisać aplikację okienkową w Javie użył bym JavaFX zamiast przestarzałego Swinga. JavaFX - 2D Shapes Rectangle - Tutorialspoint Odnośnik do komentarza Udostępnij na innych stronach Więcej opcji udostępniania...
Zevcore 21 Maja 2020 Autor 21 Maja 2020 Wymóg profesora Odnośnik do komentarza Udostępnij na innych stronach Więcej opcji udostępniania...
Kontynuuj dyskusję
Dołącz do Pecetowicza, aby kontynuować dyskusję w tym wątku.