用Java编写一个模拟屏幕保护程序,要求:

用Java编写一个模拟屏幕保护程序,要求:,第1张

import java.awt.Color

import java.awt.Graphics

import javax.swing.JFrame

public class app extends JFrame{

public void paint(Graphics g){

for (int i=0i<100i++){

Color c = new Color((int) (Math.random() * 255), (int) (Math

.random() * 255), (int) (Math.random() * 255))

g.setColor(c)

int srcX=(int)(Math.random() * 800)

int srcY=(int)(Math.random() * 600)

int destX=(int)(Math.random() * 800)

int destY = (int)(Math.random() * 600)

g.drawLine(srcX, srcY, destX, destY)

try {

Thread.sleep(1000)

} catch (InterruptedException e) {

// TODO 自动生成 catch 块

e.printStackTrace()

}

}

}

public app(){

this.setSize(800,600)

this.setVisible(true)

}

public static void main(String[] args) {

new app()

}

import java.awt.Color

import java.awt.Graphics

import javax.swing.JFrame

public class app extends JFrame{

public void paint(Graphics g){

for (int i=0i<100i++){

Color c = new Color((int) (Math.random() * 255), (int) (Math

.random() * 255), (int) (Math.random() * 255))

g.setColor(c)

int srcX=(int)(Math.random() * 800)

int srcY=(int)(Math.random() * 600)

int destX=(int)(Math.random() * 800)

int destY = (int)(Math.random() * 600)

g.drawLine(srcX, srcY, destX, destY)

try {

Thread.sleep(1000)

} catch (InterruptedException e) {

//册庆 TODO 自动生轿雀成 catch 块州帆握

e.printStackTrace()

}

}

}

public app(){

this.setSize(800,600)

this.setVisible(true)

}

public static void main(String[] args) {

new app()

}

}

Dim h%, w%

Private Sub Form_Load()

Randomize

h = 10

w = 15

Label1.AutoSize = True

Label1.FontSize = Int(10 + Rnd * 40)

Label1.ForeColor = QBColor(Int(Rnd * 16))

End Sub

Private Sub Timer1_Timer()

Label1.Left = Label1.Left + w

Label1.Top = Label1.Top + h

If Label1.Left <= 0 Or Label1.Left + Label1.Width >= Width Then

w = -w

Label1.FontSize = Int(10 + Rnd * 40)

Label1.ForeColor = QBColor(Int(Rnd * 16))

End If

If Label1.Top <= 0 Or Label1.Top + Label1.Height >= Height Then

h = -h

Label1.FontSize = Int(10 + Rnd * 40)

Label1.ForeColor = QBColor(Int(Rnd * 16))

End If

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12362123.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存