Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/446.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 用GWT替换Java小程序_Javascript_Java_Html_Gwt_Applet - Fatal编程技术网

Javascript 用GWT替换Java小程序

Javascript 用GWT替换Java小程序,javascript,java,html,gwt,applet,Javascript,Java,Html,Gwt,Applet,嗨,我有下面的类,它想用stjs替换,但它似乎对我不起作用,因为stjs并没有涵盖所有的applet库,尽管这可以通过stjs或任何其他技术来完成吗?提前谢谢 package org.stjs.examples.hello; import java.applet.Applet; import java.awt.Button; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Frame; import java

嗨,我有下面的类,它想用stjs替换,但它似乎对我不起作用,因为stjs并没有涵盖所有的applet库,尽管这可以通过stjs或任何其他技术来完成吗?提前谢谢

package org.stjs.examples.hello;

import java.applet.Applet;
import java.awt.Button;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.Rectangle;
import java.awt.TextArea;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.text.BreakIterator;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Locale;
import java.util.StringTokenizer;

public class DataCache
  extends Applet
  implements ActionListener
{
  private static final String APPLET_VERSION = "1.6.0";
  private static final int MSG_WIN_HEIGHT = 179;
  private static final int MSG_WIN_WIDTH = 288;
  private static final String MSG_WIN_ETITLE = "Error Message";
  private static final String MSG_WIN_MTITLE = "Information Message";
  public String m_error = "";
  public String m_message = "";
  public String m_currCacheString = "";
  public StringBuffer m_currXMLCache = null;
  public Hashtable m_currHashCache = null;
  private String m_commandKey;
  private Hashtable m_XMLCache = new Hashtable();
  private Hashtable m_hashCache = new Hashtable();
  private String m_key = "";
  private String m_keyList = "";
  private String m_file = "";
  private String m_dataDir = "";
  private String m_autoLoad = "TRUE";
  private String m_servletURL = "";
  private String m_debugApplet = "";
  private Frame m_msgWindow;
  private TextArea m_msgText;
  private Button m_msgButton;
  private FontMetrics m_msgMetrics;
  private int m_msgTextHeight;

  public void destroy()
  {
    this.m_msgWindow.dispose();
  }

  public void init()
  {
    createErrorWindow();
    alertStatus("applet version: 1.6.0", 'D');

    this.m_debugApplet = getAppParam("debugApplet");
    this.m_autoLoad = getAppParam("autoLoad");
    this.m_commandKey = getAppParam("commandKey");
    String ls = getAppParam("loadStatic");
    String dataDir = getAppParam("dataDir");

    this.m_servletURL = getAppParam("servletURL");
    URL url = getCodeBase();
    int port = url.getPort();
    if (this.m_debugApplet.equals("TRUE")) {
      System.out.println("url: " + this.m_servletURL);
    } else if (port != -1) {
      this.m_servletURL = ("http://" + url.getHost() + ":" + port + this.m_servletURL);
    } else {
      this.m_servletURL = ("http://" + url.getHost() + this.m_servletURL);
    }
    setDataDir(dataDir);
    if (!this.m_autoLoad.toUpperCase().equals("FALSE")) {
      if ((ls.equals("")) || (ls.toUpperCase().equals("FALSE")))
      {
        alertStatus("loading non-static...", 'D');
        loadAllData(false);
      }
      else if (ls.toUpperCase().equals("TRUE"))
      {
        alertStatus("loading static...", 'D');
        openAllData(false);
      }
    }
  }

  public void actionPerformed(ActionEvent e)
  {
    String s = e.getActionCommand();
    if (s.equals("OK")) {
      this.m_msgWindow.hide();
    }
  }

  private void createErrorWindow()
  {
    this.m_msgWindow = new Frame("New Title");
    Panel p1 = new Panel();
    Panel p2 = new Panel();
    Panel p3 = new Panel();

    p1.setLayout(new GridLayout(2, 1));


    this.m_msgText = new TextArea("New Message", 3, 40, 1);
    this.m_msgText.setEditable(false);
    this.m_msgText.setFont(new Font("Dialog", 0, 8));
    this.m_msgMetrics = this.m_msgText.getFontMetrics(this.m_msgText.getFont());
    p2.add(this.m_msgText);
    p1.add(p2);

    this.m_msgButton = new Button(" OK ");
    this.m_msgButton.addActionListener(this);
    this.m_msgButton.setActionCommand("OK");
    p3.add(this.m_msgButton);
    p1.add(p3);

    this.m_msgWindow.add(p1);
    this.m_msgWindow.pack();

    Toolkit t = this.m_msgWindow.getToolkit();
    this.m_msgTextHeight = this.m_msgMetrics.getHeight();

    this.m_msgWindow.setBounds(new Rectangle(
      t.getScreenSize().width / 2 - 144, 
      t.getScreenSize().height / 2 - 89, 
      288, 
      179));
  }

  public void setDataDir(String s)
  {
    try
    {
      if ((s != null) && (s.length() > 0))
      {
        if (s.charAt(s.length() - 1) != '\\') {
          s = s + "\\";
        }
        this.m_dataDir = s;
      }
    }
    catch (Exception e)
    {
      e.printStackTrace();
      alertStatus(e.getMessage(), 'E');
      alertStatus(s, 'E');
    }
  }

  private String getAppParam(String s)
  {
    String param = getParameter(s);
    if (param == null) {
      return "";
    }
    return param;
  }

  private String alertStatus(String source, Exception e, char status)
  {
    e.printStackTrace(System.out);
    return alertStatus(source + " -- " + e.getMessage(), status);
  }

  private String alertStatus(String s, char status)
  {
    switch (status)
    {
    case 'E': 
      this.m_error = s;
      System.out.println(s);
      showStatus(s);
      this.m_msgWindow.setTitle("Error Message");
      setWrapText(s);
      this.m_msgButton.setEnabled(true);
      this.m_msgWindow.show();
      return s;
    case 'M': 
      this.m_message = s;
      System.out.println(s);
      showStatus(s);
      this.m_msgWindow.setTitle("Information Message");
      setWrapText(s);
      this.m_msgButton.setEnabled(true);
      this.m_msgWindow.show();
      return s;
    case 'S': 
      this.m_message = s;
      System.out.println(s);
      showStatus(s);
      this.m_msgWindow.setTitle("Information Message");
      setWrapText(s);
      this.m_msgButton.setEnabled(false);
      this.m_msgWindow.show();
      return s;
    case 'D': 
      System.out.println(s);

      return s;
    }
    return "";
  }

  private void setWrapText(String s)
  {
    BreakIterator boundary = BreakIterator.getWordInstance(Locale.US);
    String line = "";

    int maxWidth = this.m_msgText.getSize().width;

    this.m_msgText.setText("");

    boundary.setText(s);
    int start = boundary.first();
    int end = boundary.next();
    while (end != -1)
    {
      String tmp = s.substring(start, end);
      if (this.m_msgMetrics.stringWidth(line + tmp) > maxWidth)
      {
        this.m_msgText.append(line + "\n");
        line = tmp;
      }
      else
      {
        line = line + tmp;
      }
      start = end;
      end = boundary.next();
      if (end == -1) {
        this.m_msgText.append(line);
      }
    }
    this.m_msgText.append(s.substring(start));
  }

  private void makeDirectories(String dir)
  {
    String fdir = dir;
    AccessController.doPrivileged(new PrivilegedAction()
    {
      private final String val$fdir="";

      public Object run()
      {
        String subdir = "";
        int i = this.val$fdir.indexOf('\\');
        while (i != -1)
        {
          subdir = this.val$fdir.substring(0, i);
          File f = new File(subdir);
          if (!f.isDirectory()) {
            f.mkdir();
          }
          i = this.val$fdir.indexOf('\\', i + 1);
        }
        return null;
      }
    });
  }

  private boolean verifyDataFile(String s)
  {
    String fs = s;
    Boolean retVal = 
      (Boolean)AccessController.doPrivileged(new PrivilegedAction()
      {
        private final String val$fs="";

        public Object run()
        {
          File f = new File(this.val$fs);
          if (!f.isFile()) {
            return new Boolean(false);
          }
          return new Boolean(true);
        }
      });
    return retVal.booleanValue();
  }

  private String verifyDataFilesInternal()
  {
    try
    {
      AccessController.doPrivileged(new PrivilegedAction()
      {
        public Object run()
        {
          File dir = new File(DataCache.this.m_dataDir);
          if (!dir.isDirectory()) {
            dir.mkdirs();
          }
          return dir;
        }
      });
      StringTokenizer st = new StringTokenizer(this.m_commandKey, ";");
      while (st.hasMoreElements())
      {
        String key = (String)st.nextElement();
        if (!verifyDataFile(this.m_dataDir + key + ".data")) {
          return "Data cache file " + this.m_dataDir + key + ".data could not be found.";
        }
        if (!verifyDataFile(this.m_dataDir + key + ".hash")) {
          return "Data cache file " + this.m_dataDir + key + ".hash could not be found.";
        }
      }
      return "";
    }
    catch (Exception e)
    {
      e.printStackTrace();
      return e.getMessage();
    }
  }

  private String loadAllDataInternal()
  {
    String status = "";
    String key = "";
    StringBuffer data = new StringBuffer("");
    Hashtable hash = null;

    alertStatus("loading data internal", 'D');
    URLConnection connection;
    ObjectInputStream in;
    try
    {
      if (this.m_servletURL.equals("")) {
        return alertStatus("Servlet URL not specified!", 'E');
      }
      try
      {
        URL inURL = new URL(this.m_servletURL);
        connection = inURL.openConnection();
      }
      catch (Exception e)
      {

        e.printStackTrace();
        return alertStatus("Error opening server connection: " + e.getMessage(), 'E');
      }
      try
      {
       // URLConnection connection;
        URL inURL;
        in = new ObjectInputStream(connection.getInputStream());
      }
      catch (Exception e)
      {
        e.printStackTrace();
        return alertStatus("Error opening input stream: " + e.getMessage(), 'E');
      }
      int count;
      try
      {
        count = Integer.parseInt((String)in.readObject());
      }
      catch (Exception e)
      {

        e.printStackTrace();
        return alertStatus("Error getting object count: " + e.getMessage(), 'E');
      }

      this.m_XMLCache = new Hashtable(count, 1.0F);
      this.m_hashCache = new Hashtable(count, 1.0F);
      for (int i = 0; i < count; i++)
      {
        key = "";
        data = new StringBuffer("");

        status = (String)in.readObject();
        alertStatus("read status", 'D');

        key = (String)in.readObject();
        alertStatus("read key", 'D');

        data = (StringBuffer)in.readObject();
        alertStatus("read data", 'D');

        hash = (Hashtable)in.readObject();
        alertStatus("read cache", 'D');
        if (status.equals("connection closed")) {
          return alertStatus("Error communicating with servlet: Connection is closed. Please re-login.", 'E');
        }
        if (status.equals("execution error")) {
          return alertStatus("Error in servlet: Error during execution of query. Please notify Data Management.", 'E');
        }
        if (data == null) {
          return alertStatus("Error communicating with servlet: There was a data transmission error. Please notify Data Management.", 'E');
        }
        alertStatus("got cache: " + key, 'D');
        this.m_XMLCache.put(key, data);
        this.m_hashCache.put(key, hash);
      }
      alertStatus("closing stream", 'D');


      in.close();

      return "";
    }
    catch (Exception e)
    {
      e.printStackTrace();
      return "Error in loadAllDataInternal: " + e.getMessage();
    }
  }

  private String openAllDataInternal(String path)
  {
    ObjectInputStream in = null;
    String file = "";
    StringBuffer data = new StringBuffer("");
    Hashtable hash = null;
    String status = "";
    try
    {
      status = verifyDataFilesInternal();
      if (!status.equals("")) {
        return status;
      }
      StringTokenizer st = new StringTokenizer(this.m_commandKey, ";");
      int len = st.countTokens();
      this.m_XMLCache = new Hashtable(len, 1.0F);
      this.m_hashCache = new Hashtable(len, 1.0F);
      while (st.hasMoreElements())
      {
        String key = (String)st.nextElement();

        file = path + key + ".data";
        in = new ObjectInputStream(new FileInputStream(file));
        data = (StringBuffer)in.readObject();
        in.close();

        file = path + key + ".hash";
        in = new ObjectInputStream(new FileInputStream(file));
        hash = (Hashtable)in.readObject();
        in.close();

        this.m_XMLCache.put(key, data);
        this.m_hashCache.put(key, hash);
      }
      return "";
    }
    catch (Exception e)
    {
      e.printStackTrace();
      return "Error in openAllDataInternal: " + e.getMessage();
    }
  }

  private String saveAllDataInternal(String s)
  {
    Enumeration keys = null;
    String file = "";
    StringBuffer data = new StringBuffer("");
    Hashtable hash = null;
    ObjectOutputStream out = null;
    if (s.equals("")) {
      return alertStatus("Data file path is '': " + s, 'E');
    }
    try
    {
      keys = this.m_XMLCache.keys();
      makeDirectories(s);
      while (keys.hasMoreElements())
      {
        this.m_key = ((String)keys.nextElement());

        file = s + this.m_key;
        data = (StringBuffer)this.m_XMLCache.get(this.m_key);
        hash = (Hashtable)this.m_hashCache.get(this.m_key);

        out = new ObjectOutputStream(new FileOutputStream(file + ".data"));
        out.writeObject(data);
        out.close();

        out = new ObjectOutputStream(new FileOutputStream(file + ".hash"));
        out.writeObject(hash);
        out.close();
      }
      return "";
    }
    catch (Exception e)
    {
      e.printStackTrace();
      return "Error in saveAllDataInternal: " + e.getMessage();
    }
  }

  public String loadAllData(boolean verbose)
  {
    String s = 
      (String)AccessController.doPrivileged(new PrivilegedAction()
      {
        public Object run()
        {
          return DataCache.this.loadAllDataInternal();
        }
      });
    if (verbose) {
      if (s.equals("")) {
        alertStatus("Loaded all data!", 'M');
      } else {
        alertStatus(s, 'E');
      }
    }
    return s;
  }

  public String saveAllData(boolean verbose, String path)
  {
    String fpath = path;
    String s = 
      (String)AccessController.doPrivileged(new PrivilegedAction()
      {
        private final String val$fpath="";

        public Object run()
        {
          return DataCache.this.saveAllDataInternal(this.val$fpath);
        }
      });
    if (verbose) {
      if (s.equals("")) {
        alertStatus("Saved all data files!", 'M');
      } else {
        alertStatus(s, 'E');
      }
    }
    return s;
  }

  public String saveAllData(boolean verbose)
  {
    String s = 
      (String)AccessController.doPrivileged(new PrivilegedAction()
      {
        public Object run()
        {
          return DataCache.this.saveAllDataInternal(DataCache.this.m_dataDir);
        }
      });
    if (verbose) {
      if (s.equals("")) {
        alertStatus("Saved all data files!", 'M');
      } else {
        alertStatus(s, 'E');
      }
    }
    return s;
  }

  public String openAllData(boolean verbose)
  {
    String s = 
      (String)AccessController.doPrivileged(new PrivilegedAction()
      {
        public Object run()
        {
          return DataCache.this.openAllDataInternal(DataCache.this.m_dataDir);
        }
      });
    if ((s.equals("")) && (verbose)) {
      alertStatus("Opened all data files!", 'M');
    }
    return s;
  }

  public String verifyAllDataFiles(boolean verbose)
  {
    String s = verifyDataFilesInternal();
    if ((s.equals("")) && (verbose)) {
      alertStatus("Verified all data files!", 'M');
    }
    return s;
  }

  public void setCache(String key, boolean verbose)
  {
    this.m_currXMLCache = ((StringBuffer)this.m_XMLCache.get(key));
    this.m_currHashCache = ((Hashtable)this.m_hashCache.get(key));
    this.m_currCacheString = key;
    if (((this.m_currXMLCache == null) || (this.m_currHashCache == null)) && 
      (verbose)) {
      alertStatus("Requested cache (" + this.m_currCacheString + ") is null!", 'E');
    }
  }

  public String getXML(String key)
  {
    this.m_currXMLCache = ((StringBuffer)this.m_XMLCache.get(key));
    this.m_currHashCache = ((Hashtable)this.m_hashCache.get(key));
    this.m_currCacheString = key;

    return getXML();
  }

  public String getXML()
  {
    if (this.m_currXMLCache == null)
    {
      alertStatus("Current cache (" + this.m_currCacheString + ") is null!", 'E');
      return "";
    }
    return this.m_currXMLCache.toString();
  }

  public String lookupCacheValue(String code)
  {
    String[] values = (String[])this.m_currHashCache.get(code);
    return values[1];
  }

  private void printData(String[][] data)
  {
    alertStatus("printing data", 'D');
    for (int i = 0; i < data[0].length; i++) {
      System.out.println("key: " + data[0][i] + "\tvalue: " + data[1][i]);
    }
  }
}
package org.stjs.examples.hello;
导入java.applet.applet;
导入java.awt.Button;
导入java.awt.Font;
导入java.awt.FontMetrics;
导入java.awt.Frame;
导入java.awt.GridLayout;
导入java.awt.Panel;
导入java.awt.Rectangle;
导入java.awt.TextArea;
导入java.awt.Toolkit;
导入java.awt.event.ActionEvent;
导入java.awt.event.ActionListener;
导入java.io.File;
导入java.io.FileInputStream;
导入java.io.FileOutputStream;
导入java.io.ObjectInputStream;
导入java.io.ObjectOutputStream;
导入java.net.URL;
导入java.net.URLConnection;
导入java.security.AccessController;
导入java.security.PrivilegedAction;
导入java.text.BreakIterator;
导入java.util.Enumeration;
导入java.util.Hashtable;
导入java.util.Locale;
导入java.util.StringTokenizer;
公共类数据缓存
主类名
实现ActionListener
{
私有静态最终字符串小程序\u VERSION=“1.6.0”;
私有静态最终整数MSG_WIN_HEIGHT=179;
私有静态最终整数MSG_WIN_WIDTH=288;
私有静态最终字符串MSG\u WIN\u ETITLE=“错误消息”;
私有静态最终字符串MSG\u WIN\u MTITLE=“信息消息”;
公共字符串m_error=“”;
公共字符串m_message=“”;
公共字符串m_currCacheString=“”;
公共StringBuffer m_currXMLCache=null;
公共哈希表m_currHashCache=null;
私有字符串m_commandKey;
私有哈希表m_XMLCache=新哈希表();
私有哈希表m_hashCache=新哈希表();
私有字符串m_key=“”;
私有字符串m_keyList=“”;
私有字符串m_file=“”;
私有字符串m_dataDir=“”;
私有字符串m_autoLoad=“TRUE”;
私有字符串m_servletURL=“”;
私有字符串m_debugApplet=“”;
私有帧m_msgWindow;
私人文本区m_msgText;
专用按钮m_MSG按钮;
私有FontMetrics m_msgMetrics;
私家车内高度;
公共空间销毁()
{
这个.m_msgWindow.dispose();
}
公共void init()
{
createErrorWindow();
alertStatus(“小程序版本:1.6.0”,“D”);
this.m_debugApplet=getAppParam(“debugApplet”);
this.m_autoLoad=getAppParam(“自动加载”);
this.m_commandKey=getAppParam(“commandKey”);
字符串ls=getAppParam(“loadStatic”);
字符串dataDir=getAppParam(“dataDir”);
this.m_servletURL=getAppParam(“servletURL”);
URL=getCodeBase();
int-port=url.getPort();
if(this.m_debugApplet.equals(“TRUE”)){
System.out.println(“url:+this.m_servletURL”);
}否则如果(端口!=-1){
this.m_servletURL=(“http://“+url.getHost()+”:“+port+this.m_servletURL”);
}否则{
this.m_servletURL=((http://“+url.getHost()+this.m_servletURL);
}
setDataDir(dataDir);
如果(!this.m_autoLoad.toUpperCase().equals(“FALSE”)){
if((ls.equals(“”)| |(ls.toUpperCase().equals(“”)FALSE))
{
alertStatus(“加载非静态…”,“D”);
loadAllData(假);
}
else if(ls.toUpperCase().equals(“TRUE”))
{
警报状态(“正在加载静态…”,“D”);
openAllData(假);
}
}
}
已执行的公共无效操作(操作事件e)
{
字符串s=e.getActionCommand();
如果(s.equals(“OK”)){
这个.m_msgWindow.hide();
}
}
私有void createErrorWindow()
{
this.m_msgWindow=新框架(“新标题”);
面板p1=新面板();
面板p2=新面板();
面板p3=新面板();
p1.设置布局(新网格布局(2,1));
this.m_msgText=新文本区域(“新消息”,3,40,1);
此.m_msgText.setEditable(false);
这个.m_msgText.setFont(新字体(“对话框”,0,8));
this.m_msgMetrics=this.m_msgText.getFontMetrics(this.m_msgText.getFont());
p2.添加(此.m_msgText);
p1.添加(p2);
此.m_msgButton=新按钮(“确定”);
this.m_msgButton.addActionListener(this);
此.m_msgButton.setActionCommand(“OK”);
p3.添加(此.m_msg按钮);
p1.添加(p3);
此.m_msgWindow.add(p1);
这个.m_msgWindow.pack();
Toolkit t=this.m_msgWindow.getToolkit();
this.m_msgTextHeight=this.m_msgMetrics.getHeight();
此.m_msgWindow.setBounds(新矩形(
t、 getScreenSize().width/2-144,
t、 getScreenSize().高度/2-89,
288, 
179));
}
公共void setDataDir(字符串s)
{
尝试
{
如果((s!=null)&(s.length()>0))
{
如果(s.charAt(s.length()-1)!=“\\”){
s=s+“\\”;
}
this.m_dataDir=s;
}
}
捕获(例外e)
{
e、 printStackTrace();
alertStatus(例如getMessage(),'e');
警报状态;
}
}
私有字符串getAppParam(字符串s)
{
String param=getParameter;
if(param==null){
返回“”;
}
返回参数;
}
私有字符串警报状态(字符串源、异常e、字符状态)
{
e、 printStackTrace(系统输出);
返回alertStatus(源+“--”+e.getMessage(),状态);
}
私有字符串警报状态(字符串s、字符状态)
{
开关(状态)
{
案例“E”:
此.m_错误=s;
系统输出打印项次;
显示状态;
此.m_msgWindow.setTitle(“错误消息”);
setWrapText(s);
此.m_msgButton.setEnabled(true);
这个.m_msgWindow.show();
返回s;
案例“M”:
此.m_消息=s;
系统输出打印项次;
显示状态;
此.m_msgWindow.setTitle(“信息消息”);
setWrapText(s);
此.m_msgButton.setEnabled(true);
这个.m_msgWindow.show();
返回s;
案例S:
此.m_消息=s;
系统输出打印项次;
显示状态;
此.m_msgWindow.setTitle(“信息消息”);
setWrapText(s);
此.m_msgButton.setEnabled(false);
th