1

タグhtml5に似たマーキーがあり、テキストは右から左に水平に移動し、エラーなしで完全に機能します。

public class texscroll extends JPanel {
    private int x = 510, y = 25;
    private String string = "Text in moving similary to the tags HTML5 Marquesina (<marquee>).";

    public texscroll() {
        Font font = new Font("Arial", Font.BOLD + Font.PLAIN, 15);
        setFont(font);
        setForeground(Color.BLACK);
        setOpaque(false);
        Timer timer = new Timer(14, new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                x -= 1;
                if (x == -10 * string.length()) {
                    x = 510;
                }
                repaint();
            }            
        });
        timer.start();
    }

    @Override
    public Dimension getPreferredSize() {
        return new Dimension(720, 480);
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g); //To change body of generated methods, choose Tools | Templates.
        Graphics2D g2 = (Graphics2D) g;
        g2.drawString(string, x, y);
    }        
}

でも今は、動きのあるテキストや画像を追加したり組み合わせたりしたいと思っています。

private String string = "Text in moving similary to the tags HTML5 Marquesina (<marquee>).";

(img/img.png)動きを視覚化できるように画像を呼び出すにはどうすればよいですか?

4

1 に答える 1