日期:2014-05-20 浏览次数:20633 次
import java.awt.*; import java.awt.event.*; public class DrawLine extends Frame { public DrawLine() { addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { dispose(); System.exit(0); } }); this.addMouseListener(new MouseAdapter() { int orgX; int orgY; public void mousePressed(MouseEvent e) { orgX=e.getX(); orgY=e.getY(); } public void mouseReleased(MouseEvent e) { Graphics g=getGraphics();//为什么等号右边要这么写。 g.setColor(Color.RED); g.setFont(new Font(null,Font.ITALIC|Font.BOLD,30)); //g.setFont(Font.BOLD)为什么此处这么写会报错?为什么不能这么写? g.drawString(orgX+","+orgY,orgX,orgY); g.drawString(e.getX()+","+e.getY(),e.getX(),e.getY()); g.drawLine(orgX,orgY,e.getX(),e.getY()); } }); } public static void main(String []args) { DrawLine dl=new DrawLine(); dl.setSize(400,400); dl.setTitle("窗体"); dl.setVisible(true); } }