当前位置: 代码迷 >> Java相关 >> [求助]请教关于Graphics类的程序!!
  详细解决方案

[求助]请教关于Graphics类的程序!!

热度:460   发布时间:2007-11-03 13:54:30.0
[求助]请教关于Graphics类的程序!!

为什么这个程序画了直线后,那条直线不能马上显示,而要对窗口进行放大或缩小时才能看到?
还有如果要想多画几条直线,怎样才能保留原先画的直线?
请指教!!
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class man extends JFrame
{
int x1,y1,x2,y2;
public man(String str)
{
super(str);
}
public void put(man JF)
{
Container contentPane=JF.getContentPane();
contentPane.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
x1=e.getX();
y1=e.getY();
}
public void mouseReleased(MouseEvent e)
{
x2=e.getX();
y2=e.getY();
}
});
women JP=new women();
contentPane.add(JP);
JF.setSize(600,400);
JF.setLocation(180,180);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JF.setVisible(true);
}
public static void main(String[] args)
{
man JF=new man("菜单窗口");
JF.put(JF);
}
class women extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.drawLine(x1,y1,x2,y2);
}
}
}


搜索更多相关的解决方案: Graphics  import  awt  直线  

----------------解决方案--------------------------------------------------------
  相关解决方案