• java没事瞎写的小程序


    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();
    }
    }

  • 相关阅读:
    SDN第二次作业
    SDN第一次上机作业
    SDN第一次作业
    alpha冲刺第四天
    alpha冲刺第二天
    alpha冲刺第一天
    项目需求分析
    结对第二次作业
    团队选题报告(i know)
    结对作业——原型设计
  • 原文地址:https://www.cnblogs.com/nanfengnan/p/13675820.html
Copyright © 2020-2023  润新知