显示九九乘法口诀表
先来看看最终效果
![](https://img-blog.csdn.net/20170227195427721?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaWN1cmlvdXM=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
文件的组织
![](https://img-blog.csdn.net/20170227195530144?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaWN1cmlvdXM=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
代码
package mulframe;
import java.awt.*;
import javax.swing.*;
public class myPanel extends JPanel{
public static final int DEFAULT_WIDTH=400;
public static final int DEFAULT_HEIGHT=300;
public myPanel(){
setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
}
protected void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2=(Graphics2D)g;
Font font_ch=new Font("黑体",Font.PLAIN,16);
g2.setFont(font_ch);
g2.drawString("九九乘法口诀表", DEFAULT_WIDTH/2-60, 30);
Font font_en=new Font("微软雅黑",Font.PLAIN,12);
g2.setFont(font_en);
g2.drawString("MADE IN CHINA", DEFAULT_WIDTH/2-60, 60);
g2.drawString("===================================================================", DEFAULT_WIDTH/2-126, 76);
for(int i=1;i<10;i++){
g2.drawString(new Integer(i).toString(), DEFAULT_WIDTH/2-126, 76+i*18);
for(int j=1;j<=i;j++){
g2.drawString(j+"*"+i+"= "+new Integer(i*j).toString(), DEFAULT_WIDTH/2-122+j*54, 76+i*18);
}
}
}
}