JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java 新手區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 Applet - 如何利用Button去開啟網頁呢 [精華]
feclin

半瓶水不可響叮噹



發文: 133
積分: 2
於 2003-08-03 13:58 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我的程式就是當按了Button後 就自動連結到yahoo 請問這樣的程式要怎麼寫呢
我是用JBuilder去寫的
void button1_actionPerformed(ActionEvent e)
{
/請問這裡面要怎麼寫呢/
}


browser edited on 2003-09-23 08:15
reply to postreply to post
作者 Re:如何利用Button去開啟網頁呢 [Re:feclin]
popcorny

Jakarta 2%

版主

發文: 752
積分: 20
於 2003-08-03 17:17 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
feclin wrote:
我的程式就是當按了Button後 就自動連結到yahoo 請問這樣的程式要怎麼寫呢
我是用JBuilder去寫的
void button1_actionPerformed(ActionEvent e)
{
/請問這裡面要怎麼寫呢/
}

1
2
3
4
5
void button1_actionPerformed(ActionEvent e)
{
    String url = "http://www.javaworld.com.tw/jute/"
     Runtime.getRuntime().exec("cmd /c start " + url);
}

限windows平台


reply to postreply to post
作者 Re:如何利用Button去開啟網頁呢 [Re:feclin]
feclin

半瓶水不可響叮噹



發文: 133
積分: 2
於 2003-08-03 23:46 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
讚美詞

anthonycs edited on 2004-04-10 23:38
reply to postreply to post
作者 Re:如何利用Button去開啟網頁呢 [Re:feclin]
feclin

半瓶水不可響叮噹



發文: 133
積分: 2
於 2003-08-03 23:56 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
發現一點問題
我把以下的程式碼打進去之後
String url = "http://www.javaworld.com.tw/jute/"
Runtime.getRuntime().exec("cmd /c start " + url);
就顯示以下錯誤
"Applet1.java": Error #: 200 : ';' expected at line 54, column 42
然後就在後面加一個";"號然後就顯示以下錯誤
"Applet1.java": Error #: 360 : unreported exception: java.io.IOException; must be caught or declared to be thrown at line 55, column 22
請問我還要加些什麼嗎?


reply to postreply to post
作者 Re:如何利用Button去開啟網頁呢 [Re:feclin]
Yoshi

塵世中一個迷途小書僮

版主

發文: 874
積分: 22
於 2003-08-04 00:01 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
feclin wrote:
[引言過長]


you need to catch the checked point exception
try {
 xxx
}
catch (IOException e) {
 xxx
}


anthonycs edited on 2004-04-10 23:37
reply to postreply to post
YOSHI!
作者 Re:如何利用Button去開啟網頁呢 [Re:feclin]
feclin

半瓶水不可響叮噹



發文: 133
積分: 2
於 2003-08-04 00:09 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
以下就是我的全部程式碼請問要加在哪裡呢 謝謝
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package untitled1;
 
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
 
public class Applet2 extends Applet {
  boolean isStandalone = false;
  Button button1 = new Button();
  /**Get a parameter value*/
  public String getParameter(String key, String def) {
    return isStandalone ? System.getProperty(key, def) :
      (getParameter(key) != null ? getParameter(key) : def);
  }
 
  /**Construct the applet*/
  public Applet2() {
  }
  /**Initialize the applet*/
  public void init() {
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  /**Component initialization*/
  private void jbInit() throws Exception {
    button1.setLabel("button1");
    button1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        button1_actionPerformed(e);
      }
    });
    this.add(button1, null);
  }
  /**Get Applet information*/
  public String getAppletInfo() {
    return "Applet Information";
  }
  /**Get parameter info*/
  public String[][] getParameterInfo() {
    return null;
  }
 
  void button1_actionPerformed(ActionEvent e) {
String url = "http://www.javaworld.com.tw/jute/"
Runtime.getRuntime().exec("cmd /c start " + url);
  }
}


browser edited on 2003-09-23 08:12
reply to postreply to post
作者 Re:如何利用Button去開啟網頁呢 [Re:feclin]
Eva

甜膩的酒窩



發文: 101
積分: 1
於 2003-08-04 00:20 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
1
2
3
4
5
6
7
8
9
void button1_actionPerformed(ActionEvent e) {
try {
 String url = "http://www.javaworld.com.tw/jute/";
Runtime.getRuntime().exec("cmd /c start " + url);
}
catch (IOException e) {
} 
 
}


