用JAVA编写一个程序绘制一个10*10的网格,每格(正方形)边长为20像点。
展开全部
import java.awt.*;
import javax.swing.*;
public class DrawRectTest extends JFrame
{
public DrawRectTest()
{
GPanel g=new GPanel();
this.getContentPane().add(g);
this.setSize(500,500);
this.setVisible(true);
}
public static void main(String[] args)
{
new DrawRectTest();
}
}
class GPanel extends JPanel
{
public void paintComponent(Graphics g)
{
int w;//横坐标
int h;//纵坐标
for(int i=1;i<=10;i++)
{
h=30;
w=10;
for(int j=1;j<=10;j++)
g.drawRect(w=w+20, h, 20, 20);
}
}
}
import javax.swing.*;
public class DrawRectTest extends JFrame
{
public DrawRectTest()
{
GPanel g=new GPanel();
this.getContentPane().add(g);
this.setSize(500,500);
this.setVisible(true);
}
public static void main(String[] args)
{
new DrawRectTest();
}
}
class GPanel extends JPanel
{
public void paintComponent(Graphics g)
{
int w;//横坐标
int h;//纵坐标
for(int i=1;i<=10;i++)
{
h=30;
w=10;
for(int j=1;j<=10;j++)
g.drawRect(w=w+20, h, 20, 20);
}
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询