刺猬在天冷时围抱取暖,但保持一定距离避免相互刺|

jinganglang567

园龄:4年5个月粉丝:0关注:20

2023-07-22 14:47阅读: 7评论: 0推荐: 0

表白程序

super关键字

  • super可以用来引用直接父类的实例变量。
  • super可以用来调用直接父类方法。
  • super()可以用于调用直接父类构造函数

线程编程

实现线程编程有两种方式

  1. 接口:自定义的类去实现Runnable接口,这个类就具有了线程的功能,实现接口之前必须对接口中的方法进行重写
  2. 继承:自定义的类去继承Thread类,自定义的类就具有了线程的功能
  3. 启动线程,创建线程对象,将还有线程的类作为参数传入,然后调用start方法
 Thread thread = new Thread(mypanel);

 thread.start();

实现接口中的run方法

run()作用 1.表示线程执行的任务处理方法,交给线程处理的业务逻辑放在run方法中

  1. 线程的run()由Jvm调用

package com.cy;

import javax.swing.*;
import java.awt.*;
import java.beans.PropertyVetoException;

public class mypanel extends JPanel implements Runnable {
    /**
     * 绘制图形,需要画布,画笔,继承jpanel
     */
    int x[]=new int[300];
    int y[]=new int[300];
    public mypanel(){
        for (int i = 0; i <300 ; i++) {
            x[i]=(int)(Math.random()*1024);
            y[i]=(int) (Math.random()*768);
        }
    }
    public void paint(Graphics g){
        super.paint(g);//调用jpanel中的paint函数,完成初始化
        this.setBackground(Color.BLACK);

        //绘制字体
        g.setColor(Color.white);//设置画笔白色

        //设置字体样式 字体样式 风格0默认 14号字体
        g.setFont(new Font("",0,14));

        //添加椭圆
        g.fillOval(100,100,80,80);

//        g.drawString("love",100,100); //设置具体位置绘画内容

        //绘制满屏love
//        Math.random()生成随机数再0,1之间,所以随机坐标设置
        for (int i = 0; i <300 ; i++) {
            g.drawString("love",x[i],y[i]);
        }
    }

    @Override
    public void run() {
        while (true){
            for (int i = 0; i <300 ; i++) {
                y[i]++;
                if (y[i]>768){y[i]=0;}

            }


            try {
                Thread.sleep(30); //线程执行这里时,会停顿相应的时间
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            //不断刷新窗口,才能展示动画效果
            repaint();

        }

    }
}


package com.cy;

import javax.swing.*;

public class star {
    public static void main(String[] args) {

        //画图三件套 jframe画板 jpanel画纸 graphics画笔
        JFrame jFrame = new JFrame("star"); //设置窗口的相关属性
        jFrame.setSize(1024,768);
        jFrame.setLocationRelativeTo(null);//设置窗口居中
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置双向关闭,关闭窗口程序终止,程序终止窗口关闭

        //设置画布对象,添加到画板窗口
        mypanel mypanel = new mypanel();
        jFrame.add(mypanel);

        Thread thread = new Thread(mypanel);

        thread.start();

        jFrame.setVisible(true);//设置窗口可见

    }
}

本文作者:jinganglang567

本文链接:https://www.cnblogs.com/tgfoven/p/17573369.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   jinganglang567  阅读(7)  评论(0编辑  收藏  举报
  1. 1 look after you louis tomlinson
  2. 2 just hold on louis tomlinson
  3. 3 i can steven cooper
  4. 4 rock me one direction
  5. 5 just can't let her go one direction
  6. 6 this town Niall Horan
  7. 7 cut in love july
  8. 8 nemo 夜愿
  9. 9 in the end Black Veil Brides
  10. 10 glad you came the wanted
  11. 11 chasing the sun the wanted
  12. 12 TAKE MY HAND simple plan
  13. 13 wish i had an angel 夜愿
just hold on - louis tomlinson
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

作词 : Sasha Alex Sloan/Eric Rosse

作曲 : Steve Aoki/Louis Tomlinson/Sasha Alex Sloan/Nolan Lambroza/Eric Rosse

Wish that you could build a time machine

So you could see

The things no one can see

Feels like you're standing on the edge

Looking at the stars

And wishing you were them

What do you do when a chapter ends?

Do you close the book and never read it again?

Where do you go when your story's done?

You can be who you were or who you'll become

Oooh

If it all goes wrong

Oooh

Darling just hold on

The sun goes down and it comes back up

The world it turns no matter what

Oooh

If it all goes wrong

Darling just hold on

Oooh

Darling just hold on

Oooh

It's not over until it's all been said

It's not over until your dying breath

So what do you want them to say when you're gone?

That you gave up or that you kept going on?

What do you do when a chapter ends?

Do you close the book and never read it again?

Where do you go when your story's done?

You can be who you were or who you'll become

Oooh

If it all goes wrong

Oooh

Darling just hold on

The sun goes down and it comes back up

The world it turns no matter what

Oooh

If it all goes wrong

Darling just hold on

Oooh

Darling just hold on

Oooh

Oooh

If it all goes wrong

Oooh

Darling just hold on

Oooh

If it all goes wrong

Darling just hold on

点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起