import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class DrawRect extends Frame{
public static void main(String [] args){
new DrawRect().init();
}
public void init(){
setTitle("矩形的绘制");
setSize(300,300);
setVisible(true);
addMouseListener(new MouseAdapter()
{
int orgX;
int orgY;
int orgH;
int orgL;
double ordH;
double ordL;
public void mousePressed(MouseEvent e)
{
orgX=e.getX();
orgY=e.getY();
}
public void mouseReleased(MouseEvent e){
ordH=Math.abs(orgX-e.getX());
ordL=Math.abs(orgY-e.getY());
orgH=(int)ordH;
orgL=(int)ordL;
Graphics g = getGraphics();
g.setColor(Color.red);
//while(e.getY()<orgY&&e.getX()>orgX)
g.drawRect(orgX,orgY,orgH,orgL);
//while(e.getY()<orgY&&e.getX()<orgX)
g.drawRect(e.getX(),orgY,orgH,orgL);
//while(e.getY()>orgY&&e.getX()>orgX)
g.drawRect(orgX,e.getY(),orgH,orgL);
//while(e.getY()>orgY&&e.getX()<orgX)
g.drawRect(e.getX(),e.getY(),orgH,orgL);
}
});
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
}
这样画出的矩形是个田字~~
请问高手们如何选择输出四种矩形绘制效果啊?
还有怎么添加重绘效果啊~~?
先谢谢各位高手了~