import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.net.*;
public class AppletTest extends Applet implements ActionListener{
Label lab=new Label("请输入一个网址:");
TextField text=new TextField(30);
Button b1=new Button("GO");
URL url;
public void init(){
this.add(lab);
this.add(text);
this.add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getActionCommand()=="GO"&&text.getText()=="http://www.163.com"){
try{
url=new URL(text.getText().trim());//获取用户在文档框中输入的URL
getAppletContext().showDocument(url);//链接到指定网页
}
catch(Exception g){System.out.println(g.toString());}
}
else text.setText("please input again") ;
}//actionPerformed
}//AppletTest
为什么输入错误的地址没有提示啊!请哪们给我讲解一下了。在线等啊!
还有就是为什么那个IF那里不能用与,用了后就算输入正确的也不可以啊?
import java.awt.event.*;
import java.applet.*;
import java.net.*;
public class AppletTest extends Applet implements ActionListener{
Label lab=new Label("请输入一个网址:");
TextField text=new TextField(30);
Button b1=new Button("GO");
URL url;
public void init(){
this.add(lab);
this.add(text);
this.add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getActionCommand()=="GO"&&text.getText()=="http://www.163.com"){
try{
url=new URL(text.getText().trim());//获取用户在文档框中输入的URL
getAppletContext().showDocument(url);//链接到指定网页
}
catch(Exception g){System.out.println(g.toString());}
}
else text.setText("please input again") ;
}//actionPerformed
}//AppletTest
为什么输入错误的地址没有提示啊!请哪们给我讲解一下了。在线等啊!
还有就是为什么那个IF那里不能用与,用了后就算输入正确的也不可以啊?
修改为:
if(e.getActionCommand().equals("GO")&&text.getText().equals("http://www.163.com")){对象比较相等应该用equals
这句话不用捕获异常吗?