回覆列表
  • 1 # syyuf165

    簡單做了一個importjava.awt.BorderLayout;importjava.awt.Button;importjava.awt.Color;importjava.awt.Frame;importjava.awt.Graphics;importjava.awt.Panel;importjava.awt.Point;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.WindowAdapter;importjava.awt.event.WindowEvent;importjava.awt.image.BufferedImage;importjava.util.ArrayList;importjava.util.List;publicclassMyFrameextendsFrameimplementsRunnable,ActionListener{doublex1=100,y1=0;//A的起始位置doublex2=100,y2=0;//B的起始位置doubles2=26;//B的水平速度doubleg=9.8;//Glongtime=10000;//模擬10秒鐘doublepy=1;//y軸比例尺List<Point>list1=newArrayList<Point>();List<Point>list2=newArrayList<Point>();MPanelp1=newMPanel();Buttonb1=newButton("啟動");Threadt;publicMyFrame(){b1.addActionListener(this);this.add(b1,BorderLayout.NORTH);this.add(p1,BorderLayout.CENTER);this.setSize(800,600);this.addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){System.exit(0);}});this.setVisible(true);}publicvoidrun(){list1=newArrayList<Point>();list2=newArrayList<Point>();doublexx1=x1,yy1=y1,xx2=x2,yy2=y2;//本時刻位置longstart=System.currentTimeMillis();longend=start;while(end-start<=time){end=System.currentTimeMillis();doublet=(end-start)/1000.0;yy1=(y1+g*t*t/2)*py;xx2=x1+s2*t;yy2=(y2+g*t*t/2)*py;intsx1=(int)xx1;intsy1=(int)yy1;intsx2=(int)xx2;intsy2=(int)yy2;list1.add(newPoint(sx1,sy1));list2.add(newPoint(sx2,sy2));p1.repaint();try{Thread.sleep(50);}catch(InterruptedExceptione){e.printStackTrace();}}}publicvoidactionPerformed(ActionEvente){if(t==null||!t.isAlive()){t=newThread(this);t.start();}}publicclassMPanelextendsPanel{BufferedImageim=newBufferedImage(800,600,BufferedImage.TYPE_INT_RGB);publicvoidpaint(Graphicsgg){Graphicsg=im.getGraphics();g.setColor(Color.white);g.fillRect(0,0,800,600);g.setColor(Color.blue);Pointppp1=null;Pointppp2=null;for(inti=0;i<list1.size();i++){Pointpp1=list1.get(i);Pointpp2=list2.get(i);if(ppp1!=null&&ppp2!=null){g.drawLine(pp1.x,pp1.y,ppp1.x,ppp1.y);g.drawLine(pp2.x,pp2.y,ppp2.x,ppp2.y);}ppp1=pp1;ppp2=pp2;}if(ppp1!=null&&ppp2!=null){g.fillOval(ppp1.x-5,ppp1.y-5,10,10);g.fillOval(ppp2.x-5,ppp2.y-5,10,10);}g.dispose();gg.drawImage(im,0,0,800,600,p1);}}publicstaticvoidmain(String[]args){newMyFrame();}}

  • 中秋節和大豐收的關聯?
  • 15kw六極電機多少才算超負荷?