browser edited on 2003-09-23 08:12
reply to postreply to post
作者 Re:如何利用Button去開啟網頁呢 [Re:feclin]
feclin

半瓶水不可響叮噹



發文: 133
積分: 2
於 2003-08-04 00:35 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我加入以下的程式碼
1
2
3
4
5
6
7
8
void button1_actionPerformed(ActionEvent e) {
try {
String url = "http://www.javaworld.com.tw/jute/";
Runtime.getRuntime().exec("cmd /c start " + url);
}
catch (IOException e) {
} 
}
就顯示以下兩個錯誤
"Applet1.java": Error #: 300 : class IOException not found in class com.borland.samples.welcome.Applet1 at line 52, column 8

"Applet1.java": Error #: 469 : variable e is already defined in method button1_actionPerformed(java.awt.event.ActionEvent) at line 52, column 20


anthonycs edited on 2004-04-10 23:36
reply to postreply to post
作者 Re:如何利用Button去開啟網頁呢 [Re:feclin]
feclin

半瓶水不可響叮噹



發文: 133
積分: 2
於 2003-08-04 00:50 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我把catch (IOException e) {} 的e換成a 就顯示以下錯誤
"Applet1.java": Error #: 300 : class IOException not found in class com.borland.samples.welcome.Applet1 at line 52, column 8


300 - 'symbol' not found
The given symbol is referenced but not declared.


reply to postreply to post
作者 Re:如何利用Button去開啟網頁呢 [Re:feclin]
Eva

甜膩的酒窩



發文: 101
積分: 1
於 2003-08-04 01:00 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
1
2
3
4
5
6
7
8
9
10
11
void button1_actionPerformed(ActionEvent e)
    {
        try
        {
            String url = "http://www.javaworld.com.tw/jute/";
            Runtime.getRuntime().exec("cmd /c start " + url);
        }
        catch (java.io.IOException exception)
        {
        }
    }

第二個錯誤是說
ActionEvent 的e 和 IOException 的e 重複定義了
這種錯誤只要改一下變數名字就行了
以後看到這種錯誤 要能自己debug才行喔


anthonycs edited on 2004-04-10 23:36
reply to postreply to post
作者 Re:如何利用Button去開啟網頁呢 [Re:feclin]
Eva

甜膩的酒窩



發文: 101
積分: 1
於 2003-08-04 01:05 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Yoshi大大:

為什麼要用catch ( java.io.IOException )
而不能直接用catch( IOException ) 啊?? StupidStupid


reply to postreply to post
作者 Re:如何利用Button去開啟網頁呢 [Re:feclin]
feclin

半瓶水不可響叮噹



發文: 133
積分: 2
於 2003-08-04 01:05 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
出來囉 真是太謝謝大家的幫忙了 以下就是程式的程式碼

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package untitled2;
 
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
 
public class Applet1 extends Applet {
  boolean isStandalone = false;
  Button button1 = new Button();
  /**Get a parameter value*/
  public String getParameter(String key, String def) {
    return isStandalone ? System.getProperty(key, def) :
      (getParameter(key) != null ? getParameter(key) : def);
  }
 
  /**Construct the applet*/
  public Applet1() {
  }
  /**Initialize the applet*/
  public void init() {
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  /**Component initialization*/
  private void jbInit() throws Exception {
    button1.setLabel("button1");
    button1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        button1_actionPerformed(e);
      }
    });
    this.add(button1, null);
  }
  /**Get Applet information*/
  public String getAppletInfo() {
    return "Applet Information";
  }
  /**Get parameter info*/
  public String[][] getParameterInfo() {
    return null;
  }
 
  void button1_actionPerformed(ActionEvent e) {
try
{
String url = "http://www.javaworld.com.tw/jute/";
Runtime.getRuntime().exec("cmd /c start " + url);
}
catch (java.io.IOException exception)
{
}
  }
}


browser edited on 2003-09-23 08:13
reply to postreply to post
作者 Re:如何利用Button去開啟網頁呢 [Re:feclin]
popcorny

Jakarta 2%

版主

發文: 752
積分: 20
於 2003-08-04 01:08 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
原來你是在寫applet唷
改成這樣寫
1
2
3
4
5
6
7
8
9
10
11
12
import java.net.*;
import java.io.*;
import java.applet.*;
..........
void button1_actionPerformed(ActionEvent e)
{
       try{
           URL url = new URL("http://www.javaworld.com.tw/jute/");
           AppletContext context = getAppletContext();
           context.showDocument(url);
       }catch(IOException ex){}
} 


