## Java applet (get selected file fullpath, OpenFile dialog)
//# -*- mode: java; coding: utf-8 -*-
//# (c) Valik mailto:vasnake@gmail.com
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class vcuClient extends Applet
{
TextField txt;
TextArea textBox;
// The method that will be automatically called when the applet is started
public void init()
{
setLayout(new FlowLayout());
this.txt = new TextField("VCU Java applet v.10", 30);
this.textBox = new TextArea();
add(this.txt);
add(this.textBox);
this.textBox.setText("log:");
this.txt.setEditable(false);
}
// This method gets called when the applet is terminated
// That's when the user goes to another page or exits the browser.
public void stop()
{
// no actions needed here now.
}
// The standard method that you have to use to paint things on screen
// This overrides the empty Applet method, you can't called it "display" for example.
public void paint(Graphics g)
{
//method to draw text on screen
return;
}
// app logic:
public void log(String str){
this.textBox.setText( this.textBox.getText() +"\n"+ str );
}
public String message(String msgType, String msgBody) {
// communication interface :)
String res = "fail";
this.log("message: type ["+msgType+"], body ["+msgBody+"]");
if (msgType.compareToIgnoreCase("selectFile") == 0) {
res = this.selectFile();
this.log("File: ["+res+"]");
}
return res;
} // public String message(String msgType, String msgBody) {
private String selectFile() {
FileDialog fd = new FileDialog(new Frame(), "Pick a file:", FileDialog.LOAD);
fd.setVisible(true);
if (fd.getFile() != null) {
return fd.getDirectory() + fd.getFile();
}
else {
return "";
}
} // private String selectFile() {
} // public class vcuClient extends Applet implements ActionListener
## HTML page (get selected file fullpath, OpenFile dialog)
<!--
# -*- mode: html; coding: utf-8 -*-
# (c) Valik mailto:vasnake@gmail.com
-->
<HTML>
<HEAD>
<TITLE>VCU Java Client</TITLE>
</HEAD>
<BODY>
<applet name="jApplet" id="jApplet"
code="vcuClient.class"
width=500 height=200>
alt="Your browser understands the <APPLET> tag but isn't running the applet, for some reason."
Your browser is completely ignoring the <APPLET> tag!
</applet>
<br/>
<input type="button"
name="btnSelectFile" id="btnSelectFile"
value="Select..."
onclick="return selectFile();" />
<script type="text/javascript">
function selectFile(){
var res = document.jApplet.message('selectFile', '');
alert('selected file ['+res+']');
}
</script>
</BODY>
</HTML>
|
Комментариев нет:
Отправить комментарий