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

📄 showdocexam.java

📁 Java程序设计实用教程源代码 本书源代码按章分别放置在不同的文件夹中,所有程序均在JDK1.6环境下编译运行正常,除了第13章需要建立ODBC数据源之外,其他程序只要有Java运行环境即可直接运行
💻 JAVA
字号:
import java.awt.*;
import java.net.*;
import java.applet.*;
import java.awt.event.*; 
public class showDocExam extends Applet implements ActionListener {
  TextField t1;
  Choice seletwin;
  public void init() {
    GridBagLayout gBLayout = new GridBagLayout();
    GridBagConstraints gBCon = new GridBagConstraints();
    setLayout(gBLayout);
    Label Lb1 = new Label("请输入需要浏览的网页地址:", Label.RIGHT);
    Lb1.setBackground(Color.WHITE);
    gBLayout.setConstraints(Lb1, gBCon);
    add(Lb1);
    t1 = new TextField("http://www.baidu.com", 35);
    t1.addActionListener(this);
    gBCon.gridwidth = GridBagConstraints.REMAINDER;
    gBCon.fill = GridBagConstraints.HORIZONTAL;
    gBCon.weightx = 1.0;
    gBLayout.setConstraints(t1, gBCon);
    add(t1);
    Label Lb2 = new Label("请选择需要打开网页的窗口:", Label.RIGHT);
    Lb2.setBackground(Color.WHITE);
    gBCon.gridwidth = 1;
    gBCon.weightx = 1.0;
    gBLayout.setConstraints(Lb2, gBCon);
    add(Lb2);
    seletwin = new Choice();
    seletwin.addItem("_blank");
    seletwin.addItem("_self");
    seletwin.addItem("_parent");
    seletwin.addItem("_top");
    gBCon.fill = GridBagConstraints.NONE;
    gBCon.gridwidth = GridBagConstraints.REMAINDER;
    gBCon.anchor = GridBagConstraints.WEST;
    gBLayout.setConstraints(seletwin, gBCon);
    add(seletwin);
    Button b = new Button("打开");
    b.addActionListener(this);
    gBCon.weighty = 1.0;
    gBCon.ipadx = 2;
    gBCon.ipady = 2;
    gBCon.insets = new Insets(5, 0, 0, 0);
    gBCon.anchor = GridBagConstraints.CENTER;
    gBLayout.setConstraints(b, gBCon);
    add(b);
  }
  public void paint(Graphics g) {
    this.setBackground(Color.WHITE);
  }
  public void actionPerformed(ActionEvent e) {
    String str = t1.getText();
    URL url = null;
    try {
      url = new URL(str);
    }
    catch (MalformedURLException ex) {
      System.err.println(ex.getMessage());
    }
    if (url != null) {
      getAppletContext().showDocument(url, seletwin.getSelectedItem());
    }
  }
}

⌨️ 快捷键说明

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