import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.util.*;
public class DrawLine1 extends Frame
{
Image oimg = null;
Graphics og = null;
//Vector vline = new Vector();
int orgX;
int orgY;
int endX;
int endY;
public void paint(Graphics g)
{
g.drawImage(oimg,0,0,this);
}
public DrawLine1()
{
setSize(400,400);
setTitle("DrawLine1");
setVisible(true);
Dimension d = getSize();
Image oimg = createImage(d.width,d.height);
Graphics og = oimg.getGraphics();
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
dispose();
System.exit(0);
}
});
this.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
orgX = e.getX();
orgY = e.getY();
}
public void mouseReleased(MouseEvent e)
{
endX = e.getX();
endY = e.getY();
Graphics og = getGraphics();
og.setColor(Color.RED);
og.setFont(new Font("null",Font.ITALIC|Font.BOLD,30));
og.drawLine(orgX,orgY,e.getX(),e.getY());
og.drawString(orgX + "," + orgY,orgX,orgY);
og.drawString(e.getX() + "," + e.getY(),e.getX(),e.getY());
}
});
}
public static void main(String[] args) {
// TODO: Add your code here
DrawLine1 mainFrame = new DrawLine1();
}
}
怎么我的代码中paint方法里g.drawImage(oimg,0,0,this)怎么没有执行啊?请高人指点·····
答案:2 悬赏:80 手机版
解决时间 2021-02-22 23:17
- 提问者网友:人傍凄凉立暮秋
- 2021-02-22 09:38
最佳答案
- 五星知识达人网友:酒安江南
- 2021-02-22 10:37
在drawImage之前写一句System.out.println("aa"); 会发现运行的时候打印了aa说明drawImage一定会被调用到,至于这句话有没有起到你期望的作用,那是另一个问题,并且你没有给出足够的信息
全部回答
- 1楼网友:往事埋风中
- 2021-02-22 11:14
同问。。。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