Java.GUI图形操作.双缓冲

修改上篇日志中的MyForm.java

 

//MyFrame.java package myprojects.drawline; import java.util.*; import java.awt.Frame; import java.awt.*; import java.awt.event.*; public class MyFrame extends Frame { Dimension d=getSize(); Image img=creatImage(d.width,d.height); Graphics og=img.getGraphics(); int x1,x2,y1,y2; //Vector v=new Vector(); public MyFrame(){ enableEvents(AWTEvent.MOUSE_EVENT_MASK); enableEvents(AWTEvent.WINDOW_EVENT_MASK); } protected void processMouseEvent(MouseEvent e){ if(e.getID()==MouseEvent.MOUSE_PRESSED){ x1=e.getX(); y1=e.getY(); } if(e.getID()==MouseEvent.MOUSE_RELEASED){ x2=e.getX(); y2=e.getY(); Graphics g=getGraphics(); g.setColor(Color.red); g.setFont(new Font("隶书",Font.ITALIC,30));//设置文本字体 g.drawString(new String(x1+","+y1),x1,y1);//坐标文本和按下鼠标时的坐标 g.drawLine(x1,y1,x2,y2); g.drawString(new String(x2+","+y2),x2,y2); //v.addElement(new MyLine(x1,y1,x2,y2)); og.setColor(Color.red); og.setFont(new Font("隶书",Font.ITALIC,30));//设置文本字体 og.drawString(new String(x1+","+y1),x1,y1);//坐标文本和按下鼠标时的坐标 og.drawLine(x1,y1,x2,y2); og.drawString(new String(x2+","+y2),x2,y2); } } protected void processWindowEvent(WindowEvent e){ if(e.getID()==WindowEvent.WINDOW_CLOSING){ dispose(); } } public void paint(Graphics g){ /* Enumeration e=v.elements(); while(e.hasMoreElements()){ MyLine ln=(MyLine)e.nextElement(); Thread.sleep(5000); ln.drawLine(g); } */ if(img!=null) g.drawImage(img,0,0,this); } }

你可能感兴趣的:(vector,image,String,Class,import,图形)