我想知道,如何让输入的网址 在新的浏览器中打开,大概要用到什么方法?import java.applet.*; import java.awt.*; import java.net.*; import javax.swing.*;public class w6 extends Applet{ Image a ; public void init() { }
public void paint(Graphics g) { a = getImage(getDocumentBase(), "2.jpg"); g.drawImage(a,2,3,this); double x = a.getWidth(this); double y = a.getHeight(this); g.drawImage(a,200,3,x * 2, y * 2,this); //提示找不到符号??? } }关于图片的那个为何提示找不到符号?
下面的过程是开浏览器打开指定的页面, 支持多平台public boolean showInBrowser(String url){ String os = System.getProperty("os.name").toLowerCase(); Runtime rt = Runtime.getRuntime(); try{ if (os.indexOf( "win" ) >= 0) { // this doesn't support showing urls in the form of "page.html#nameLink" rt.exec( "rundll32 url.dll,FileProtocolHandler " + url); } else if (os.indexOf( "mac" ) >= 0) { rt.exec( "open " + url); } else if (os.indexOf( "nix") >=0 || os.indexOf( "nux") >=0) { // Do a best guess on unix until we get a platform independent way // Build a list of browsers to try, in this order. String[] browsers = {"epiphany", "firefox", "mozilla", "konqueror", "netscape","opera","links","lynx"};
// Build a command string which looks like "browser1 "url" || browser2 "url" ||..." StringBuffer cmd = new StringBuffer(); for (int i=0; i<browsers.length; i++) cmd.append( (i==0 ? "" : " || " ) + browsers[i] +" \"" + url + "\" ");
import java.awt.*;
import java.net.*;
import javax.swing.*;public class w6 extends Applet{
Image a ; public void init()
{
}
public void paint(Graphics g) {
a = getImage(getDocumentBase(), "2.jpg");
g.drawImage(a,2,3,this);
double x = a.getWidth(this);
double y = a.getHeight(this);
g.drawImage(a,200,3,x * 2, y * 2,this); //提示找不到符号???
}
}关于图片的那个为何提示找不到符号?
String os = System.getProperty("os.name").toLowerCase();
Runtime rt = Runtime.getRuntime();
try{
if (os.indexOf( "win" ) >= 0) {
// this doesn't support showing urls in the form of "page.html#nameLink"
rt.exec( "rundll32 url.dll,FileProtocolHandler " + url);
} else if (os.indexOf( "mac" ) >= 0) {
rt.exec( "open " + url);
} else if (os.indexOf( "nix") >=0 || os.indexOf( "nux") >=0) {
// Do a best guess on unix until we get a platform independent way
// Build a list of browsers to try, in this order.
String[] browsers = {"epiphany", "firefox", "mozilla", "konqueror",
"netscape","opera","links","lynx"};
// Build a command string which looks like "browser1 "url" || browser2 "url" ||..."
StringBuffer cmd = new StringBuffer();
for (int i=0; i<browsers.length; i++)
cmd.append( (i==0 ? "" : " || " ) + browsers[i] +" \"" + url + "\" ");
rt.exec(new String[] { "sh", "-c", cmd.toString() });
} else {
return false;
}
}catch (IOException e){
return false;
}
return true;
}那个提示找不到符号,因为第4,5个参数是double, 而api中定义是int