Java实现全屏的四种方式(四个例子)【附源码】_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > Java实现全屏的四种方式(四个例子)【附源码】

Java实现全屏的四种方式(四个例子)【附源码】

 2011/11/29 10:14:27  xp9802  http://xp9802.iteye.com  我要评论(0)
  • 摘要:FullScreenDemo.java:packageFullScreenDemo;importjava.awt.*;importjavax.swing.*;/***@authorhttp://xp9802.iteye.com/*2011-11-19下午04:40:38*/publicclassFullScreenDemo{publicstaticvoidmain(String[]args){finalJFramejframe=newJFrame()
  • 标签:实现 源码 例子 Java 方式

FullScreenDemo.java:

package FullScreenDemo;

import java.awt.*;

import javax.swing.*;

/**
 * @author http://xp9802.iteye.com/
 * 2011-11-19下午04:40:38
 */
public class FullScreenDemo {

	public static void main(String[] args) {
		final JFrame jframe = new JFrame();
		JButton fullsButton = new JButton("全屏显示");
		JButton exitButton = new JButton("退出");
		exitButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				System.exit(1);
			}
		});
		fullsButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
				//通过调用GraphicsEnvironment的getDefaultScreenDevice方法获得当前的屏幕设备了
				GraphicsDevice gd = ge.getDefaultScreenDevice();
				// 全屏设置
				gd.setFullScreenWindow(jframe);
			}
		});
		jframe.add(fullsButton);
		jframe.add(exitButton);
		jframe.setLayout(new FlowLayout());
		jframe.setSize(400, 300);
		jframe.setVisible(true);
	}
}

?

?

?

FullScreenDemo1.java:

?

?

package FullScreenDemo;

import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.UIManager;

/**
 * @author http://xp9802.iteye.com/
 * 2011-11-19下午04:31:38
 */
public class FullScreenDemo1 {

	public static void main(String[] args) {
		JFrame jframe = new JFrame();
		JButton exitButton = new JButton("退出");
		exitButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				System.exit(1);
			}
		});
		jframe.add(exitButton);
		jframe.setLayout(new FlowLayout());
		jframe.setUndecorated(false);
		jframe.getGraphicsConfiguration().getDevice()
				.setFullScreenWindow(jframe);
		jframe.setVisible(true);
	}
}

?

?

FullScreenDemo2.java:

?

package FullScreenDemo;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Toolkit;

import javax.swing.JButton;
import javax.swing.JFrame;


/**
 * @author http://xp9802.iteye.com/
 * 2011-11-19下午04:32:38
 */
public class FullScreenDemo2 {
	public static void main(String[] args) {
		JFrame jframe = new JFrame();
		JButton exitButton = new JButton("退出");
		exitButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				System.exit(1);
			}
		});
		jframe.add(exitButton);
		jframe.setLayout(new FlowLayout());
		/**
		 * true无边框 全屏显示
		 * false有边框 全屏显示
		 */
		jframe.setUndecorated(false);
		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
		jframe.setSize(d.width, d.height);
		jframe.setVisible(true);
	}
}

?

?

?

FullScreenDemo3.java:

?

?

package FullScreenDemo;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Rectangle;
import java.awt.Toolkit;

import javax.swing.JButton;
import javax.swing.JFrame;

/**
 * @author http://xp9802.iteye.com/
 * 2011-11-19下午04:39:38
 */
public class FullScreenDemo3 {

	public static void main(String[] args) {
		JFrame jframe = new JFrame();
		JButton exitButton = new JButton("退出");
		exitButton.addActionListener(new java.awt.event.ActionListener() {

			public void actionPerformed(java.awt.event.ActionEvent evt) {
				System.exit(1);
			}
		});
		jframe.add(exitButton);
		jframe.setLayout(new FlowLayout());
		/**
		 * true无边框 全屏显示
		 * false有边框 全屏显示
		 */
		jframe.setUndecorated(false);
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		Rectangle bounds = new Rectangle(screenSize);
		jframe.setBounds(bounds);
		jframe.setExtendedState(JFrame.MAXIMIZED_BOTH);
		jframe.setVisible(true);
	}
}

?

?

?源码解压密码为:xp9802.iteye.com

  • FullScreenDemo.zip (2.9 KB)
  • 下载次数: 68
发表评论
用户名: 匿名