java paint的方法 不能自动调用
importjava.awt.*;importjava.awt.event.*;publicclassDrawlineextendsFrame{Framefm;Graph...
import java.awt.*; import java.awt.event.*; public class Drawline extends Frame { Frame fm; Graphics g; int intx,inty,endx,endy; Drawline() { fm=new Frame("画图程序"); fm.setBounds(100, 100, 740, 460); fm.setBackground(Color.BLUE); fm.setVisible(true); g=fm.getGraphics(); fm.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); fm.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { intx=e.getX(); inty=e.getY(); g.drawString(intx+","+inty, intx, inty); } public void mouseReleased(MouseEvent e) { endx=e.getX(); endy=e.getY(); g.drawString(endx+","+endy,endx,endy); g.drawLine(intx, inty, endx, endy); } }); } public void paint(Graphics g) { System.out.println("重画"); g.drawLine(100, 100, 210, 360); } } class HanTu { public static void main(String[] args) { new Drawline(); } }
展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询