1楼:王_世杰
/** java绘图原理
*/package yousphu;
import java.awt.*;
import javax.swing.*;
public class demo9_1 extends jframe
public demo9_1()
}//定义一个吗panel、用于绘制和实现图像class mypanel extends jpanel}
2楼:匿名用户
graphics g; //想办法获得图形上下文对象
g.drawoval(x, y, width, height);
求一个java程序:绘图程序包括画圆,椭圆,线,矩形,自定义。并且可以调图形颜色! 30
3楼:匿名用户
publicenumshapetypes
publicinte***ceshape
publicclassrectangleimplementsshape
publicrectangle(intx,inty,intwidth,intheight,colorrectanglecolor)
@override
publicvoidpaint(graphicsg)
}publicclasslineimplementsshape
publicline()
@override
publicvoidpaint(graphicsg)
}publicclasscircleimplementsshape
publiccircle(intx,inty,intradius,colorcirclecolor)
@override
publicvoidpaint(graphicsg)
}publicclasssketchpadpanelextendscanvasimplementsmouselistener,mousemotionlistener
/***撤销方法
*/publicvoidundo()
}/**
*恢复撤销方法
*/publicvoidredo()
}/**
*设置命令
**@paramtype
*/publicvoidsetshapetype(shapetypestype)
/***设置颜色
**@paramcolor
*/publicvoidsetcolor(colorcolor)
publicvoidupdete(graphicsg)
/***绘制画板
*/@override
publicvoidpaint(graphicsg)
//如果当前鼠标没有释放
if(i**ousepressing)else
}elseelse
}break;
//绘制圆形
casecircle:
//半径为a*a+b*b的平方根
intradius=(int)math
.sqrt((beginx-currentx)*(beginx-currentx)+(beginy-currenty)*(beginy-currenty));
g.drawarc(beginx-radius/2,beginy-radius/2,radius,radius,0,360);
break;}}
}@override
publicvoidmouseclicked(mouseevente)
@override
publicvoidmouseentered(mouseevente)
@override
publicvoidmouseexited(mouseevente)
/***当鼠标按下的时候获得起始坐标
*/@override
publicvoidmousepressed(mouseevente)
/***当鼠标释放时获得当前坐标
*/@override
publicvoidmousereleased(mouseevente)else
}elseelse
}currentshapes.push(rectangle);
break;
}repaint();
}@override
publicvoidmousedragged(mouseevente)
@override
publicvoidmousemoved(mouseevente)
}publicclasssketchpadframeextendsjframe
privatevoidinitlistener()
});bluebutton.addactionlistener(newactionlistener()
});greenbutton.addactionlistener(newactionlistener()
});undobutton.addactionlistener(newactionlistener()
});redobutton.addactionlistener(newactionlistener()
});exitbutton.addactionlistener(newactionlistener()
});linebutton.addactionlistener(newactionlistener()
});circlebutton.addactionlistener(newactionlistener()
});rectanglebutton.addactionlistener(newactionlistener()
});}
publicsketchpadframe()
/*********************处理事件**********************/
privatevoidundoaction(actionevente)
privatevoidredoaction(actionevente)
privatevoidexitaction(actionevente)
privatevoidlineaction(actionevente)
privatevoidcircleaction(actionevente)
privatevoidrectangleaction(actionevente)
privatevoidredaction(actionevente)
privatevoidblueaction(actionevente)
privatevoidgreenaction(actionevente)
}/**
**@author不落的太阳(seanyang)
*@version1.0
*@sincejdk1.8
**/
publicclasssketchpadmain
});}}