使用do/while循环,写一个窗口小程序MultiplicationTableApplet.java 显示如下:0 1 2 3 4 5 6 7 8 9 ----------------------------------------0 | 0 0 0 0 0 0 0 0 0 0 1 | 0 1 2 3 4 5 6 7 8 9 2 | 0 2 4 6 8 10 12 14 16 18 3 | 0 3 6 9 12 15 18 2

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/26 08:15:03
使用do/while循环,写一个窗口小程序MultiplicationTableApplet.java 显示如下:0 1 2 3 4 5 6 7 8 9 ----------------------------------------0 | 0 0 0 0 0 0 0 0 0 0 1 | 0 1 2 3 4 5 6 7 8 9 2 | 0 2 4 6 8 10 12 14 16 18 3 | 0 3 6 9 12 15 18 2
xX[oD+U#i%T>VBc{]{6iH$T@(*7ATPy!l7gfޭf7vs͙#7t=|\>8FA4A %4c\Oaϟ*<3D]PLAJA+vR{3E\Bd^`2IR(ZAt@CUYAXir0 a0!htjp@&scQa :C:)MJb> S05bltʃFB*5bY Fz/i>%6N  t '^t+l-&!i㽭%I8.<'f/

使用do/while循环,写一个窗口小程序MultiplicationTableApplet.java 显示如下:0 1 2 3 4 5 6 7 8 9 ----------------------------------------0 | 0 0 0 0 0 0 0 0 0 0 1 | 0 1 2 3 4 5 6 7 8 9 2 | 0 2 4 6 8 10 12 14 16 18 3 | 0 3 6 9 12 15 18 2
使用do/while循环,写一个窗口小程序MultiplicationTableApplet.java 显示如下:
0 1 2 3 4 5 6 7 8 9
----------------------------------------
0 | 0 0 0 0 0 0 0 0 0 0
1 | 0 1 2 3 4 5 6 7 8 9
2 | 0 2 4 6 8 10 12 14 16 18
3 | 0 3 6 9 12 15 18 21 24 27
4 | 0 4 8 12 16 20 24 28 32 36
5 | 0 5 10 15 20 25 30 35 40 45
6 | 0 6 12 18 24 30 36 42 48 54
7 | 0 7 14 21 28 35 42 49 56 63
8 | 0 8 16 24 32 40 48 56 64 72
9 | 0 9 18 27 36 45 54 63 72 81
字体大小为12像素,每行占用15像素.

使用do/while循环,写一个窗口小程序MultiplicationTableApplet.java 显示如下:0 1 2 3 4 5 6 7 8 9 ----------------------------------------0 | 0 0 0 0 0 0 0 0 0 0 1 | 0 1 2 3 4 5 6 7 8 9 2 | 0 2 4 6 8 10 12 14 16 18 3 | 0 3 6 9 12 15 18 2

import javax.swing.*;

import javax.swing.table.*;

import java.awt.*;

import java.applet.*;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

 

 

public class MultiplicationTableApplet extends Applet implements ActionListener{

  JLabel label, rowl, coll;

  JTextField cols, rows;

  JButton create;

  JScrollPane scrollpanel;

 

  public void init(){

    label = new JLabel();

    rowl = new JLabel("行");

    coll = new JLabel("列");

    scrollpanel = new JScrollPane(label);

   

    cols=new JTextField("9", 8);

    cols.setForeground(Color.gray);

    cols.setEditable(true);

    rows=new JTextField("9", 8);

    rows.setForeground(Color.gray);

    rows.setEditable(true);

 

    create=new JButton("生成");

    add(rowl);

    add(rows);

    add(coll);

    add(cols);

    add(create);

    add(scrollpanel);

 

    create.addActionListener(this);

  }

 

  @Override

  public void actionPerformed(ActionEvent e){

    int col=0, row=0;

    StringBuffer sb = new StringBuffer();

   

    if(e.getSource()==create) {

      row = Integer.valueOf(rows.getText().trim())+1;

      col = Integer.valueOf(cols.getText().trim())+1;

     

      sb.append("<html>\n\r");

      sb.append("<head>\n\r");

      sb.append("<style type=text/css>\n\r");

      sb.append("<!-- #dataTable {\n\r");

      sb.append(" BORDER: #000000 1px solid;\n\r");

      sb.append(" BORDER-COLLAPSE: collapse;\n\r");

      sb.append("}\n\r");

      sb.append("#td {\n\r");

      sb.append(" BORDER: #000000 1px solid;\n\r");

      sb.append(" BORDER-COLLAPSE: collapse;\n\r");

      sb.append("}\n\r");

      sb.append("--></style>\n\r");

      sb.append("</head>\n\r");

      sb.append("<table id='dataTable' style='margin-right: auto; margin-left: auto;' >\n\r");

      sb.append("<tr>\n\r<th id='td'>&nbsp;</th>\n\r");

     

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

        sb.append("<th id='td' style='font: bold;'>"+ i +"列</th>\n\r");

      }

      sb.append("</tr>\n\r");

     

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

        sb.append("<tr>\n\r");

        sb.append("<td id='td' style='font: bold;'>"+ i +"行</td>\n\r");

        for (int j=0; j<col; j++) {

          sb.append("<td id='td'>"+ (i*j) +"</td>\n\r");

        }

        sb.append("</tr>\n\r");

      }

      sb.append("</table>\n\r");

      sb.append("</html>\n\r");

//      System.out.println(sb.toString());

      label.setText(sb.toString());

      validate();

    }

  }

 

}

 

 

HTML:

<applet code="MultiplicationTableApplet.class" width="450" height="350" ></applet>

 

效果图: