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

📄 simulator.java

📁 WAP ide 代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                   _p2.getPreferredSize().width,                   _p2.getPreferredSize().height);    offset_y += _p2.getPreferredSize().height;    int buttonwidth = 28;    getContentPane().add( up);    up.setBounds( centerline - ( buttonwidth/2), offset_y + 7,                  buttonwidth, 20);    getContentPane().add( down);    down.setBounds( centerline - ( buttonwidth/2), offset_y + 30,                    buttonwidth, 20);    int sideoffset = 23;    getContentPane().add( left);    left.setBounds( centerline - sideoffset - buttonwidth, offset_y + 10,                    buttonwidth, 17);    getContentPane().add( right);    right.setBounds( centerline + sideoffset, offset_y + 10,                     buttonwidth, 17);    String seq[] = { "1", "2", "3", "4", "5", "6",      "7", "8", "9", "*", "0", "#" };    // add some dead buttons, the phone numbers    for( int i = 0; i< 4; i++){      for( int j = 0; j< 3; j++){        Button b = new Button( seq[ i*3+j] );        getContentPane().add( b);        int x = centerline - 45 + ( j * 31);        int y = offset_y + 60 + ( i * 30);        b.setBounds( x, y, 24, 20);        // this is live now, just as a convenience: it        // routes back to the first page passed in.        if( seq[ i*3+j].equals("#")){          b.addActionListener( this);          b.setActionCommand( "home");        }      }    }    // an attempt to fix a problem with repainting the background.    this.setVisible(false);    this.setVisible(true);    checkPrev();  }  /**   * Frame mouse listener, if frame right clicked then   * display a popup menu.   */  private void this_mouseClicked(MouseEvent e) {    if (idemenu == null) {      if (e.getModifiers() == RIGHT_MOUSE_BUTTON) {        checkPrev();        navPopupMenu.show(this, e.getX(), e.getY());      }    }  }  /** Navigates to previous card */  private void navBack_actionPerformed(ActionEvent e) {    if(_doprev && !_dostring.equals("")){      if( _dostring.startsWith("#")){        _highlightlink = 0;        drawScreen(_currentcard = _dostring.substring(1));        _vertical = 0;      }      else{        _highlightlink = 0;        loadContent(_dostring);        drawScreen(_currentcard);        _vertical = 0;      }    }    this.repaint();  }  /** Goes to start of deck */  private void navHome_actionPerformed(ActionEvent e) {    _highlightlink = 0;    loadContent(_page);    drawScreen(_currentcard);    _vertical = 0;    this.repaint();  }  /**   * Refreshes the current card - will eventually wipe   * variables when variables are supported   */  private void navRefresh_actionPerformed(ActionEvent e) {    drawScreen(_currentcard);    this.repaint();  }  /** Reloads the deck */  private void navReload_actionPerformed(ActionEvent e) {    reload();  }  /** Loads a new wml file into the simulator */  private void navFile_actionPerformed(ActionEvent e) {    try{      String[] filters = {"wml"};      Designer.Filter f = new Designer.Filter(filters, "WAP Files");      JFileChooser fc = new JFileChooser();      fc.addChoosableFileFilter(f);      int retVal = fc.showOpenDialog(this);      if (retVal == fc.APPROVE_OPTION) {        String path = fc.getSelectedFile().getParent() + File.separator;        String fname = fc.getSelectedFile().getPath().substring(path.length());        _page = path + fname;        _highlightlink = 0;        loadContent(_page);        drawScreen(_currentcard);        _vertical = 0;        this.repaint();      }    }    catch (NullPointerException pe) {}  }  /**   * Displays a dialog for loading a different skin, and   * if the user selects a proper .skn file, calls up routines   * to load it into the simulator.   */  private void navSkin_actionPerformed(ActionEvent e) {    try{      String[] filters = {"skn"};      Designer.Filter f = new Designer.Filter(filters, "Phone Designer Files");      JFileChooser fc = new JFileChooser();      fc.addChoosableFileFilter(f);      int retVal = fc.showOpenDialog(this);      if (retVal == fc.APPROVE_OPTION) {        String path = fc.getSelectedFile().getParent() + File.separator;        String fname = fc.getSelectedFile().getPath().substring(path.length());        FileInputStream fis = null;        String str = null;        try {          fis = new FileInputStream (path + fname);          int size = fis.available();          byte[] bytes = new byte [size];          fis.read (bytes);          str = new String (bytes);          fis.close ();        }        catch (IOException err) {        }        if (str != null) {          loadSkin(str);        }        else          init();      }    }    catch (NullPointerException pe) {}  }  /** Loads the default skin */  private void navSkinDefault_actionPerformed(ActionEvent e) {    init();  }  /**   * Loads a new .skn file, created using the designer, into   * the Simulator and redraws the current card.  If   * no background image is found then reverts to old   * default skin.   */  private boolean loadSkin(String theFile) {    int StartSection = theFile.indexOf("<phone>");    int EndSection = theFile.indexOf("</phone>");    if ((StartSection > -1) && (EndSection > -1)) {      mainPanel.removeAll();      this.getContentPane().removeAll();      JLabel BKGround = new JLabel();      String theData = theFile.substring(StartSection + 8, EndSection);      Vector data = new Vector();      StringTokenizer st = new StringTokenizer(theData, "\n");      while (st.hasMoreTokens()) {        data.add(st.nextToken().trim());      }      String backgrd = (String) data.get(0);      int start = backgrd.indexOf(">") + 1;      int end = backgrd.indexOf("<", start);      backgrd = backgrd.substring(start, end);      if (backgrd.length() > 0) {        _bgimage =  null;        Image bkimg = Toolkit.getDefaultToolkit().getImage(backgrd);        ImageIcon i = new ImageIcon(bkimg);        BKGround.setIcon(i);        BKGround.setBackground(java.awt.Color.gray);        BKGround.setSize(i.getIconWidth(), i.getIconHeight());        this.getContentPane().setLayout(gridBagLayout1);        this.getContentPane().add(mainPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));        mainPanel.add(BKGround, null);        this.setSize(BKGround.getSize());        this.setVisible(false);        this.setVisible(true);        data.remove(0);        // load the rest of the controls        boolean process = false; // if control found then process properties        boolean screen = false; // if true need special attention        JLabel tmplabel = new JLabel();        for (int x = 0; x < data.size(); x++) {          String d = (String) data.get(x);          if (process) {            int tagstart = d.indexOf("<");            int tagend = d.indexOf(">", tagstart);            String tag = d.substring(tagstart + 1, tagend);            int enddata = d.indexOf("</" + tag + ">");            if ((tagstart < 0) || (tagend < 0) || (enddata < 0)) {              process = false;            }            else { // continue loading tag data              String tagdata = d.substring(tagend + 1, enddata);              if (tag.equals("action")) {                if (tagdata.equals("Screen")) {                  screen = true;                }                else {                  tmplabel.setName(tagdata);                  tmplabel.addMouseListener(this);                }              }              if (tag.equals("icon")) {                tmplabel.setIcon(new ImageIcon(tagdata));              }              if (tag.equals("bkcolor")) {                int c = 0;                int intArray[] = new int[3];                StringTokenizer commaReader = new StringTokenizer(tagdata, ", ");                while (commaReader.hasMoreTokens()) {                  intArray[c] = Integer.parseInt(commaReader.nextToken());                  c++;                }                tmplabel.setBackground(new Color(intArray[0], intArray[1], intArray[2]));              }              if (tag.equals("location")) {                int c = 0;                int intArray[] = new int[2];                StringTokenizer commaReader = new StringTokenizer(tagdata, ", ");                while (commaReader.hasMoreTokens()) {                  intArray[c] = Integer.parseInt(commaReader.nextToken());                  c++;                }                tmplabel.setLocation(intArray[0], intArray[1]);              }              if (tag.equals("size")) {                int c = 0;                int intArray[] = new int[2];                StringTokenizer commaReader = new StringTokenizer(tagdata, ", ");                while (commaReader.hasMoreTokens()) {                  intArray[c] = Integer.parseInt(commaReader.nextToken());                  c++;                }                tmplabel.setSize(intArray[0], intArray[1]);              }              if (tag.equals("opaque")) {                boolean v = true;                if (tagdata.equals("false"))                  v = false;                tmplabel.setOpaque(v);              }            }          }          if (d.equals("</control>")) {            process =  false;            if (screen) {                  tmplabel.add(setupScreen(tmplabel));                  Screen_Green = tmplabel.getBackground();                  screen = false;                }            BKGround.add(tmplabel);            BKGround.repaint();          }          if (d.equals("<control>")) {            process = true;            tmplabel = new JLabel();          }        }        _parser = new Parser();        loadContent(_page);         // set some defaults, and render the page.         _cursor = new Point(1, 16);         _justify = LEFT_JUSTIFY;         _underline = false;         _invert = false;         _currentfont = FONT_PLAIN;         _currentlinkindex = -1;         _vertical = 0;         _buffer = new Vector();         _links = new Hashtable();         _highlightlink = 0;         _doprev = false;         _dostring = "";         _donext = false;         _donextstring = "";         // draw card         drawScreen(_currentcard);         checkPrev();      }      else { // background failed to load, use default skin        init();        return false;      }    }    return true;  }  /**   * Constructs the screen component to be added to the screen label   * @param Jlabel label - the lbel that acts as the screen   * @return JPanel - the panel to be added to the screen label   */  private JPanel setupScreen(JLabel tl) {    final JPanel l = new JPanel();    l.setSize(tl.getWidth(), tl.getHeight());    l.setLocation(0, 0);    ScreenWidth = tl.getWidth();    ScreenHeight = tl.getHeight() - BUTTONSCREENHEIGHT - 1;    _p = new Panel(){      public Dimension getMinimumSize(){        return new Dimension(ScreenWidth, ScreenHeight);      }      public Dimension getPreferredSize(){        return getMinimumSize();      }      public void update(Graphics g){        paint(g);      }      public void paint(Graphics g){        g.drawImage(_offscreen, 0, 0 + _vertical, l);      }    };    _p2 = new Panel(){      public Dimension getMinimumSize(){        return new Dimension(ScreenWidth, BUTTONSCREENHEIGHT);      }      public Dimension getPreferredSize(){        return getMinimumSize();      }      public void update(Graphics g){        paint(g);      }      public void paint(Graphics g){        g.setColor( Screen_Green);        g.fillRect( 0, 0, ScreenWidth, BUTTONSCREENHEIGHT);        g.setColor( Color.black);        if( _donext) {          g.setFont( FONTS[FONT_BOLD]);          g.drawString(_donexttext, 4, ROWHEIGHT + 2);        }        // eventually, provide better simulation        // by allowing links and do's to be        // integrated into a menu that        // is overlayed on the screen.  Right now,        // only one do tag can be displayed, and        // it takes preference over a link.        else if( linkOnScreen( _highlightlink)) {          g.setFont( FONTS[FONT_BOLD]);          g.drawString("Link", 4, ROWHEIGHT + 2);        }        if( _doprev) {          g.setFont( FONTS[FONT_BOLD]);          g.drawString(_dotext, ScreenWidth - 32, ROWHEIGHT + 2);        }      }    };    _p.setSize(ScreenWidth, ScreenHeight);    _p2.setSize(ScreenWidth, BUTTONSCREENHEIGHT);    l.setLayout(null);    l.add(_p);    l.add(_p2);    _p2.setLocation(0, ScreenHeight);    return l;  }  /** If _doprev is true, enables back button in popup and possibly WAPIDE */  private void checkPrev() {    if (_doprev)      navBack.setEnabled(true);    else        navBack.setEnabled(false);    if (idemenu != null)      idemenu.getItem(0).setEnabled(navBack.isEnabled());  }  ////////// Routins for use with WAPIDE ///////////////////////////  /** Navigates back */  public void Back() {    navBack.doClick();  }  /** Loads home page, at the moment start of current deck */  public void Home() {    navHome.doClick();  }  /**   * Refreshes current card, will eventually wipe clean variables when variable   * support is built into simulator   */  public void Refresh() {    navRefresh.doClick();  }  /** Reloads the deck */  public void Reload() {    navReload.doClick();  }  /** Stops loading the current deck and card- not yet umplemented  */  public void Stop() {    // not yet implemented  }  /** Loads a different file into the simulator */  public void loadFile() {    navFile.doClick();  }  /** Loads a location with wml files into the simulator - not yet implemented */  public void loadLoc() {    // not yet implemented  }  /** Sets the skin to use from the WAPIDE */  public boolean setSkin(String fname) {    FileInputStream fis = null;    String str = null;    try {      fis = new FileInputStream (fname);      int size = fis.available();      byte[] bytes = new byte [size];      fis.read (bytes);      str = new String (bytes);      fis.close ();    }    catch (IOException err) {    }    if (str != null) {      return loadSkin(str);    }    else {      init();      return false;    }  }}

⌨️ 快捷键说明

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