java有没有打开一个页面的方法? rt 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你说的是这个吗?try{ String command = "C:\\Program Files\\Internet Explorer\\Iexplore.exe www.csdn.net"; Runtime.getRuntime().exec(command); }catch(IOException ex){} 有没有别的方法? //Desktop是JDK1.6的新特性,可以用其中的browse方法调用默认的浏览器来打开网页import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.net.URI;import java.io.*;public class Browse extends JFrame{ private Container container; private Desktop desktop; private JLabel label; public Browse(){ super("Browse测试"); desktop = Desktop.getDesktop(); //Desktop类没有构造方法,只能用静态方法getDesktop返回当前浏览器上下文的 Desktop 实例 label = new JLabel(); label.setText("<html><A href='http://www.google.cn'>谷歌</A></html>");//让字体以超文本的方式显示 //为label注册鼠标监听器,若单击则打开网页 label.addMouseListener( new MouseAdapter(){ public void mouseClicked(MouseEvent event){ try{ desktop.browse(new URI("www.google.cn")); } catch(Exception e){ } } } ); container = getContentPane(); container.setLayout(new FlowLayout()); container.add(label); setVisible(true); pack(); setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //使窗口屏幕居中 Dimension frameSize,screenSize = Toolkit.getDefaultToolkit().getScreenSize(); frameSize = getSize(); setLocation((screenSize.width-frameSize.width)/2,(screenSize.height-frameSize.height)/2); } public static void main(String args[]){ Browse browse = new Browse(); }} LZ的意思我想应该是想用Java打开一个网络页面吧?//代码是收藏的import java.awt.BorderLayout;import javax.swing.JPanel;import javax.swing.JFrame;import javax.swing.JEditorPane;import java.awt.Rectangle;import javax.swing.JTextPane;import java.awt.Dimension;import java.awt.GridBagLayout;import java.awt.GridBagConstraints;import java.io.File;import java.io.IOException;import java.net.URL;import java.net.MalformedURLException;import javax.swing.JScrollPane;public class Lk extends JFrame {private static final long serialVersionUID = 1L;private JPanel jContentPane = null;private JPanel jPanel = null;private JScrollPane jScrollPane = null;private JTextPane jTextPane = null;public Lk() { super(); initialize(); try { String filepath="//help//1.html";////文件在工程下面的路径 File file=new File(""); //getAbsolutePath() 返回抽象路径名的绝对路径名字符串。 String path=file.getAbsolutePath()+filepath; //jTextPane.setPage("file:///"+path); jTextPane.setPage(new URL("http://www.wozaishuo.com.cn")); } catch (Exception e) { e.printStackTrace(); }}private void initialize() { this.setSize(764, 542); this.setContentPane(getJContentPane()); this.setTitle("JFrame"); this.pack(); this.setSize(500, 450); this.setEnabled(true); this.setVisible(true);}private JPanel getJContentPane() { if (jContentPane == null) { jContentPane = new JPanel(); jContentPane.setLayout(null); jContentPane.add(getJPanel(), null); } return jContentPane;}private JPanel getJPanel() { if (jPanel == null) { jPanel = new JPanel(); jPanel.setLayout(null); jPanel.setBounds(new Rectangle(18, 8, 715, 493)); jPanel.add(getJScrollPane(), null); } return jPanel;}private JScrollPane getJScrollPane() { if (jScrollPane == null) { jScrollPane = new JScrollPane(); jScrollPane.setBounds(new Rectangle(-4, 0, 662, 455)); jScrollPane.setViewportView(getJTextPane()); } return jScrollPane;}private JTextPane getJTextPane() { if (jTextPane == null) { jTextPane = new JTextPane(); } return jTextPane;} public static void main(String[] args){ Lk lk = new Lk(); }} 如果是弹出一个对话框的话用JS里的alert("要输出信息")就可以了。 用6.0的新特性:Desktop,如果你用开发SWT程序,可以用Program类,内部院里都是一样的具体的介绍,看博客:http://blog.csdn.net/neusoftware_20063500/archive/2009/02/20/3913914.aspx 这个算多线程处理了么? Java 包装类型与原类型的关系详细说明 我想select一个最大值,然后返回给类中的一个变量,该如何写? ?java 怎样实现播放mp3的?最好写段关键代码 题目求解答 0x5265c00L这个是什么意思啊? 关于URL类怎么样连接带验证码的问题(16日晚上10点结贴) 我在运行一个简单的java程序时,总是出现这个问题 【求助】replaceAll("\\","\\\\")这样写难道有错??? 对“对象系列化”的概念不是很懂。请指教,最好能举例说明 怎么判断一个线程是不是正常终止的 请教javax.naming包下的类都有什么用处
String command =
"C:\\Program Files\\Internet Explorer\\Iexplore.exe www.csdn.net";
Runtime.getRuntime().exec(command);
}catch(IOException ex){}
有没有别的方法?
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.net.URI;
import java.io.*;public class Browse extends JFrame{
private Container container;
private Desktop desktop;
private JLabel label;
public Browse(){
super("Browse测试");
desktop = Desktop.getDesktop(); //Desktop类没有构造方法,只能用静态方法getDesktop返回当前浏览器上下文的 Desktop 实例 label = new JLabel();
label.setText("<html><A href='http://www.google.cn'>谷歌</A></html>");//让字体以超文本的方式显示
//为label注册鼠标监听器,若单击则打开网页
label.addMouseListener(
new MouseAdapter(){
public void mouseClicked(MouseEvent event){
try{
desktop.browse(new URI("www.google.cn"));
}
catch(Exception e){
}
}
}
);
container = getContentPane();
container.setLayout(new FlowLayout());
container.add(label);
setVisible(true);
pack();
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//使窗口屏幕居中
Dimension frameSize,screenSize = Toolkit.getDefaultToolkit().getScreenSize();
frameSize = getSize();
setLocation((screenSize.width-frameSize.width)/2,(screenSize.height-frameSize.height)/2);
}
public static void main(String args[]){
Browse browse = new Browse();
}
}
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JEditorPane;
import java.awt.Rectangle;
import javax.swing.JTextPane;
import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.MalformedURLException;import javax.swing.JScrollPane;public class Lk extends JFrame {private static final long serialVersionUID = 1L;private JPanel jContentPane = null;private JPanel jPanel = null;private JScrollPane jScrollPane = null;private JTextPane jTextPane = null;public Lk() {
super();
initialize();
try {
String filepath="//help//1.html";////文件在工程下面的路径 File file=new File("");
//getAbsolutePath() 返回抽象路径名的绝对路径名字符串。
String path=file.getAbsolutePath()+filepath;
//jTextPane.setPage("file:///"+path);
jTextPane.setPage(new URL("http://www.wozaishuo.com.cn"));
}
catch (Exception e) {
e.printStackTrace();
}
}
private void initialize() {
this.setSize(764, 542);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
this.pack();
this.setSize(500, 450);
this.setEnabled(true);
this.setVisible(true);
}private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getJPanel(), null);
}
return jContentPane;
}private JPanel getJPanel() {
if (jPanel == null) {
jPanel = new JPanel();
jPanel.setLayout(null);
jPanel.setBounds(new Rectangle(18, 8, 715, 493));
jPanel.add(getJScrollPane(), null);
}
return jPanel;
}
private JScrollPane getJScrollPane() {
if (jScrollPane == null) {
jScrollPane = new JScrollPane();
jScrollPane.setBounds(new Rectangle(-4, 0, 662, 455));
jScrollPane.setViewportView(getJTextPane());
}
return jScrollPane;
}private JTextPane getJTextPane() {
if (jTextPane == null) {
jTextPane = new JTextPane();
}
return jTextPane;
} public static void main(String[] args){
Lk lk = new Lk();
}}
具体的介绍,看博客:http://blog.csdn.net/neusoftware_20063500/archive/2009/02/20/3913914.aspx