package result;
//先按确定,在敲键盘,会出现黑屏
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
class Ft extends JFrame{
JButton jButton = new JButton("开始");
public Ft() {
super("简单绘图");
setSize(500,500);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new FlowLayout());
jButton.setForeground(Color.cyan);
add(jButton);
jButton.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent event) {
//局部类
class Gf extends JFrame{
//内部类
class MyCanvas extends Canvas{
public MyCanvas() {
// TODO Auto-generated constructor stub
setSize(400,300);
}
public void paint(Graphics g) {
g.drawLine(0, 0, 100, 100);
g.fillRect(0, 0, 400, 300);
}
}
public Gf() {
// TODO Auto-generated constructor stub
super("绘图啦");
setSize(400,300);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
add(new MyCanvas());
//用内部类对象调用内部类
validate();
}
}
new Gf();
}
});
validate();
}
}
public class F8{
public static void main(String[] args) {
new Ft();
}
}