当前位置: 代码迷 >> Java相关 >> [求助]图显示不了?
  详细解决方案

[求助]图显示不了?

热度:134   发布时间:2007-09-15 16:00:30.0
[求助]图显示不了?
这是一个简单的画图程序,为什么图现实不了呢?请帮忙,谢谢!
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class shapes extends JPanel
{
public void painComponent(Graphics g)
{
super.paintComponent(g);
g.setColor(Color.blue);
g.drawRect(20,30,100,70);
g.drawLine(180,220,300,270);
g.drawRoundRect(140,40,80,50,15,15);
g.drawOval(30,120,100,40);
Polygon p = new Polygon();
p.addPoint(320,320);
p.addPoint(320,390);
p.addPoint(400,400);
g.drawPolygon(p);
g.setColor(Color.orange);
g.fillRect(320,30,100,70);
g.fillRoundRect(70,220,80,50,15,15);
g.fill3DRect(120,300,100,30,true);
for(int i=1;i<=7;i++)
g.draw3DRect(120-i,300-i,100+2*(i-1),30+2*(i-1),true);
g.fill3DRect(120,370,100,30,false);
for(int i=1;i<=7;i++)
g.draw3DRect(120-i,370-i,100+2*(i-1),30+2*(i-1),true);
g.fillOval(200,130,100,40);
}
}
class Fra extends JFrame
{
public Fra()
{
setTitle("Drawing shapes");
setSize(500,500);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
Container con=getContentPane();
con.add(new shapes());
}
}
public class Diagram
{
public static void main(String args[])
{
JFrame fr = new Fra();
fr.setVisible(true);
}
}

[此贴子已经被作者于2007-9-15 19:07:53编辑过]

搜索更多相关的解决方案: 画图  public  import  

----------------解决方案--------------------------------------------------------
以下是引用lzf0112在2007-9-15 16:00:30的发言:
这是一个简单的画图程序,为什么图现实不了呢?请帮忙,谢谢!
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class shapes extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.setColor(Color.blue);
g.drawRect(20,30,100,70);
g.drawLine(180,220,300,270);
g.drawRoundRect(140,40,80,50,15,15);
g.drawOval(30,120,100,40);
Polygon p = new Polygon();
p.addPoint(320,320);
p.addPoint(320,390);
p.addPoint(400,400);
g.drawPolygon(p);
g.setColor(Color.orange);
g.fillRect(320,30,100,70);
g.fillRoundRect(70,220,80,50,15,15);
g.fill3DRect(120,300,100,30,true);
for(int i=1;i<=7;i++)
g.draw3DRect(120-i,300-i,100+2*(i-1),30+2*(i-1),true);
g.fill3DRect(120,370,100,30,false);
for(int i=1;i<=7;i++)
g.draw3DRect(120-i,370-i,100+2*(i-1),30+2*(i-1),true);
g.fillOval(200,130,100,40);
}
}
class Fra extends JFrame
{
public Fra()
{
setTitle("Drawing shapes");
setSize(500,500);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
Container con=getContentPane();
con.add(new shapes());
}
}
public class Diagram
{
public static void main(String args[])
{
JFrame fr = new Fra();
fr.setVisible(true);
}
}


----------------解决方案--------------------------------------------------------

晕,大意了,谢谢斑竹!


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