Swing程序嵌入Html/Jsp页面

demo2.html代码:

<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
    width="400" height="300" align="baseline"
    codebase="http://java.sun.com/products/plugin/1.4/jinstall-14-win32.cab#Version=1,4,0,mn">
    <PARAM NAME="code" VALUE="Demo2.class">
    <PARAM NAME="codebase" VALUE="D:\aaa">
    <PARAM NAME="type" VALUE="application/x-java-applet;jpi-version=1.4">
    <PARAM NAME="model" VALUE="models/HyaluronicAcid.xyz">
    <PARAM NAME="scriptable" VALUE="true">

    <COMMENT>
    <!--Demo2.class和demo2.html在同一目录下  -->
    <EMBED type="application/x-java-applet;jpi-version=1.4" width="400"
     height="400" align="baseline" code="Demo2.class" codebase="\"
     model="models/HyaluronicAcid.xyz"
     pluginspage="http://java.sun.com/j2se/1.4/download.html">
     <NOEMBED>
      No Java 2 SDK, Standard Edition v 1.4 support for APPLET!!
     </NOEMBED>
    </EMBED>
    </COMMENT>
</OBJECT>
  Demo2.java
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class Demo2 implements ActionListener {
Frame f = new Frame("文件复制!");
JLabel l = new JLabel("选择文件:");
JTextField tf = new JTextField(20);
JButton b = new JButton("选择。。。");
JFileChooser fd = new JFileChooser();

	public Demo2() {
	   fd.setDialogTitle("哈哈。。。");
	   fd.setCurrentDirectory(new File("D:\\"));
	   double lx = Toolkit.getDefaultToolkit().getScreenSize().getWidth();
	   double ly = Toolkit.getDefaultToolkit().getScreenSize().getHeight();
	   b.addActionListener(this);
	   f.setLayout(new FlowLayout());
	   f.add(l);
	   f.add(tf);
	   f.add(b);
	   f.setLocation((int) lx / 2 - 150, (int) ly / 2 - 150);
	   f.setSize(400, 400);
	   f.setVisible(true);
	   f.addWindowListener(new WindowAdapter() {
	    public void windowClosing(WindowEvent e) {
	     System.exit(0);
	    }
	   });
	}

	public void actionPerformed(ActionEvent e) {
	   if (e.getSource().equals(b)) {
	    fd.setFileSelectionMode(JFileChooser.FILES_ONLY); //只能选择文件
	    int state = fd.showOpenDialog(null);
	    if (state == 1) {
	     return;// 撤销则返回
	    } else {
	     File f = fd.getSelectedFile();// f为选择到的文件
	     tf.setText(f.getAbsolutePath());
	    }
	   }
	}

	public static void main(String[] args) {
	   Demo2 d = new Demo2();
	}
}

 

 关于java.security.AccessControlException: access denied 的解决方法

    E:\jre6\lib\security(本人路径),在grant里增加2个语句:

(加前2句时,并没起作用;加了第3句才解决)

permission java.lang.RuntimePermission "accessClassInPackage.sun.jdbc.odbc"; permission java.util.PropertyPermission "file.encoding", "read"; permission java.security.AllPermission;

 

 

你可能感兴趣的:(java,html,jsp,swing,F#)