Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
for(int i = 1;i <= 20;i++)
{
System.out.println(i);
Thread.sleep(2000);
}
public class SubKlasse extends SuperKlasse {
public static void main(String[] args) {
for (int i = 1; i <= 20; i++) {
System.out.println(i);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
class SuperKlasse {
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class Pria extends JFrame {
// Anfang Variablen
private int comm = 0;
String path;
private TrayIcon trayIcon = null;
private StringSplitter ss = new StringSplitter();
private JTextArea jta = new JTextArea("",1,1);
private JScrollPane jsp= new JScrollPane(jta);
private JMenuBar jmb = new JMenuBar();
JTextField jtf = new JTextField();
private JButton jbu = new JButton();
private AutostartOptions ao = null;
private ScriptReader sr = new ScriptReader(this);
private FilteredFileReader fl = new FilteredFileReader();
private MyActionListener
myActionListener = new MyActionListener(this);
// Ende Variablen
public Pria(String title) {
// Frame-Initialisierung
super(title);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) { setVisible(false); }
});
int frameWidth = 500;
int frameHeight = 340;
setSize(frameWidth, frameHeight);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int x = (d.width - getSize().width) / 2;
int y = (d.height - getSize().height) / 2 ;
setLocation(x, y);
Container cp = getContentPane();
cp.setLayout(null);
// Anfang Komponenten
/////////////////////////////////////////////////////////
Image image = Toolkit.getDefaultToolkit().getImage(
Pria.class.getResource("Pria.gif") );
PopupMenu popup = new PopupMenu();
MenuItem oc = new MenuItem("ComandLine");
MenuItem fav = new MenuItem("Favorites");
MenuItem upd = new MenuItem("Updater");
MenuItem ex = new MenuItem("Exit");
popup.add(oc);
popup.add(fav);
popup.add(upd);
popup.add(ex);
oc.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
ocActionPerformed(evt); } });
fav.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
favActionPerformed(evt); } });
upd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
updActionPerformed(evt); } });
ex.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
exActionPerformed(evt); } });
trayIcon = new TrayIcon( image, "Pria ComandWindow v.0.1b", popup );
trayIcon.setImageAutoSize( true );
SystemTray tray = SystemTray.getSystemTray();
try{tray.add( trayIcon );}catch(AWTException error){}
/////////////////////////////////////////////////////////
//Textfenster
jta.setText("");
jsp.setBounds(0, 0, 500, 266);
jta.setLineWrap(true);
jta.setEditable(false);
cp.add(jsp);
//MenuBar
setJMenuBar(jmb);
JMenu datei = new JMenu("File");
JMenuItem se = new JMenuItem("Editor");
JMenuItem exit = new JMenuItem("Exit");
datei.add(se);
datei.add(exit);
jmb.add(datei);
se.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
seActionPerformed(evt); } });
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
System.exit(0); } });
JMenu options = new JMenu("Options");
JMenuItem asp = new JMenuItem("Autostart-Script");
options.add(asp);
jmb.add(options);
asp.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
aspActionPerformed(evt); } });
//Eingabebereich
jtf.setBounds(0, 266, 500, 21);
cp.add(jtf);
//Listeners
jtf.addActionListener(myActionListener);
// Ende Komponenten
setResizable(false);
setVisible(true);
reader("config.asl");
path = fl.son[2];
if(path.equals(""))
path = path;
else
{
sr.preperate(path,null,0);
sr.readScript();
}
}
// Anfang Ereignisprozeduren
public void ocActionPerformed(ActionEvent evt)
{
setVisible(true);
}
public void favActionPerformed(ActionEvent evt)
{
Favorites fa = new Favorites("Your Favorites");
}
public void updActionPerformed(ActionEvent evt)
{
String errProt = "";
try{Process process = Runtime.getRuntime().exec("Updater.exe");}catch(IOException err){setVisible(true);write(err + "\n");}
if(errProt.equals(""))
System.exit(0);
}
public void exActionPerformed(ActionEvent evt)
{
System.exit(0);
}
public void seActionPerformed(ActionEvent evt)
{
ASLEditor asle = new ASLEditor("ScriptEditor");
}
public void aspActionPerformed(ActionEvent evt)
{
ao = new AutostartOptions(this,this,"Pria-AutostartOptions",true,"");
path = ao.path;
String inhalt = "/////////////Config//////////////" + "\n" + "@" + path + "$";
File fn = new File("Scripts" + fl.son[0] + "config.asl");
try
{
FileOutputStream fileout = new FileOutputStream(fn);
fileout.write(inhalt.getBytes(), 0,inhalt.length());
fileout.close();
}
catch(FileNotFoundException e){}catch(IOException e){}
}
// Ende Ereignisprozeduren
void setLayout(String farbe,String schrift)
{
if(farbe.equals("magenta"))
{
jta.setBackground(Color.magenta);
jtf.setBackground(Color.magenta);
}
else
if(farbe.equals("green"))
{
jta.setBackground(Color.green);
jtf.setBackground(Color.green);
}
else
if(farbe.equals("yellow"))
{
jta.setBackground(Color.yellow);
jtf.setBackground(Color.yellow);
}
else
if(farbe.equals("white"))
{
jta.setBackground(Color.white);
jtf.setBackground(Color.white);
}
else
if(farbe.equals("red"))
{
jta.setBackground(Color.red);
jtf.setBackground(Color.red);
}
else
if(farbe.equals("pink"))
{
jta.setBackground(Color.pink);
jtf.setBackground(Color.pink);
}
else
if(farbe.equals("orange"))
{
jta.setBackground(Color.orange);
jtf.setBackground(Color.orange);
}
else
if(farbe.equals("gray"))
{
jta.setBackground(Color.gray);
jtf.setBackground(Color.gray);
}
else
if(farbe.equals("cyan"))
{
jta.setBackground(Color.cyan);
jtf.setBackground(Color.cyan);
}
else
if(farbe.equals("black"))
{
jta.setBackground(Color.black);
jtf.setBackground(Color.black);
}
else
if(farbe.equals("blue"))
{
jta.setBackground(Color.blue);
jtf.setBackground(Color.blue);
}
else
if(farbe.equals("lightGray"))
{
jta.setBackground(Color.lightGray);
jtf.setBackground(Color.lightGray);
}
else
if(farbe.equals("darkGray"))
{
jta.setBackground(Color.darkGray);
jtf.setBackground(Color.darkGray);
}
if(schrift.equals("magenta"))
{
jta.setForeground(Color.magenta);
jtf.setForeground(Color.magenta);
}
else
if(schrift.equals("green"))
{
jta.setForeground(Color.green);
jtf.setForeground(Color.green);
}
else
if(schrift.equals("yellow"))
{
jta.setForeground(Color.yellow);
jtf.setForeground(Color.yellow);
}
else
if(schrift.equals("white"))
{
jta.setForeground(Color.white);
jtf.setForeground(Color.white);
}
else
if(schrift.equals("red"))
{
jta.setForeground(Color.red);
jtf.setForeground(Color.red);
}
else
if(schrift.equals("pink"))
{
jta.setForeground(Color.pink);
jtf.setForeground(Color.pink);
}
else
if(schrift.equals("orange"))
{
jta.setForeground(Color.orange);
jtf.setForeground(Color.orange);
}
else
if(schrift.equals("gray"))
{
jta.setForeground(Color.gray);
jtf.setForeground(Color.gray);
}
else
if(schrift.equals("cyan"))
{
jta.setForeground(Color.cyan);
jtf.setForeground(Color.cyan);
}
else
if(schrift.equals("black"))
{
jta.setForeground(Color.black);
jtf.setForeground(Color.black);
}
else
if(schrift.equals("blue"))
{
jta.setForeground(Color.blue);
jtf.setForeground(Color.blue);
}
else
if(schrift.equals("lightGray"))
{
jta.setForeground(Color.lightGray);
jtf.setForeground(Color.lightGray);
}
else
if(schrift.equals("darkGray"))
{
jta.setForeground(Color.darkGray);
jtf.setForeground(Color.darkGray);
}
}
void write(String text)
{
jta.setText(jta.getText() + text);
}
void interpretComand(String comand)
{
comm++;
String cm = ss.splitt(comand," ");
if(cm.equals("write"))
write(ss.str[1] + "\n");
else
if(cm.equals("setLayout"))
setLayout(ss.str[1],ss.str[2]);
else
if(cm.equals("exit"))
System.exit(0);
else
if(cm.equals("runScript"))
{
sr.preperate(ss.str[1],null,0);
sr.readScript();
}
else
write("> Error at Line " + comm + "invalid Comand: " + comand + "\n");
}
void reader(String file)
{
if(fl.readFile("Scripts" + fl.son[0] + file))
write("<----- " + file + " ----->" + "\n");
else
write("<-- !! LoadingError " + file + " !! -->" + "\n");
}
}
import java.io.*;
import java.util.*;
import java.net.*;
import java.awt.*;
class ScriptReader
{
Pria p;
private String script;
private String param;
private int lines;
public ScriptReader(Pria p)
{
this.p = p;
}
void preperate(String script,String param,int lines)
{
this.script = script;
this.param = param;
this.lines = lines;
}
public void readScript()
{
/////////////////////////
String[] strArray = null;
int[] intArray = null;
double[] dblArray = null;
boolean[] blArray = null;
char[] chArray = null;
////////////////////////
boolean waitForAction = true;
boolean nquit = true;
boolean cl = true;
boolean bl = false;
fenster f = null;
dialog d = null;
int hight = 300;
int width = 300;
FilteredFileReader fl = new FilteredFileReader();
//Ereignissblock
while(nquit)
{
if(script.equals(""))
{
if(param != null)
{
fl.son[0] = param;
fl.a = 2 + lines;
nquit = false;
}
}
else
cl = fl.readFile(script);
if(cl)
{////////////////////////
for(int i = 2;i < fl.a;i++)
{
if(fl.son[i].equals("init String"))
{
i++;
strArray = new String[Integer.parseInt(fl.son[i])];
for(int s = 0;s < Integer.parseInt(fl.son[i]);s++)
strArray[i] = "";
}
else
if(fl.son[i].equals("init int"))
{
i++;
intArray = new int[Integer.parseInt(fl.son[i])];
for(int s = 0;s < Integer.parseInt(fl.son[i]);s++)
intArray[i] = 0;
}
else
if(fl.son[i].equals("init double"))
{
i++;
dblArray = new double[Integer.parseInt(fl.son[i])];
for(int s = 0;s < Integer.parseInt(fl.son[i]);s++)
dblArray[i] = 0;
}
else
if(fl.son[i].equals("init boolean"))
{
i++;
blArray = new boolean[Integer.parseInt(fl.son[i])];
int r = Integer.parseInt(fl.son[i]);
i++;
for(int s = 0;s < r;s++)
if(fl.son[i].equals("true"))
blArray[i] = true;
else
blArray[i] = false;
}
else
if(fl.son[i].equals("init char"))
{
i++;
chArray = new char[Integer.parseInt(fl.son[i])];
for(int s = 0;s < Integer.parseInt(fl.son[i]);s++)
chArray[i] = 0;
}
else
if(fl.son[i].equals("lockDefaultWindow"))
{
f.setResizable(false);
}
else
if(fl.son[i].equals("setUndecore"))
{
bl = true;
}
else
if(fl.son[i].equals("addTo"))
{
i++;
if(fl.son[i].equals("String"))
{
i++;
int zs = Integer.parseInt(fl.son[i]);
i++;
strArray[zs] = fl.son[i];
}
else
if(fl.son[i].equals("int"))
{
i++;
int zs = Integer.parseInt(fl.son[i]);
i++;
intArray[zs] = Integer.parseInt(fl.son[i]);
}
else
if(fl.son[i].equals("double"))
{
i++;
int zs = Integer.parseInt(fl.son[i]);
i++;
dblArray[zs] = Double.parseDouble(fl.son[i]);
}
else
if(fl.son[i].equals("boolean"))
{
i++;
int zs = Integer.parseInt(fl.son[i]);
i++;
if(fl.son[i].equals("true"))
blArray[zs] = true;
else
blArray[zs] = false;
}
else
if(fl.son[i].equals("char"))
{
i++;
int zs = Integer.parseInt(fl.son[i]);
i++;
char chs = fl.son[i].charAt(0);
chArray[zs] = chs;
}
}
else
if(fl.son[i].equals("mathAdd"))
{
i++;
if(fl.son[i].equals("int"))
{
i++;
int zs = Integer.parseInt(fl.son[i]);
i++;
intArray[zs] = intArray[zs] + Integer.parseInt(fl.son[i]);
}
else
if(fl.son[i].equals("double"))
{
i++;
int zs = Integer.parseInt(fl.son[i]);
i++;
dblArray[zs] = intArray[zs] + Double.parseDouble(fl.son[i]);
}
}
else
if(fl.son[i].equals("mathSub"))
{
i++;
if(fl.son[i].equals("int"))
{
i++;
int zs = Integer.parseInt(fl.son[i]);
i++;
intArray[zs] = intArray[zs] - Integer.parseInt(fl.son[i]);
}
else
if(fl.son[i].equals("double"))
{
i++;
int zs = Integer.parseInt(fl.son[i]);
i++;
dblArray[zs] = intArray[zs] - Double.parseDouble(fl.son[i]);
}
}
else
if(fl.son[i].equals("addToString"))
{
i++;
if(fl.son[i].equals("Text"))
{
i++;
int zs = Integer.parseInt(fl.son[i]);
i++;
strArray[zs] = strArray[zs] + fl.son[i];
}
else
if(fl.son[i].equals("var"))
{
if(fl.son[i].equals("String"))
{
i++;
int zs = Integer.parseInt(fl.son[i]);
i++;
int zs2 = Integer.parseInt(fl.son[i]);
strArray[zs] = strArray[zs] + strArray[zs2];
}
else
if(fl.son[i].equals("String"))
{
i++;
int zs = Integer.parseInt(fl.son[i]);
i++;
int zs2 = Integer.parseInt(fl.son[i]);
strArray[zs] = strArray[zs] + chArray[zs2];
}
}
}
else
if(fl.son[i].equals("setWindowBounds"))
{
i++;
if(fl.son[i].equals(">"))
{
if(fl.son[i].equals("String"))
{
i++;
int zs = Integer.parseInt(fl.son[i]);
width = Integer.parseInt(strArray[zs]);
}
else
if(fl.son[i].equals("int"))
{
i++;
int zs = Integer.parseInt(fl.son[i]);
width = intArray[zs];
}
i++;
if(fl.son[i].equals("String"))
{
i++;
int zs = Integer.parseInt(fl.son[i]);
hight = Integer.parseInt(strArray[zs]);
}
else
if(fl.son[i].equals("int"))
{
i++;
int zs = Integer.parseInt(fl.son[i]);
hight = intArray[zs];
}
}
else
{
width = Integer.parseInt(fl.son[i]);
i++;
hight = Integer.parseInt(fl.son[i]);
}
}
else
if(fl.son[i].equals("callDefaultWindow"))
{
i++;
if(fl.son[i].equals(">"))
{
i++;
int zs = Integer.parseInt(fl.son[i]);
f = new fenster(strArray[zs],width,hight,bl);
}
else
f = new fenster(fl.son[i],width,hight,bl);
}
else
if(fl.son[i].equals("addDefaultButton"))
{
i++;
String button = fl.son[i];
i++;
String label = fl.son[i];
i++;
int x = Integer.parseInt(fl.son[i]);
i++;
int y = Integer.parseInt(fl.son[i]);
i++;
int w= Integer.parseInt(fl.son[i]);
i++;
int h = Integer.parseInt(fl.son[i]);
f.addButton(button,label,x,y,w,h);
}
else
if(fl.son[i].equals("hideDefaultWindow"))
{
f.setVisible(false);
}
else
if(fl.son[i].equals("hideComandWindow"))
{
p.setVisible(false);
}
else
if(fl.son[i].equals("showDefaultWindow"))
{
f.setVisible(true);
}
else
if(fl.son[i].equals("showComandWindow"))
{
p.setVisible(true);
}
else
if(fl.son[i].equals("setLayout"))
{
i++;
String l1 = fl.son[i];
i++;
String l2 = fl.son[i];
p.setLayout(l1,l2);
}
else
if(fl.son[i].equals("setDefaultColor"))
{
i++;
f.setTextColor(fl.son[i]);
}
else
if(fl.son[i].equals("setDefaultBGColor"))
{
i++;
if(fl.son[i].equals("magenta"))
f.setBackground(Color.magenta);
else
if(fl.son[i].equals("green"))
f.setBackground(Color.green);
else
if(fl.son[i].equals("yellow"))
f.setBackground(Color.yellow);
else
if(fl.son[i].equals("white"))
f.setBackground(Color.white);
else
if(fl.son[i].equals("red"))
f.setBackground(Color.red);
else
if(fl.son[i].equals("pink"))
f.setBackground(Color.pink);
else
if(fl.son[i].equals("orange"))
f.setBackground(Color.orange);
else
if(fl.son[i].equals("gray"))
f.setBackground(Color.gray);
else
if(fl.son[i].equals("cyan"))
f.setBackground(Color.cyan);
else
if(fl.son[i].equals("black"))
f.setBackground(Color.black);
else
if(fl.son[i].equals("blue"))
f.setBackground(Color.blue);
else
if(fl.son[i].equals("lightGray"))
f.setBackground(Color.lightGray);
else
if(fl.son[i].equals("darkGray"))
f.setBackground(Color.darkGray);
else
{
p.write("Error in " + fl.file + " at line " + (i - 2) + " invalid Comand: " + fl.son[i] + "\n");
}
}
else
if(fl.son[i].equals("W_writeDefaultString"))
{
String text = "";
int y = 0;
int x = 0;
i++;
if(fl.son[i].equals(">"))
{
i++;
int zs = Integer.parseInt(fl.son[i]);
text = strArray[i];
i++;
zs = Integer.parseInt(fl.son[i]);
x = intArray[zs];
i++;
zs = Integer.parseInt(fl.son[i]);
y = intArray[zs];
}
else
{
text = fl.son[i];
i++;
x = Integer.parseInt(fl.son[i]);
i++;
y = Integer.parseInt(fl.son[i]);
}
f.writeString(text,x,y);
}
else
if(fl.son[i].equals("c_writeString"))
{
i++;
p.write(fl.son[i]);
}
else
if(fl.son[i].equals("c_writeStringAtLines"))
{
i++;
p.write(fl.son[i] + "\n");
}
else
if(fl.son[i].equals("wait"))
{
int time = 0;
i++;
if(fl.son[i].equals(">"))
{
i++;
int zs = Integer.parseInt(fl.son[i]);
time = intArray[zs];
}
time = Integer.parseInt(fl.son[i]);
try{Thread.sleep(time);}catch(InterruptedException err){}
}
else
if(fl.son[i].equals("end"))
{
nquit = false;
p.write("Erfolgreich ausgeführt" + "\n");
}
else
if(fl.son[i].equals("exit"))
{
System.exit(0);
}
else
if(fl.son[i].equals("waitForDefaultAction"))
{
while(waitForAction)
{
if(f.action.equals(""))
waitForAction = true;
else
waitForAction = false;
System.out.println("..");
}
}
else
if(fl.son[i].equals("defaultActionDone"))
{
i++;
if(f.action.equals(fl.son[i]))
{
i++;
}
else
{
i++;
i = i + Integer.parseInt(fl.son[i]);
}
}
else
if(fl.son[i].equals("clearDefaultActionEvent"))
f.action = "";
else
if(fl.son[i].equals("call"))
{
i++;
String file = "";
if(fl.son[i].equals(">"))
{
i++;
int zs = Integer.parseInt(fl.son[i]);
file = strArray[i];
}
else
file = fl.son[i];
cl = fl.readFile(file);
if(cl)
i = 1;
else
{
p.write("Error in " + fl.file + " at line " + (i - 2) + " invalid Comand: " + fl.son[i] + "\n");
}
}
else
{
p.write("Error in " + fl.file + " at line " + (i - 2) + " invalid Comand: " + fl.son[i] + "\n");
}
}//////////////////////////
}
else
{
p.write("InputError while reading File: " + fl.file + "\n");
nquit = false;
}
}
//end Ereignissblock
}
}
Wenn du in einem Thread Thread.sleep(...) aufrufst, dann wird eben dieser Thread für die angegebene Zeit schlafen gelegt. D.h. dass auch keine Ausgaben in dieser Zeit erfolgen, da der entsprechende Thread ja schläft. Ein weiteres Problem könnte sein, dass du in einen Deadlock reingelaufen bist.Sleep in Subklassen
Hi,
ich wollte mal fragen , warum bei einer Subklasse eine aufgerufene
Code:
Thread.sleep(x);
Funktion z.b. in einer Schleife , die Aktionen so behindert , dass sie nur nach durchlauf der Schleife sichtbar sind , und in der Main-Klasse das aber alles problemlos funktioniert?
if(fl.son[i].equals(">"))
{
i++;
int zs = Integer.parseInt(fl.son[i]);
time = intArray[zs];
}
time = Integer.parseInt(fl.son[i]);
try{Thread.sleep(time);}catch(InterruptedException err){}
..if(fl.son[i].equals("waitForAction"))