十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團隊
量身定制 + 運營維護+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
html
在承德縣等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供網(wǎng)站制作、成都網(wǎng)站制作 網(wǎng)站設(shè)計制作按需規(guī)劃網(wǎng)站,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),成都營銷網(wǎng)站建設(shè),外貿(mào)網(wǎng)站建設(shè),承德縣網(wǎng)站建設(shè)費用合理。
head
script
function move(){
var x = Math.floor(Math.random()*800);
var y = Math.floor(Math.random()*600);
var r = Math.floor(Math.random()*16).toString(16);
var g = Math.floor(Math.random()*16).toString(16);
var b = Math.floor(Math.random()*16).toString(16);
document.getElementById("prank1").style.marginLeft = x+"px";
document.getElementById("prank1").style.marginTop = y+"px";
x = Math.floor(Math.random()*800);
y = Math.floor(Math.random()*600);
r = Math.floor(Math.random()*16).toString(16);
g = Math.floor(Math.random()*16).toString(16);
b = Math.floor(Math.random()*16).toString(16);
document.getElementById("prank2").style.marginLeft = x+"px";
document.getElementById("prank2").style.marginTop = y+"px";
document.body.style.background ="#"+r+g+b;
}
function win(){
alert("You Win!!!");
}
/script
/head
body
button id="close" onclick="window.close()"close window/button
button id="prank1" onMouseMove="move()" onClick="win()"Click Me/button
button id="prank2" onMouseMove="move()" onClick="win()"Click Me/button
/body
/html
可以使用 Desktop ,例如:
Desktop.getDesktop().browse(new?URI("網(wǎng)址"));
這樣可以打開一個網(wǎng)址,瀏覽器也自然打開了。
可以使用 Runtime 打開指定的瀏覽器,例如下面打開 谷歌瀏覽器。
Runtime.getRuntime().exec("C:\\Program?Files?(x86)\\Google\\Chrome\\Application\\chrome.exe");
我來梳理思路并給你講下邏輯和流程
Java想要實現(xiàn)電腦開機自動打開瀏覽器網(wǎng)站需要借助的是開機自啟的EXE,Java自身是不可能繞開系統(tǒng)這一關(guān)的,Windows下的話必須要借助注冊表一類的,實現(xiàn)開機自啟EXE,然后通過EXE執(zhí)行打開瀏覽器訪問指定地址的網(wǎng)站。
思路明確后,我們需要的是一個成品的EXE
代碼上我就不過多解釋了,直接用下面的代碼
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler "+url);
(就是通過默認瀏覽器直接打開指定網(wǎng)頁)
編寫好代碼后開始減小體積,也就是刪除不使用的類以及不使用的字符集編碼
確認瘦身后依舊運行正常后,開始進行壓縮,建議是用pack200,效果賊好
然后把程序打成jar包,然后在上層目錄編寫啟動批處理
編寫完成后測試程序能否正常啟動,如果不行就檢查下是不是少類了
然后把批處理編成EXE,QBFC比較好用,如果做安裝包的話記得掛G模式,InnoSetup這里也可以耍一下
這個時候我們就獲取到了一個安裝腳本,然后我們要做的就是修改安裝腳本的代碼
在腳本中加上下面的一段
[Registry]
Root: HKLM; Subkey: "SOFTWARE/Microsoft/Windows/CurrentVersion/Run"; ValueType: string; ValueName: "程序名"; ValueData: """{app}/main.exe"" ""{app}/jre/bin"""
直接使用這個時候的安裝腳本和安裝包就可以實現(xiàn)了
開機自動啟動這個編寫好的EXE,然后這個EXE就自動打開默認瀏覽器并訪問指定網(wǎng)頁了
package com.test;
import java.lang.reflect.Method;
//實現(xiàn)打開瀏覽器并跳到指定網(wǎng)址的類
public class BareBonesBrowserLaunch {
public static void openURL(String url) {
try {
browse(url);
} catch (Exception e) {
}
}
private static void browse(String url) throws Exception {
//獲取操作系統(tǒng)的名字
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++)
//執(zhí)行代碼,在brower有值后跳出,
//這里是如果進程創(chuàng)建成功了,==0是表示正常結(jié)束。
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
//這個值在上面已經(jīng)成功的得到了一個進程。
Runtime.getRuntime().exec(new String[] { browser, url });
}
}
}
//主方法 測試類
public static void main(String[] args) {
String url = "";
BareBonesBrowserLaunch.openURL(url);
}
朋友,覺得好的話,請采納!你的鼓勵是我學(xué)習(xí)的動力。