如何用Jbutton打开一个html文件 [英] How can I open a html file with Jbutton

查看:98
本文介绍了如何用Jbutton打开一个html文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我需要帮助在Jbutton下打开一个html文件。我在面板上创建了一个按钮,并将其命名为表格。我在项目文件夹中创建了一个名为tables的html文件。该程序预计会这样做;



当用户点击按钮时,应在浏览器上打开html文件。

HTML文件是静态的,不需要数据库或任何其他东西。您可能认为与java项目没有任何关系。用户应该在浏览器上看到它。

我搜索得太多了。但是,我无法解决这个问题。



  private   void  btnDevelopersActionPerformed(java.awt.event.ActionEvent evt){

try {
// 打开我的计算机上的HTML文件

}
catch (Exception ex){
System.out.println( 无法执行命令。 + ex);
}

}

解决方案

更简单:



  //  查找给定文件的程序 
程序p = Program.findProgram( pdf); // 也可以是html或其他
p.execute(printFilePath); // 在程序中抛出文件





简单地让操作系统决定并采取行动。它非常安全。






看看这个类似的讨论:

< a href =http://stackoverflow.com/questions/4649816/open-local-html-page-java> http://stackoverflow.com/questions/4649816/open-local-html-page-java [ ^ ]


  String  webpage =  < span class =code-string> C:\\ myRootFolder \\myWebPage.html; 
Runtime.getRuntime()。exec( cmd / c start +网页);


Hello everyone,

I need to help about openning a html file under a Jbutton. I created a button on the panel and named it as tables. And I created a html file named as tables in the project folder. The program is expected to do this;

When the user clicked on the butto, the html file should be opened on the browser.
HTML file is static no need a database or any other things. You may think there is no relation with the java project. The user just should see it on the browser.
I searched too much. However, I couldn't solve this.

  private void btnDevelopersActionPerformed(java.awt.event.ActionEvent evt) {                                              

try{ 
//OPEN A HTML FILE ON MY COMPUTER

} 
catch(Exception ex){ 
System.out.println("cannot execute command. " +ex); 
} 

    }  

解决方案

even simpler:

// find program for given file
Program p = Program.findProgram("pdf"); // could also be html or whatever 
p.execute(printFilePath); // throw file at program



One simply lets the OS decide and take action. It's pretty failsafe.


Hi,

Have a look at this similar discussion:
http://stackoverflow.com/questions/4649816/open-local-html-page-java[^]


String webpage="C:\\myRootFolder\\myWebPage.html";
Runtime.getRuntime().exec("cmd /c start "+webpage);


这篇关于如何用Jbutton打开一个html文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