Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Reviewed your code,I suggest you to give every class a good name. </p> <p>Bad-style naming ,such as Frame extends Canvas ,will make a mess.</p> <p>And If you use Swing,there built-in buffered-Strategy for you,like double-buffered strategy. </p> <p>please give more information.</p> <p>currently,I refactored your code ,and make a sample as follow:</p> <pre><code>import java.awt.*; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.image.BufferStrategy; import javax.swing.JFrame; import javax.swing.SwingUtilities; /** * this code still Need to improve * deal with Thread related code * */ public class Game extends Canvas implements Runnable{ public static void main(String[] args) { //GUI EDT thread SwingUtilities.invokeLater(new Runnable(){ @Override public void run() { JFrame frame = new JFrame("Finland2D"); frame.setPreferredSize(new Dimension(765, 500)); final Game game = new Game(); game.playing = true; frame.add(game); frame.pack(); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.addWindowListener(new WindowAdapter(){ @Override public void windowClosing(WindowEvent e) { // TODO Auto-generated method stub game.finish(); System.exit(0); } }); //start game thread new Thread(game).start(); } }); } public Game() { } @Override public void run() { while (playing) { update(); render(); } } public void finish() { playing = false; } public void update() { } public void render() { BufferStrategy b = null; if (super.getBufferStrategy() == null) { super.createBufferStrategy(3); } b = super.getBufferStrategy(); Graphics2D g = (Graphics2D) b.getDrawGraphics(); g.setColor(Color.BLACK); g.fillRect(0, 0, getWidth(), getHeight()); g.dispose(); b.show(); } private static final long serialVersionUID = 1L; public boolean playing = false; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload