publicclassMouseLisextendsMouseAdapter{privateArrayList<Bullet> bs;publicMouseLis(ArrayList<Bullet> bs){this.bs=bs;}publicvoidmouseReleased(MouseEvent e){Bullet bu =newBullet(e.getX(), e.getY());this.bs.add(bu);}}
最后设置界面,把监听器,线程类都加到上面去
publicclassGameextendsJFrame{privateArrayList<Bullet> bs=newArrayList<>();publicGame(){super();}publicvoidinitUI(){this.setTitle("对战系统");this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setSize(1600,800);this.setVisible(true);Graphics g =this.getGraphics();MouseLis ms =newMouseLis(bs);this.addMouseListener(ms);ThreadDraw td =newThreadDraw(bs,g);
td.start();}publicstaticvoidmain(String[] args){Game g =newGame();
g.initUI();}}