請查java.applet.AppletContext的API


reply to postreply to post
作者 Re:如何利用Button去開啟網頁呢 [Re:Eva]
Yoshi

塵世中一個迷途小書僮

版主

發文: 874
積分: 22
於 2003-08-04 01:39 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Eva wrote:
Yoshi大大:

為什麼要用catch ( java.io.IOException )
而不能直接用catch( IOException ) 啊?? StupidStupid


你要用後者, 就要先import java.io.*啊
不然就要指名"完整類別名稱"


reply to postreply to post
YOSHI!
作者 Re:如何利用Button去開啟網頁呢 [Re:feclin]
caterpillar

良葛格

版主

發文: 2613
積分: 70
於 2003-08-04 21:43 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
feclin wrote:
[引言過長]


試試看,Java How to Programm中的,我沒試過。。。。


anthonycs edited on 2004-04-10 23:36
reply to postreply to post
良葛格學習筆記
作者 Re:如何利用Button去開啟網頁呢 [Re:popcorny]
stommy





發文: 17
積分: 2
於 2003-09-22 15:31 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
popcorny wrote:
1
2
3
4
5
void button1_actionPerformed(ActionEvent e)
{
    String url = "http://www.javaworld.com.tw/jute/"
     Runtime.getRuntime().exec("cmd /c start " + url);
}

限windows平台


請問一下~~在unix平台下
Runtime.getRuntime().exec("???????"+ url);
^^^^^
應該填什麼ㄋ??
還有 如何判斷 使用者是在何種平台下ㄋ??

謝謝~~~


reply to postreply to post
作者 Re:如何利用Button去開啟網頁呢 [Re:feclin]
T55555

Java, Ruby, Haskell

版主

發文: 1026
積分: 24
於 2003-09-22 20:52 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Suggestion:
Better not use :
Runtime.getRuntime().exec("cmd /c start " + url);

This will work only on Windows Platform!
It is better find a "general" solution for cross-platform.
(like open Netscape on unix)
Do research yourself, if you cannot find it, I can give you solution.

(Of course, if you limite to only M$ windows, ignore this)


reply to postreply to post
作者 Re:如何利用Button去開啟網頁呢 [Re:feclin]
T55555

Java, Ruby, Haskell

版主

發文: 1026
積分: 24
於 2003-09-22 20:54 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
feclin wrote:
[引言過長]


import java.io.*;


anthonycs edited on 2004-04-10 23:35
reply to postreply to post
作者 Re:如何利用Button去開啟網頁呢 [Re:T55555]
stommy





發文: 17
積分: 2
於 2003-09-23 00:42 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
T55555 wrote:
[引言過長]


謝謝你了~~


anthonycs edited on 2004-04-10 23:35
reply to postreply to post
作者 Re:如何利用Button去開啟網頁呢 [Re:feclin]
T55555

Java, Ruby, Haskell

版主

發文: 1026
積分: 24
於 2003-09-23 01:22 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
好啦. 指點您們一條明路...
http://www.javaworld.com/javaworld/javatips/jw-javatip66.html?
這東西, 我拿下來改了改, 非常好用.
(你可以拿下來就用, 不用改)


reply to postreply to post
作者 Re:如何利用Button去開啟網頁呢 [Re:T55555]
UndeadJ

UX & UI Design



發文: 384
積分: 3
於 2003-09-23 01:38 user profilesend a private message to usersend email to UndeadJreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
T55555 wrote:
好啦. 指點您們一條明路...
http://www.javaworld.com/javaworld/javatips/jw-javatip66.html?
這東西, 我拿下來改了改, 非常好用.
(你可以拿下來就用, 不用改)

很不錯,連OS Platform check都幫你直接做好了

--
if (windows)...這個名字實在是...


UndeadJ edited on 2003-09-23 01:41
reply to postreply to post
我們是懷抱各自的夢想,買了車票的乘客,不過就像列車一定會有終點,人生有時會碰到必須換車的時候...

我們站在名為「今天」的車站,在名為「昨天」的列車下車,轉搭為「明天」的列車

不過,若沒及時搭上的話....
作者 Re:如何利用Button去開啟網頁呢 [Re:Eva]
C1cadA





發文: 12
積分: 0
於 2006-06-22 03:53 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
請問一下 在這個程式中

如果把applet嵌入到網頁裡

按button的時候 會在原網頁開啟連結

有辦法 讓button按下去的時候 另開新IE嗎 ?


reply to postreply to post
» JWorld@TW »  Java 新手區

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8