⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 applet2.java

📁 java经典的源代码 我非常喜欢这个源代码 对于编程很有好处
💻 JAVA
字号:
import java.awt.*;
import java.net.*;
import java.applet.*;
import java.awt.event.*;
public class applet2 extends Applet implements ActionListener{
  TextField text;
  Choice choice;
  public void init() {
      GridBagLayout gridBag=new GridBagLayout();
      GridBagConstraints c=new GridBagConstraints();
      setLayout(gridBag);
      Label label=new Label("输入显示对象的URL",Label.RIGHT);
      gridBag.setConstraints(label,c);
      add(label);
      text=new TextField("http://www.tsinghua.edu.cn",35);
      text.addActionListener(this);
      c.gridwidth=GridBagConstraints.REMAINDER;
      c.fill=GridBagConstraints.HORIZONTAL;
      c.weightx=1.0;
      gridBag.setConstraints(text,c);
      add(text);
      Label label1=new Label("Window/frame to show it in:",Label.RIGHT);
      c.gridwidth=1;
      c.weightx=0.0;
      gridBag.setConstraints(label1,c);
      add(label1);
      choice=new Choice();
      choice.addItem("选择浏览器窗口类型");
      choice.addItem("_blank");
      choice.addItem("_self");
      choice.addItem("_parent");
      choice.addItem("_top");
      c.fill=GridBagConstraints.NONE;
      c.gridwidth=GridBagConstraints.REMAINDER;
      c.anchor=GridBagConstraints.WEST;
      gridBag.setConstraints(choice,c);
      add(choice);
      Button b=new Button("显示");
      b.addActionListener(this);
      c.weighty=1.0;
      c.ipadx=10;
      c.ipady=10;
      c.insets=new Insets(5,0,0,0);
      c.anchor=GridBagConstraints.SOUTH;
      gridBag.setConstraints(b,c);
      add(b);
  }
  public void actionPerformed(ActionEvent e) {
      String str=text.getText();
      URL url=null;
      try{
        url=new URL(str);
      }
      catch(MalformedURLException ex){
        System.err.println("Malformed URL:"+str);
      }
      if(url!=null){
        if(choice.getSelectedIndex()==0){
          getAppletContext().showDocument(url);
        }
        else{
          getAppletContext().showDocument(url,choice.getSelectedItem());
        }
      }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -