Java GWT的AWT组件映射

Java GWT的AWT组件映射,java,gwt,awt,Java,Gwt,Awt,我想用谷歌GWT实现一个15个谜题。我有一个JavaAWT的实现,我想把它转换成GWT puzzel中的瓷砖表示为: import java.awt.Component; import java.awt.image.BufferedImage; import javax.imageio.ImageIO; [...] @SuppressWarnings("serial") public class PuzzleTile extends Component { BufferedImage

我想用谷歌GWT实现一个15个谜题。我有一个JavaAWT的实现,我想把它转换成GWT

puzzel中的瓷砖表示为:

import java.awt.Component;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
[...]

@SuppressWarnings("serial")
public class PuzzleTile extends Component {

    BufferedImage img = null;
    public int[] position = new int[2];
    int[] dim = new int[2];

    public PuzzleTile( String filename, int x, int y ) {
        this.position[0] = x;
        this.position[1] = y;

        try {
            this.img = ImageIO.read( new File(filename) );
            this.dim[0] = img.getWidth(null);
            this.dim[1] = img.getHeight(null);
        } catch (IOException e) {
            System.err.println( "ERROR: Can't open "+filename );
            throw new RuntimeException( "Image not found" );
        }
    }

    public void paint(Graphics g) {
        if ( null != this.img ) {
            g.drawImage( this.img, 0, 0, null );
        }
    }
    [...]
}
拼图表由以下类管理:

import java.awt.Component;
[...]

@SuppressWarnings("serial")
public class PuzzleBoard extends Component implements MouseListener {
    static final String DEFAULT_IMAGE_DIR = "images";
    static final String DEFAULT_TITLE = "Image Puzzle";
    int XSIZE=200;
    int YSIZE=180;

    PuzzleTile[][] board = null;
    //PuzzleTile emptyTile = null;
    int[] dim = new int[2];

    public PuzzleBoard( int x, int y ) {
        this.dim[0] = x;
        this.dim[1] = y;
        this.board = new PuzzleTile[x][y];
        loadTiles( "portrait" );
        this.addMouseListener( this );
    }

    public void loadTiles( String base ) {
        // Draw tiles expect last row
        int x;
        int y;
        for ( y = 0; y < this.dim[1]-1; ++y ) {
            for ( x=0; x < this.dim[0]; ++x ) {
                this.board[x][y] = new PuzzleTile( DEFAULT_IMAGE_DIR+"/"+base+"_"+y+"_"+x+".png" );
                //this.board[x][y].addMouseListener( this );
                //win.add( this.board[x][y] );
            }
        }

        // Draw last row with leftmost tile missing
        for ( x = 0; x < this.dim[0]-1; ++x ) {
            this.board[x][y] = new PuzzleTile( DEFAULT_IMAGE_DIR+"/"+base+"_"+y+"_"+x+".png" );
        }
    }

    public void paint(Graphics g) {
        for ( int xpos = 0; xpos < this.dim[0]; ++xpos ) {
            for ( int ypos = 0; ypos < this.dim[1]; ++ypos ) {
                Graphics area = g.create( xpos*XSIZE+1, ypos*YSIZE+1, XSIZE, YSIZE );
                if ( null != this.board[xpos][ypos] ) {
                    this.board[xpos][ypos].paint( area );
                }
            }
        }
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        int xpos = e.getX() / this.XSIZE;
        int ypos = e.getY() / this.YSIZE;
        System.out.println( "Mouse clicked on tile ("+xpos+", "+ypos+")" );
        if ( null != this.board[xpos][ypos] ) {
            // Check for empty space around
            int[] freelocation = getEmptyNeighbor( xpos, ypos );
            System.out.println( "Empty neighbor: ("+freelocation[0]+", "+freelocation[1]+")" );
            if ( null != freelocation ) {
                this.board[freelocation[0]][freelocation[1]] = this.board[xpos][ypos];
                this.board[xpos][ypos] = null;
                this.repaint();
            }
        }
    }

        [...]

    /**
     * @param args
     */
    public static void main(String[] args) {
        Frame win = null;

        win = new Frame( DEFAULT_TITLE );
        win.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });

        PuzzleBoard puzzle = new PuzzleBoard( 2, 4 );
        win.add(puzzle);
        win.pack();
        win.setVisible(true);
    }
}
是否有人已经实现或看到了这些AWT类到GWT的映射的实现

我大致可以看到以下任务:

为图像组件创建映射 为容器创建一个映射,该容器可以容纳这些图像组件 为映像容器上的事件处理创建映射 有没有人在扩展GWT方面有更多的经验,可以指出一些陷阱并给我一些提示

问候,


马丁。

15拼图界面是一个网格。像FlexTable这样的东西会自动出现。
瓷砖是可点击的。标签或超链接可以帮助您显示和收听瓷砖上的点击。

是否可以将图像加载到Flex表格中?我今晚去看看。谢谢,马丁。是的。只需查看API即可。它接受一个小部件,HTML是一个小部件。您可以使用“抱歉,最近没有多少时间”来嵌入图像。我检查了API,看起来我可以用FlexTable和图像小部件解决这个问题。谢谢,马丁。