重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
import javax.swing.*;
成都创新互联公司主要从事成都网站设计、做网站、网页设计、企业做网站、公司建网站等业务。立足成都服务珠海,10余年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:13518219792
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import javax.swing.event.*;
@SuppressWarnings("serial")
class Win3 extends JFrame implements ActionListener,Runnable
{
JButton button;
URL url;
JTextField text;
JEditorPane editPane;
byte b[]=new byte[118];
Thread thread;
public Win3()
{
text=new JTextField(20);
editPane=new JEditorPane();
editPane.setEditable(false);
button=new JButton("确定");
button.addActionListener(this);
thread=new Thread(this);
JPanel p=new JPanel();
p.add(new JLabel("输入网址:"));
p.add(text);
p.add(button);
Container con=getContentPane();
con.add(new JScrollPane(editPane),BorderLayout.CENTER);
con.add(p,BorderLayout.NORTH);
setBounds(60,60,400,300);
setVisible(true);
validate();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
editPane.addHyperlinkListener(new HyperlinkListener()
{
public void hyperlinkUpdate(HyperlinkEvent e)
{
if(e.getEventType()==
HyperlinkEvent.EventType.ACTIVATED)
{
try{
editPane.setPage(e.getURL());
}
catch(IOException e1)
{
editPane.setText(""+e1);
}
}
}
}
);
}
public void actionPerformed(ActionEvent e)
{
if(!(thread.isAlive()))
thread=new Thread(this);
try{
thread.start();
}
catch(Exception ee)
{
text.setText("我正在读取"+url);
}
}
public void run()
{
try {
int n=-1;
editPane.setText(null);
url=new URL(text.getText().trim());
editPane.setPage(url);
}
catch(MalformedURLException e1)
{
text.setText(""+e1);
return;
}
catch(IOException e1)
{
text.setText(""+e1);
return;
}
}
}
public class Example3
{
public static void main(String args[])
{
new Win3();
}
}
html
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
网页地址在代码中的java代码写法如下:
packagecom.test;
importjava.lang.reflect.Method;
//实现打开浏览器并跳到指定网址的类
publicclassBareBonesBrowserLaunch{
publicstaticvoidopenURL(Stringurl){
try{
browse(url);
}catch(Exceptione){
}
}
privatestaticvoidbrowse(Stringurl)throwsException{
//获取操作系统的名字
StringosName=System.getProperty("os.name","");
if(osName.startsWith("MacOS")){
//苹果的打开方式
ClassfileMgr=Class.forName("com.apple.eio.FileManager");
MethodopenURL=fileMgr.getDeclaredMethod("openURL",newClass[]{String.class});
openURL.invoke(null,newObject[]{url});
}elseif(osName.startsWith("Windows")){
//windows的打开方式。
Runtime.getRuntime().exec("rundll32url.dll,FileProtocolHandler"+url);
}else{
//UnixorLinux的打开方式
String[]browsers={"firefox","opera","konqueror","epiphany","mozilla","netscape"};
Stringbrowser=null;
for(intcount=0;countbrowsers.lengthbrowser==null;count++)
//执行代码,在brower有值后跳出,
//这里是如果进程创建成功了,==0是表示正常结束。
if(Runtime.getRuntime().exec(newString[]{"which",browsers[count]}).waitFor()==0)
browser=browsers[count];
if(browser==null)
thrownewException("Couldnotfindwebbrowser");
else
//这个值在上面已经成功的得到了一个进程。
Runtime.getRuntime().exec(newString[]{browser,url});
}
}
}
//主方法测试类
publicstaticvoidmain(String[]args){
Stringurl="";
BareBonesBrowserLaunch.openURL(url);
}
webBrowser.addWebBrowserListener(new WebBrowserAdapter() {
// 监听加载进度
public void loadingProgressChanged(WebBrowserEvent e) {
// 当加载完毕时
if (e.getWebBrowser().getLoadingProgress() == 100) { }
}
}