更改下题,根据字符参数fillCharacter所包含的任何一种字符组成正方形,如果side等于5,fillCharacter等于#

import java.applet.Applet;

import java.awt.Button;

import java.awt.Graphics;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JOptionPane;public class Task6_18 extends Applet {

   int size ;

   public void init(){

   Button bt = new Button("点击我弹出输入框"); 

   bt.addActionListener(new ActionListener(){

   public void actionPerformed(ActionEvent e) {

    String s = JOptionPane.showInputDialog(null, "请输入:");

    size = Integer.parseInt(s);

    repaint();

   }

  });

  this.add(bt);

 }

 public void paint(Graphics g){

  if(size>0){

   squareOfAsterisks(g,size);

  }

 }

 public void squareOfAsterisks(Graphics g, int size){

  String str="";

  int x=50,y=100;

  for(int j=0;j<size;j++)

    str+="* ";

  for(int i=0;i<size;i++){

   g.drawString(str, x, y);

   y+=10;

  }

 }

}


慕粉02102016
浏览 1573回答 0
0回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java