窗口类:package Shiyan;
import javax.swing.*;
public class chuangkou {
public chuangkou(){
super();
setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
((Object) getContentPane()).add(new Mypane1());
}
private void setSize(int defaultWidth, int defaultHeight) {
// TODO Auto-generated method stub
}
private Object getContentPane() {
// TODO Auto-generated method stub
return null;
}
public static final int DEFAULT_WIDTH=300;
public static final int DEFAULT_HEIGHT=300;
public void setVisible(boolean b) {
// TODO Auto-generated method stub
}
public void setDefaultCloseOperation(int exitOnClose) {
// TODO Auto-generated method stub
}
}
内函数:
package Shiyan;
import java.awt.*;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.*;
public class Mypane1 {
public static final int DEFAULT_WIDTH=300;
public static final int DEFAULT_HEIGHT=300;
public Mypane1(){
setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
}
private void setSize(int defaultWidth, int defaultHeight) {
// TODO Auto-generated method stub
}
protected void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2=(Graphics2D)g;
Font font=new Font("黑体",Font.PLAIN,16);
g2.setFont(font);
g2.drawString("1
2
3
4
5
6
7
8
9",DEFAULT_WIDTH/2-100,60);
g2.drawString("=====================",DEFAULT_WIDTH/2-130,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<10;j++){
g2.drawString(new Integer(i*j).toString(),DEFAULT_WIDTH/2-122+j*24,76+i*18);
}
}
}
}
运行类:
package Shiyan;
import javax.swing.JFrame;
public class test {
public static void main(String[] ages){
chuangkou frame=new chuangkou();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}