java图形用户界面编程
给下面的螺旋方阵添加图形用户界面,急求。publicstaticvoidmain(String[]args){intnumber=5;int[][]arys=printC...
给下面的螺旋方阵添加图形用户界面,急求。
public static void main(String[] args)
{
int number=5;
int[][] arys=printCircle(number);
for (int i=0;i<number;i++)
{
for (int j=0;j<number;j++)
{
System.out.print(arys[i][j]+"\t");
}
System.out.println();
}
}
private static int[][] printCircle(int number)
{
int[][] ary = new int[number][number];
int rightLen;
int downLen;
int leftLen;
int upLen;
int rightRow=0;
int rightCol=0;
int leftRow=number-1;
int leftCol=number-1;
int downRow=1;
int downCol=number-1;
int upRow=number-2;
int upCol=0;
int digit=1;
while(number>0)
{
rightLen=number;
downLen=number-1;
leftLen=number-1;
upLen=number-2;
for(int i=0,temp=rightCol;i<rightLen;i++)
{
ary[rightRow][temp++]=digit++;
}
for(int j=0,temp=downRow;j<downLen;j++)
{
ary[temp++][downCol]=digit++;
}
for(int m=0,temp=leftCol-1;m<leftLen;m++)
{
ary[leftRow][temp--]=digit++;
}
for(int n=0,temp=upRow;n<upLen;n++)
{
ary[temp--][upCol]=digit++;
}
number=number-2;
rightRow++;
rightCol++;
downRow++;
downCol--;
leftRow--;
leftCol--;
upRow--;
upCol++;
}
return ary;
}
} 展开
public static void main(String[] args)
{
int number=5;
int[][] arys=printCircle(number);
for (int i=0;i<number;i++)
{
for (int j=0;j<number;j++)
{
System.out.print(arys[i][j]+"\t");
}
System.out.println();
}
}
private static int[][] printCircle(int number)
{
int[][] ary = new int[number][number];
int rightLen;
int downLen;
int leftLen;
int upLen;
int rightRow=0;
int rightCol=0;
int leftRow=number-1;
int leftCol=number-1;
int downRow=1;
int downCol=number-1;
int upRow=number-2;
int upCol=0;
int digit=1;
while(number>0)
{
rightLen=number;
downLen=number-1;
leftLen=number-1;
upLen=number-2;
for(int i=0,temp=rightCol;i<rightLen;i++)
{
ary[rightRow][temp++]=digit++;
}
for(int j=0,temp=downRow;j<downLen;j++)
{
ary[temp++][downCol]=digit++;
}
for(int m=0,temp=leftCol-1;m<leftLen;m++)
{
ary[leftRow][temp--]=digit++;
}
for(int n=0,temp=upRow;n<upLen;n++)
{
ary[temp--][upCol]=digit++;
}
number=number-2;
rightRow++;
rightCol++;
downRow++;
downCol--;
leftRow--;
leftCol--;
upRow--;
upCol++;
}
return ary;
}
} 展开
展开全部
import java.applet.Applet;
import java.awt.Graphics;
public class MyApplet extends Applet {
/**
*
*/
private static final long serialVersionUID = -3514248401804395713L;
public MyApplet(){
super();
}
public void init(){
setSize(320, 300);
}
public void paint(Graphics 桥薯g){
super.paint(g);
int number = 5;
int r = 50;
int padd = 30;
int[][] arys = printCircle(number);
for (int i = 0; i < number; i++) {
for (int j = 0; j < number; j++) {
g.drawString("" + arys[i][j], padd + j*r, padd + i*r);
System.out.print(arys[i][j] + "\t");
}
System.out.println();
}
}
private int[][] printCircle(int number) {
int[][] ary = new int[number][number];
int rightLen;
int downLen;
int leftLen;
int upLen;
int rightRow = 0;
int rightCol = 0;
int leftRow = number - 1;
int leftCol = number - 1;
int downRow = 1;
int downCol = number - 1;
int upRow = number - 2;
int upCol = 0;
int digit = 1;
while (number > 0) {
rightLen = number;
downLen = number - 1;
leftLen = number - 1;
upLen = number - 2;
for (int i = 0, 粗空temp = rightCol; i < rightLen; i++) {
ary[rightRow][temp++] = digit++;
}
for (int j = 0, temp = downRow; j < downLen; j++) {
ary[temp++][downCol] = digit++;
}
for (int m = 0, temp = leftCol - 1; m < leftLen; m++) {
ary[leftRow][temp--] = digit++;
}
for (int n = 0, temp = upRow; n < upLen; n++) {
ary[temp--][upCol] = digit++;
}
number = number - 2;
rightRow++;
rightCol++;
downRow++;
downCol--;
leftRow--;
leftCol--;
upRow--;
upCol++;
}
return ary;
}
}
好岩消瞎吧,直接在Applet上显示出来最简单
追问
如果要添加阶数自定义功能呢?
追答
那就加呗
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询