//框架 私有静态JFrame框架;
private static BufferStrategy bs;
private static Graphics g;
private static JPanel jp;
private static Canvas canvas;
private static int width = 1000;
private static int height = 1000;
public static void main(String[] args) {
// TODO Auto-generated method stub
locX.clear();
locY.clear();
loadData();
createFrame();
}
public static void createFrame() {
frame = new JFrame("Title");
frame.setSize(width, height);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(true);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
canvas = new Canvas();
canvas.setPreferredSize(new Dimension(width,height));
canvas.setMaximumSize(new Dimension(width,height));
canvas.setMinimumSize(new Dimension(width,height));
canvas.setBackground(Color.cyan);
//jp.setSize(new Dimension(width,height));
//frame.add(jp);
frame.add(canvas);
frame.pack();
bs = canvas.getBufferStrategy();
if(bs == null) {
canvas.createBufferStrategy(1);
return;
}
g = bs.getDrawGraphics();
// clear screen
//g.clearRect(0, 0, width, height);
g.setColor(Color.red);
g.fillRect(400, 50, 100, 100);
bs.show();
g.dispose();
}