Спиральный текст снизу вверх
спиральный текст снизу вверх в Java
Что я уже пробовал:
import java.awt.BorderLayout; import java.awt.Component; import java.awt.EventQueue; import java.awt.Font; import java.awt.TextArea; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.Timer; public class Tickertape { private void display() { JFrame jFrame = new JFrame("TicketTape"); jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String Tape = "E:\\Text\\TickerTap.txt"; String file = redfile(Tape); if (file != null) { TickerPanel mp = new TickerPanel(file, 32); jFrame.add(mp); jFrame.pack(); jFrame.setLocationRelativeTo(null); jFrame.setVisible(true); mp.start(); } } public static void main(String[] args) { /*final JScrollPane scroll = new JScrollPane(); javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { scroll.getVerticalScrollBar().setValue(0); } });*/ EventQueue.invokeLater(new Runnable() { @Override public void run() { new Tickertape().display(); } }); } public String redfile(String file) { String string = ""; try { FileReader reader = new FileReader(file); BufferedReader bufferedReader = new BufferedReader(reader); String line; while ((line = bufferedReader.readLine()) != null) { string += line; } reader.close(); } catch (IOException e) { e.printStackTrace(); } return string; } /** Side-scroll n characters of file */ class TickerPanel extends JPanel implements ActionListener { private static final int RATE = 12; private final Timer timer = new Timer(1000 / RATE, this); private final JLabel label = new JLabel(); private String s; private final int n; private int index; public TickerPanel(String s, int n) { if (s == null || n < 1) { throw new IllegalArgumentException("Null string or n < 1"); } StringBuilder sb = new StringBuilder(n); for (int i = 0; i < n; i++) { sb.append(' '); } this.s = sb + s + sb; this.n = n; label.setFont(new Font("Serif", Font.ITALIC, 36)); /*label.setHorizontalAlignment(JLabel.LEFT); label.setVerticalAlignment(JLabel.BOTTOM);*/ /* label.setText("Left-Bottom"); label.setVerticalTextPosition(JLabel.BOTTOM); label.setHorizontalTextPosition(JLabel.TOP);*/ //label.setBorder(border); label.setText(sb.toString()); /*label.setAlignmentX(10); label.setAlignmentY(8);*/ //label.setHorizontalTextPosition(getX()); //label.setHorizontalAlignment(label.CENTER); //label.setVerticalTextPosition(label.CENTER); //label.setVerticalTextPosition(label.BOTTOM); //label.setVerticalAlignment(label.BOTTOM); this.add(label); } public void start() { timer.start(); } public void stop() { timer.stop(); } @Override public void actionPerformed(ActionEvent e) { index++; if (index > s.length() -n) { index =0; } s = new StringBuffer(s.substring(1)).append(s.substring(0,1)).toString(); /*label.setText(s.substring(index, index + n));*/ label.setText(s); } } }
Richard MacCutchan
В чем заключается ваш вопрос?