我编写了如下代码,如下package myprojects.drawline;import java.awt.*;import java.awt.event.*;class drawline extends Frame {public drawline (){addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e){dispose();System.exit(0);}});this.addMouseListener(new MuoseAdapter(){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.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) {// TODO Auto-generated method stubSystem.out.println("Starting drawline");drawline mainFrame = new drawline();mainFrame.setSize(400,400);mainFrame.setTitle("画线测试");mainFrame.setVisible(true);}}
添加回答
举报
0/150
提交
取消