0

我正在尝试测试此代码,但遇到了问题。我有默认 JavaFX 平台的 netbeans。在此处输入图像描述

这个例子来自这个网站:http ://onjava.com/pub/a/onjava/2007/07/27/introduction-to-javafx-script.html?page=4

     package captureexample1;


import java.io.*;
import javafx.ui.*;
   import javafx.ui.canvas.*;
 import javafx.ui.filter.*;
import java.awt.Robot;
import java.awt.Rectangle;
import java.awt.image.RenderedImage;
import javax.imageio.ImageIO;
 import java.lang.System;
  class CaptureExample extends CompositeNode{
  attribute lx: Integer;
  attribute ly: Integer;
  operation CaptureExample();
   }
   attribute CaptureExample.lx = 0;
  attribute CaptureExample.ly = 0;
    operation saveCapture(lx_copy:Integer, ly_copy:Integer) {
     var robot = new Robot();
     var rect = new Rectangle (lx_copy, ly_copy, 50, 50);
    var BI=robot.createScreenCapture(rect);
    var file = new File(".//capture.jpg");
    ImageIO.write((RenderedImage)BI, "jpg", file);
     }
     function CaptureExample.composeNode() =
     Group{
     transform: []
    content:[ImageView {
     transform: []
      image: Image { url: ".//app//Sunset.gif" }
      cursor: DEFAULT
     onMouseClicked: operation(e:CanvasMouseEvent) {
     saveCapture(e.source.XOnScreen,e.source.YOnScreen);
     }
      onMouseMoved: operation(e:CanvasMouseEvent) {
      lx = e.x;
      ly = e.y;
       }
     },
      Rect{
    x: bind lx
     y: bind ly
     width: 50
     height:50
     strokeWidth: 1
    stroke: black
    }]
    };
   Frame {
     centerOnScreen: true
     visible: true
    height: 230
    width: 300
    title: "Capture the screen..."
    onClose: operation() {System.exit(0);}
      content: ScrollPane {
    background: white
     view: Canvas {
      background: black
        cursor: DEFAULT
        content: CaptureExample
           }
         }
             }
4

1 回答 1

2

看来您正在混合 JavaFX 脚本和 JavaFX2。

如果你真的想使用 JavaFX 1.3:

  • 获取较旧的 NetBeans,例如 6.1
  • 将您.java的文件重命名为.fx

但是,如果您只是想学习 JavaFX,我真的建议您尝试 JavaFX 2。

于 2012-10-10T23:28:43.463 回答