网站建设资讯

NEWS

网站建设资讯

关于屏保动画java代码的信息

如何使用java程序实现windows锁屏

先请编译和运行下面程序:

创新互联专业为企业提供凉州网站建设、凉州做网站、凉州网站设计、凉州网站制作等企业网站建设、网页设计与制作、凉州企业网站模板建站服务,十年凉州做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

import java.util.*;

import java.io.*;

public class BadExecJavac2

{

public static void main(String args[])

{

try

{

Runtime rt = Runtime.getRuntime();

Process proc = rt.exec("javac");

int exitVal = proc.waitFor();

System.out.println("Process exitValue: " + exitVal);

} catch (Throwable t){

t.printStackTrace();

}

}

}

我们知道javac命令,当不带参数运行javac

程序时,它将输出帮助说明,为什么上面程序不产生任何输出并挂起,永不完成呢?java文档上说,由于有些本地平台为标准输入和输出流所提供的缓冲区大小

有限,如果不能及时写入子进程的输入流或者读取子进程的输出流,可能导致子进程阻塞,甚至陷入死锁。所以,上面的程序应改写为:

import java.util.*;

import java.io.*;

public class MediocreExecJavac

{

public static void main(String args[])

{

try

{

Runtime rt = Runtime.getRuntime();

Process proc = rt.exec("javac");

InputStream stderr = proc.getErrorStream();

InputStreamReader isr = new InputStreamReader(stderr);

BufferedReader br = new BufferedReader(isr);

String line = null;

System.out.println("");

while ( (line = br.readLine()) != null)

System.out.println(line);

System.out.println("");

用Java编制一个桌面弹球的屏幕保护程序。

很麻烦,屏幕保护程序,是一定格式的.exe文件来的。JAVA程序要转成纯.exe还有些困难。

自己写一个.exe根据不同的参数启动JAVA程序,还可以。

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

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=0;i100;i++){

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

}

求助!java设计windows屏保问题!!

说明屏幕保护是自动切换的。可以调整下: 第一步:在桌面空白位置右击,选择“个性化”。 第二步:在个性化页面,选择“桌面背景”。 第三步:之后在“背景设置”页面中,勾选上想设置背景的图片(一张的话,不需要设置切换时间,多张的话,设置下切换...

求一个简单的java屏保小程序,要求代码简单,易理解,要独创的,没有的,或者直接从网上荡的,直接别来!

protected void paint(Graphics g) {

// TODO Auto-generated method stub

g.setColor(255,0,0);

g.fillRect(0, 0, this.getWidth(), this.getHeight());

g.setColor(0,0, 255);

g.fillArc(x,y,d,d,0,360);

this.repaint();

}//画一个圆当做屏保图案坐标是x,y 大小是d

public void run() {

// TODO Auto-generated method stub

while(true){

if(x=0){

dir=ran.nextInt(8);

while(dir==0||dir==3||dir==5)

dir=ran.nextInt(8);

}else if(y=0){

dir=ran.nextInt(8);

while(dir==0||dir==1||dir==2)

dir=ran.nextInt(8);

}else if(x=w){

dir=ran.nextInt(8);

while(dir==2||dir==4||dir==7)

dir=ran.nextInt(8);

}else if(y=h){

dir=ran.nextInt(8);

while(dir==5||dir==6||dir==7)

dir=ran.nextInt(8);

}

switch(dir)

{

case 0: y-=5;x-=5; break;

case 1: y-=5; break;

case 2: y-=5;x+=5; break;

case 3: x-=5; break;

case 4: x+=5; break;

case 5: y+=5;x-=5; break;

case 6: y+=5; break;

case 7: y+=5;x+=5; break;

}

try {

Thread.currentThread().sleep(30);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

this.repaint();

}

//这个撞到墙壁小球就会随机变换方向 达到屏保的效果

给你个思路啊 自己填完整了他

如何用java写一个屏保程序

看看这个试试!

import java.text.*;

import java.awt.*;

import javax.swing.*;

import java.awt.geom.*;

import java.util.*;

import java.awt.event.*;

/**

*

*

*/

public class ScreenTest extends JPanel implements Runnable{

/** Creates a new instance of ScreenTest */

private String time;

private Rectangle2D rd;

private int x,y,a,b;//座标值和方向值

private int rgb=0;//颜色的值

private Color color;//字体的颜色

private int width,height;//屏幕的大小

public ScreenTest(int width,int height) {

this.width=width;

this.height=height;

initWindow();

}

private void initWindow(){

x=(int)(Math.random()*300);

y=(int)(Math.random()*500);

a=1;

b=1;

this.setBackground(Color.BLACK);

this.setOpaque(true);

rd=new Rectangle2D.Double(10,10,101,10);

color=Color.YELLOW;

}

private void doColor(){

rgb=(int)(Math.random()*0xFFFFFF);

color=new Color(rgb);

}

public void paintComponent(Graphics g){

g.setColor(Color.BLACK);

g.fillRect(0,0,width,height);

g.setColor(color);

g.setFont(new Font("楷书",Font.BOLD,150));

FontMetrics fm=g.getFontMetrics();

rd=fm.getStringBounds(time,g);

g.drawString(time,x,(int)(y+rd.getHeight()));

}

private void doTime(){

Calendar cal=Calendar.getInstance();

DateFormat df=DateFormat.getTimeInstance(DateFormat.MEDIUM);

Date date=cal.getTime();

time=df.format(date);

x+=a;

y+=b;

double width1=rd.getWidth();

double height1=rd.getHeight();

rd.setRect(x,y,width1,height1);

if(rd.intersectsLine(width,0,width,height)){

doColor();

a=-1;

}

else if(rd.intersectsLine(0,0,0,height)){

doColor();

a=1;

}

else if(rd.getY()=-80){

doColor();

b=1;

}

else if(rd.intersectsLine(0,height,width,height)){

doColor();

b=-1;

}

}

public void run(){

while(true){

try{

Thread.sleep(2);

doTime();

repaint();

}

catch(InterruptedException ie){

ie.printStackTrace();

}

}

}

public static void main(String arsg[]){

GraphicsDevice gd=GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();

DisplayMode dm=gd.getDisplayMode();

int width=dm.getWidth();

int height=dm.getHeight();

System.out.println("width="+width+"\nheight="+height);

ScreenTest st=new ScreenTest(width,height);

final JFrame jf=new JFrame();

jf.getContentPane().add(st,BorderLayout.CENTER);

jf.setUndecorated(true);

gd.setFullScreenWindow(jf);

new Thread(st).start();

jf.addKeyListener(new KeyAdapter(){

public void keyReleased(KeyEvent ke){

if(ke.getKeyCode()==KeyEvent.VK_NUMPAD0)

System.exit(0);

}

});

}

}


网站栏目:关于屏保动画java代码的信息
分享路径:http://cdweb.net/article/hcedjd.html