Hallo,
ich will es nochmal probieren
hat jemand von euch eine IDEE wie ich die Leistung runterkriege
ich habe jetzt überlegt alles in einen Thread zu packen
Ich bräuchte einen Lösungsansatz
Danke!!!!!
ich will es nochmal probieren
hat jemand von euch eine IDEE wie ich die Leistung runterkriege
ich habe jetzt überlegt alles in einen Thread zu packen
Ich bräuchte einen Lösungsansatz
Danke!!!!!
Java:
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.TimerTask;
import java.awt.Color;
import java.awt.Dimension;
import java.io.FileReader;
import java.io.IOException;
import java.util.Timer;
import java.util.Timer;
import java.util.TimerTask;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.TimerTask;
import javax.swing.JTextField;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
public class Main extends JFrame {
private static final long serialVersionUID = 1L;
private JTextField tf;
public Main() {
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
setAlwaysOnTop(rootPaneCheckingEnabled);
// setzt die Position des Jrames
setLocation(450, 80);
// nimmt min. max. close weg
setUndecorated(true);
// JTextArea textArea = new JTextArea();
tf = new JTextField();
// kannst du nicht bearbeiten
tf.setEditable(false);
//JScrollPane scrollPane = new JScrollPane(tf);
//scrollPane.setPreferredSize(new Dimension(230, 50));
tf.setPreferredSize(new Dimension(250,30));
add(tf);
pack();
setVisible(true);
tf.setCursor(null);
tf.setBackground(Color.red);
tf.setForeground(Color.green);
tf.setCaretPosition(tf.getText().length());
tf.setHighlighter(null);
new Timer().schedule(new TextMarqueeTimer(tf), 0L, 200L);
}
public String readLine(FileReader reader) throws IOException {
String line = null;
StringBuilder no = new StringBuilder();
for (int readInt = 0; (readInt = reader.read()) != 13 && readInt != -1;) {
String s = String.valueOf((char) readInt);
if (no == null)
line = s;
else
line += s;
}
reader.read();
return (line);
}
public static void main(String[] args) {
new Main();
}
}
//
class CheckFileContentTimer extends TimerTask {
private static final File FILE = new File("C:/loi/data.txt ");
private long lastMod;
private TextMarqueeTimer textMarqueeTimer;
CheckFileContentTimer(TextMarqueeTimer textMarqueeTimer) {
super();
this.textMarqueeTimer = textMarqueeTimer;
}
public void run() {
while(true) {
try {
long atmLastMod = FILE.lastModified();
if(atmLastMod > lastMod) {
FileReader fileReader = new FileReader(FILE);
StringBuilder stringBuilder = new StringBuilder();
for (String incomingLine = null; !(incomingLine = readLine(fileReader)).equals("");) {
stringBuilder.append(incomingLine.concat(" "));
}
fileReader.close();
lastMod = atmLastMod;
textMarqueeTimer.setNextText(stringBuilder.toString());
}
}
catch (IOException e) {
e.printStackTrace();
}
}
}
public String readLine(FileReader reader) throws IOException {
StringBuilder builder = new StringBuilder();
for (int readInt = 0; (readInt = reader.read()) != 13 && readInt != -1;) {
builder.append((char) readInt);
}
reader.read();
return (builder.toString());
}
}
class TextMarqueeTimer extends TimerTask {
private String atmText = "";
private String nextText = "";
private JTextField textField;
TextMarqueeTimer(JTextField textField) {
new Timer().schedule(new CheckFileContentTimer(this), 0L, 500000L);
this.textField = textField;
}
public void run() {
if(atmText != null && nextText != null) {
if(!atmText.equals(nextText)) {
atmText = nextText;
textField.setText(atmText);
} else {
if(atmText.length() > 0) {
String changedText = textField.getText();
String withoutFirstChar = changedText.substring(1, changedText.length());
char firstChar = changedText.charAt(0);
String newText = withoutFirstChar.concat(String.valueOf(firstChar));
textField.setText(newText);
}
}
}
}
public void setNextText(String nextText) {
this.nextText = nextText;
}
}