0 Members and 1 Guest are viewing this topic.
import java.awt.*;import javax.swing.JFrame;public class Screen { private GraphicsDevice vc; //Allows access to Graphics Card public Screen() { GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); vc = env.getDefaultScreenDevice(); } public void setFullScreen(DisplayMode dm, JFrame window) { window.setUndecorated(true); window.setResizable(false); vc.setFullScreenWindow(window); if (dm != null && vc.isDisplayChangeSupported()) { try { vc.setDisplayMode(dm); } catch(Exception ex) { } } } public Window getFullScreenWindow() { return vc.getFullScreenWindow(); } public void restoreScreen() { Window w = vc.getFullScreenWindow(); if (w != null) { w.dispose(); } vc.setFullScreenWindow(null); } }
import java.awt.*;import javax.swing.ImageIcon;import javax.swing.JFrame;public class Images extends JFrame { public static void main(String[] args) { DisplayMode dm = new DisplayMode(800,600,16,DisplayMode.REFRESH_RATE_UNKNOWN); Images i = new Images(); i.run(dm); } private Screen s; private Image bg; private Image pic; private boolean loaded; //run method public void run(DisplayMode dm) { setForeground(Color.WHITE); setFont(new Font("Arial", Font.PLAIN, 24)); loaded = false; s = new Screen(); try { s.setFullScreen(dm, this); loadpics(); try { Thread.sleep(5000); } catch (Exception ex) {} } finally { s.restoreScreen(); } } public void loadpics() { bg = new ImageIcon("background.jpeg").getImage(); pic = new ImageIcon("face.png").getImage(); loaded = true; repaint(); } public void paint(Graphics g) { if (g instanceof Graphics2D) { Graphics2D g2 = (Graphics2D)g; //Typecasting g to Graphics2D g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } if (loaded) { g.drawImage(bg,0,0,null); g.drawImage(pic,170,180,null); } }}
catch(Exception ex) { System.out.println("An error occurred: " + ex); }
catch(Exception ex) { }
System.out.println(vc.isDisplayChangeSupported());
if (dm != null && vc.isDisplayChangeSupported()) {
An error occurred in FullScreen: java.lang.IllegalArgumentException: Invalid display mode
Image bg;image pic;bg = new ImageIcon("background.jpeg").getImage();pic = new ImageIcon("face.png").getImage();
import java.awt.image.*;import javax.imageio.*;BufferedImage bg;BufferedImage pic;bg = ImageIO.read(getClass().getResource("background.jpeg"))pic = ImageIO.read(getClass().getResource("face.png"))
for(DisplayMode dm : vc.getDisplayModes())System.out.println(dm);
DisplayMode dm = new DisplayMode(800,600,16,DisplayMode.REFRESH_RATE_UNKNOWN);