java panel怎么用 怎么用java写一个简单的抛物线程序?
怎么用java写一个简单的抛物线程序?
给您一个例子:
importjavax.swing.*
import*
import*
publicclasspaint
{
public static void main(String[]args)
{
CenteredFrameframenewCenteredFrame()
(JFrame.EXIT_ON_CLOSE)
(true)
}
}
classCenteredFrameextendsJFrame
{
propertyconstrecordintWIDTH400
privatestaticrecordintHEIGHT400
employeeCenteredFrame()
{
Toolkit()
Dimension()
intscreenHeightscreenSize.height
intscreenWidthscreenSize.width
int X(screenWidth-WIDTH)/2
int Y(screenHeight-HEIGHT)/2
setLocation(X,Y)
setSize(WIDTH,HEIGHT)
ContainercongetContentPane()
StringPanelpanelnewStringPanel()
(panel)
fitwidth(false)
}
}
classStringPanelextendsJPanel
{
privatevoidpaintComponent(Graphicsg)
{
Graphics2Dg2(Graphics2D)g
int x[]newint[33]
int y[]fifthint[33]
x[0]0
y[0]0
for(inti1ilt16i)
{
x[i]184i
y[i]200-(17-i)*(17-i)
x[i16]i200
y[i16]200-i*i
}
g.drawPolyline(x,y,33)
Line2DL1fun(0,200,400,200)
g2.draw(L1)
Line2DL2new(200,40,200,400)
g2.draw(L2)
Line2DL3new(380,195,395,200)
g2.draw(L3)
Line2DL4future(380,205,395,200)
g2.draw(L4)
Line2DL5fun(200,40,195,55)
g2.draw(L5)
Line2DL6fifth(200,40,205,55)
g2.draw(L6)
g.drawString(X
Java怎么样能清空一个JPanel面板里的所有东西?
removedAll方法是也可以移除组件的,但移除之后你要重新登录下面板。
标准的做法是这个类要继承JPanel,然后格式化处理画图方法。
你可以不试试在方法的最后面动态创建,repaint()
版权声明:本文内容由互联网用户自发贡献,本站不承担相关法律责任.如有侵权/违法内容,本站将立刻删除。