
正文
java代码怎么弄成画面 怎么把java代码变成exe
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
如何用java设置全屏的代码
创建一个JFrame ,设置成undecorated,设置bounds为屏幕大小
//import 如下:
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Toolkit;
import javax.swing.JFrame;
代码如下:
JFrame frame = new JFrame();
frame.setUndecorated(true);
// 取得屏幕大小
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle bounds = new Rectangle( screenSize );
frame.setBounds( bounds );
frame.setVisibale(true);
相关问答
Q1: 写了一段java代码,怎么让它以桌面程序的形式运行?
创建一个记事本
在记事本中输入
java love1
然后另存为love1.bat
然后把这个bat文件和你的这个类编译后的class文件都丢到桌面上
双击运行bat文件
PS:如果你要想做成桌面exe,可以使用exe4j来打包,不过exe一般是针对有界面的cs程序
Q2: Java如何将一段HTML代码以网页的形式显示出来
可以把这段代码写在隐藏域里,如果需要把它显示出来的时候,用java取消隐藏域,就可以了吧。
Q3: java全是代码,怎么会做出非常漂亮的画面
唉java代码怎么弄成画面,给java代码怎么弄成画面你看看小Casejava代码怎么弄成画面的,自己运行一下
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class TranslucentButton extends JButton {
BufferedImage buttonImage = null;
/** Creates a new instance of TranslucentButton */
public TranslucentButton(String label) {
super(label);
setOpaque(false);
}
public void paint(Graphics g) {
// Create an image for the button graphics if necessary
if (buttonImage == null || buttonImage.getWidth() != getWidth() ||
buttonImage.getHeight() != getHeight()) {
buttonImage = getGraphicsConfiguration().
createCompatibleImage(getWidth(), getHeight());//返回一个数据布局和颜色模型与此 GraphicsConfiguration 兼容java代码怎么弄成画面的 BufferedImage
}
Graphics gButton = buttonImage.getGraphics();
gButton.setClip(g.getClip());//设置获取的当前的剪贴区域
// Have the superclass render the button for us
super.paint(gButton);
// Make the graphics object sent to this paint() method translucent
Graphics2D g2d = (Graphics2D)g;
AlphaComposite newComposite =
AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f);
g2d.setComposite(newComposite);
// Copy the button's image to the destination graphics, translucently
g2d.drawImage(buttonImage, 0, 0, null);
}
private static void createAndShowGUI() {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(300, 300);
JPanel checkerboard = new Checkerboard();
checkerboard.add(new TranslucentButton("Translucent Button"));
f.add(checkerboard);
f.setVisible(true);
}
public static void main(String args[]) {
Runnable doCreateAndShowGUI = new Runnable() {
public void run() {
createAndShowGUI();
}
};
SwingUtilities.invokeLater(doCreateAndShowGUI);//swing线程
}
private static class Checkerboard extends JPanel {
static final int CHECKER_SIZE = 60;
public void paintComponent(Graphics g) {
g.setColor(Color.white);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(Color.BLACK);
for (int stripeX = 0; stripeX getWidth(); stripeX += CHECKER_SIZE) {
for (int y = 0, row = 0; y getHeight(); y += CHECKER_SIZE/2, ++row) {
int x = (row % 2 == 0) ? stripeX : (stripeX + CHECKER_SIZE/2);
g.fillRect(x, y, CHECKER_SIZE/2, CHECKER_SIZE/2);
}
}
}
}
}
Q4: 用Java代码怎么在浏览器中显示一个网页
package com.test;
import java.lang.reflect.Method;
//实现打开浏览器并跳到指定网址的类
public class BareBonesBrowserLaunch {
public static void openURL(String url) {
try {
browse(url);
} catch (Exception e) {
}
}
private static void browse(String url) throws Exception {
//获取操作系统的名字
String osName = System.getProperty("os.name", "");
if (osName.startsWith("Mac OS")) {
//苹果的打开方式
Class fileMgr = Class.forName("com.apple.eio.FileManager");
Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] { String.class });
openURL.invoke(null, new Object[] { url });
} else if (osName.startsWith("Windows")) {
//windows的打开方式。
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
} else {
// Unix or Linux的打开方式
String[] browsers = { "firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape" };
String browser = null;
for (int count = 0; count browsers.length browser == null; count++)
//执行代码,在brower有值后跳出,
//这里是如果进程创建成功了,==0是表示正常结束。
if (Runtime.getRuntime().exec(new String[] { "which", browsers[count] }).waitFor() == 0)
browser = browsers[count];
if (browser == null)
throw new Exception("Could not find web browser");
else
//这个值在上面已经成功的得到了一个进程。
Runtime.getRuntime().exec(new String[] { browser, url });
}
}
}
Q5: java中装了swing拖拉界面,怎么样把我的代码变成界面显示
你用的是eclipse吗?如果是的,确保插件安装成功,重启eclipse后,在你要打开的类上右键选择open with 然后就有WindowBuilder选项,选择即可,如图。
打开之后代码界面和拖拉界面切换如图。
其中点击Design就是拖拉界面,点击source就是代码界面。
java代码怎么弄成画面的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于怎么把java代码变成exe、java代码怎么弄成画面的信息别忘了在本站进行查找喔。







