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

📄 g2dint.java

📁 java 作图的程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                  if(x1 > datarect.x + datarect.width )                      x1 = datarect.x + datarect.width;                  if(y1 < datarect.y) y1 = datarect.y;                  else                  if(y1 > datarect.y + datarect.height )                      y1 = datarect.y + datarect.height;                }                                if(cpgin != null && cpgin.isVisible()) {                            cpgin.setXlabel(  xaxis.getDouble(x1) );                            cpgin.setYlabel(  yaxis.getDouble(y1) );                }                repaint();                return true;    }/**  * Handle the Mouse Mouve events */    public boolean mouseMove(Event e, int x, int y) {                if(xaxis==null || yaxis==null) return false;                x1   = e.x;                y1   = e.y;                                if(cpgin != null && cpgin.isVisible()) {                            cpgin.setXlabel(  xaxis.getDouble(x1) );                            cpgin.setYlabel(  yaxis.getDouble(y1) );                }                return true;    }/** * Handle the Action Events. * This handler allows external classes (pop-up windows etc.) to * communicate to this class asyncronously. */     public boolean action(Event e, Object a) {          if(xaxis==null || yaxis==null) return false;          if(e.target instanceof Range && range != null) {            Double d;            double txmin = xaxis.minimum;            double txmax = xaxis.maximum;            double tymin = yaxis.minimum;            double tymax = yaxis.maximum;            d = range.getXmin();            if(d != null) txmin = d.doubleValue();            d = range.getXmax();            if(d != null) txmax = d.doubleValue();            d = range.getYmin();            if(d != null) tymin = d.doubleValue();            d = range.getYmax();            if(d != null) tymax = d.doubleValue();            if( txmax > txmin && tymax > tymin ) {                 xaxis.minimum = txmin;                 xaxis.maximum = txmax;                 yaxis.minimum = tymin;                 yaxis.maximum = tymax;	    }            repaint();            return true;          }           return false;    }/** *   Find the closest data point to the cursor */     protected double[] getClosestPoint(int ix, int iy) {        DataSet ds;        int   i;        double a[] = new double[3];        double distsq = -1.0;        double data[] = {0.0, 0.0};        double x = xaxis.getDouble(ix);        double y = yaxis.getDouble(iy);        //System.out.println("getClosestPoint: x="+x+", y="+y);        for (i=0; i<dataset.size(); i++) {               ds = (DataSet)(dataset.elementAt(i));               a = ds.getClosestPoint(x,y);               if( distsq < 0.0 || distsq > a[2] ) {                                    data[0] = a[0];                                    data[1] = a[1];                                    distsq  = a[2];	        }	}        return data;      }}/** *      Popup a window to output data after a Graphics Input command *      the window contains the following *           X  value *           Y  value */class Gin extends Frame {     private Label xlabel = new Label();     private Label ylabel = new Label();  /**   * Instantiate the class   */     public Gin() {         setLayout(new GridLayout(2,1) ) ;         xlabel.setAlignment(Label.LEFT);         ylabel.setAlignment(Label.LEFT);         this.setFont(new Font("Helvetica", Font.PLAIN, 20));         add("x",xlabel);         add("y",ylabel);         resize(150,100);         super.setTitle("Graphics Input");     }  /**   * Instantiate the class.    * @param title the title to use on the pop-window.   */     public Gin(String title) {         this();         if(title != null) super.setTitle(title);       }  /**   *  Set the X value   * @param d The value to set it   */     public void setXlabel(double d) {         xlabel.setText( String.valueOf(d) );     }  /**   *  Set the Y value   * @param d The value to set it   */     public void setYlabel(double d) {         ylabel.setText( String.valueOf(d) );     }  /**   *  Set the both values   * @param dx The X value to set   * @param dy The Y value to set   */     public void setLabels(double dx, double dy) {         xlabel.setText( String.valueOf(dx) );         ylabel.setText( String.valueOf(dy) );     }  /**   * Set the display font   */     public void setFont( Font f ) {        if ( f == null ) return;        xlabel.setFont( f );        ylabel.setFont( f );     }  /**   * Set the size of the window   * @param x width in pixels   * @param y height in pixels   */     public void resize( int x, int y) {        super.resize(x,y);     }  /**   * Catch the Key Down event 'h'. If the key is pressed then   * hide this window.   *   * @param e The event   * @param key the key pressed   */     public boolean keyDown(Event e, int key) {             if( key == 'h' ) {                                  this.hide();                                  return true;				}             return false;     }}/** *    A  popup window for altering the range of the plot */class Range extends Frame {     Graph2D g2d = null;     private Label xminLabel = new Label("Xmin");     private Label yminLabel = new Label("Ymin");     private Label xmaxLabel = new Label("Xmax");     private Label ymaxLabel = new Label("Ymax");     private TextField xminText = new TextField(20);     private TextField yminText = new TextField(20);     private TextField xmaxText = new TextField(20);     private TextField ymaxText = new TextField(20);     private Button cancel = new Button("Cancel");     private Button done   = new Button("Done");     public Range(Graph2D g) {         g2d = g;         setLayout(new GridLayout(5,2,5,10) ) ;         xminLabel.setAlignment(Label.LEFT);         xmaxLabel.setAlignment(Label.LEFT);         yminLabel.setAlignment(Label.LEFT);         ymaxLabel.setAlignment(Label.LEFT);         add("xminLabel",xminLabel);         add("xminText",xminText);         add("xmaxLabel",xmaxLabel);         add("xmaxText",xmaxText);         add("yminLabel",yminLabel);         add("yminText",yminText);         add("ymaxLabel",ymaxLabel);         add("ymaxText",ymaxText);         add("cancel", cancel);         cancel.setBackground(Color.red);         add("done",done);         done.setBackground(Color.green);         resize(250,250);         super.setTitle("Set Plot Range");     }     public Double getXmin() {         try {               return Double.valueOf(xminText.getText());             }         catch (Exception ex) {               return null;	     }     }          public Double getXmax() {         try {               return Double.valueOf(xmaxText.getText());             }         catch (Exception ex) {               return null;	     }     }     public Double getYmin() {         try {               return Double.valueOf(yminText.getText());             }         catch (Exception ex) {               return null;	     }     }          public Double getYmax() {         try {               return Double.valueOf(ymaxText.getText());             }         catch (Exception ex) {               return null;	     }     }     public void resize( int x, int y) {        super.resize(x,y);     }      public void requestFocus() {       xminText.requestFocus();     }/*** Handle the events*/   public boolean keyDown(Event e, int key) {         if(e.target instanceof TextField) {            if( ( key == 10 || e.key == 13 ) ) {                        if(xminText.equals(e.target)) {                          xmaxText.requestFocus();                          return true;                        } else                        if(xmaxText.equals(e.target)) {                          yminText.requestFocus();                          return true;                        } else                        if(yminText.equals(e.target)) {                          ymaxText.requestFocus();                          return true;                        } else                        if(ymaxText.equals(e.target)) {                          xminText.requestFocus();                          return true;		        }                        return true;            }	 }         return false;   }    public boolean action(Event e, Object a) {         if(e.target instanceof Button) {             if( done.equals(e.target) && g2d != null) {                  g2d.deliverEvent( new Event(this,Event.ACTION_EVENT,this) );                  this.hide();                  return true;             } else              if( cancel.equals(e.target) ) {                  this.hide();                  return true;	     }         }         return false;       }   }

⌨️ 快捷键说明

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