Screen

xiaoxiao2021-03-05  26

This is a screen saver analog program that displays a diamond to simulate the screensaver with full screen. For the displayed graphics, you can write your own write algorithm.

Note: This program cannot be actually embedded in Windows screensaver like a screensaver developed by VC, which is just an simulation.

Source code:

Screen.java

Import java.aw. *; import javax.swing. *;

class Screen extends JFrame {public Screen () {DisplayMode displayMode = new DisplayMode (1024, 768, 16, DisplayMode.REFRESH_RATE_UNKNOWN); run (displayMode);} public void run (DisplayMode displayMode) {setBackground (Color.black); setForeground ( Color.White); SetFont (New Font ("Dialog", 0, 24));

ScreenManager Screen = new screenManager (); try {screen.setfullscreen (displaymode, this);} catch (exception e) {E.PrintStackTrace ();}}

Public Void Paint (Graphics G) {Diamond (G);} public void diamond (graphics g) {int x [] = new int [100]; int y [] = new int =, int R = 300, N = 20, X0 = 512, Y0 = 384; Double T; T = 2 * math.pi / n; for (int i = 0; i

ScreenManager.java

Import java.awt. *; import java.awt.event. *; import javax.swing. *;

Public class screenManager {private graphicsdevice device DEVICE DEVICE DEVICE

Public screenManager () {graphicsenvironment environment = graphicsenvironment.getlocalgraphicsenvironment (); device = environment.getDefaultscreenDevice ();

public void setFullScreen (DisplayMode displayMode, JFrame window) {window.setUndecorated (true); window.setResizable (false); device.setFullScreenWindow (window); if (! displayMode = null && device.isDisplayChangeSupported ()) {try {device. setDisplayMode (displayMode);} catch (IllegalArgumentException ex) {ex.printStackTrace ();}} window.addMouseListener (new MouseL (window));} public window getFullScreenWindow () {return device.getFullScreenWindow ();} public void restoreScreen ( ) {window window = device.getFullScreenWindow (); if (window = null) {window.dispose ();!} device.setFullScreenWindow (null);} class MouseL extends MouseAdapter {JFrame window; public MouseL (JFrame window) {this .window = window;} public void mouseclicked (mouseevent e) {jPanel PWP = new jPanel (); J TextField pwTF = new JTextField (5); pwP.add (new JLabel ( "PassWord")); pwP.add (pwTF); if (JOptionPane.showConfirmDialog (window, pwP, "PassWord", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE ) == JOPTIONPANE.OK_OPTION {IF ((PWTF.GetText ()). Equals ("pluto")) {window.dispose ();} else {jPanel errorp = new jPanel (); errorp.add (New Jlabel) "Sorry, your password you entered is wrong")); JOPTIONPANE.SHOWMESSAGEDIALOG (Window, ErrorP, "Error", JOPTIONPANE.YES_OPTION;}}}}}

Screensaver.java

Import java.util. *; import java.awt. *; import java.awt.event. *; import javax.swing. *;

转载请注明原文地址:https://www.9cbs.com/read-35843.html

New Post(0)