0

ジャバ初心者。Jpanel とタイマーを使用してスクロール テキストを表示しようとしていますが、機能しますが、システムの行セパレーターを使用して行セパレーターを挿入しようとしましたが、テキストは改行なしで表示されます。なぜですか?

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JPanel;


public class Participants extends JPanel
{
     private int x;
     private int y;
     private String text;

     Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

    public Participants  ()
    {
        x = 600;
        y = 1200;
        String eol = System.getProperty("line.separator");  

        text = "Story Director/Producer:"+eol+"Mr. SMith" +
             "Technical Director:" +  eol + 
              "Mr. T" +  eol + eol;

        setSize(1200, 900);
    }

public void paint(Graphics g)
{
    super.paint(g);
    g.setColor(Color.white);
    g.fillRect(0, 0, 1200, 900);
    g.setColor(Color.black);
    g.drawString(text,x, y);


}

public void start() throws InterruptedException
{
    while(true)
    {
        while(y >= 0)
        {
            x = getWidth() / 2;
            y--;
            repaint();
            Thread.sleep(10);
        }
    }
}

public static void main (String [] args) throws InterruptedException
{
    JFrame frame = new JFrame("Participants  ");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Participants participants  = new Participants ();
    frame.getContentPane().add(participants  );
    frame.setSize(1200, 900);
    frame.setVisible(true);
    participants  .start();
}

}

4

1 に答える 1

1

改行 (\n) は、コンソール書き込みでのみ機能します。スイングでは機能しません。別の Draw メソッドを使用して、別のテキストを書き込むだけです。

よろしく、ラヴィ

于 2013-04-11T04:14:06.247 に答える