Zum Inhalt springen

Devilmarkus

Mitglieder
  • Gesamte Inhalte

    158
  • Benutzer seit

  • Letzter Besuch

Alle Inhalte von Devilmarkus

  1. Hallo, gibt es eine Möglichkeit in JAVA, die Keyboard-translation auf englische Tastatureingabe zu ändern? Ich möchte mein Applet so auslegen, dass es nach Aufruf die Tastatur-Eingabe auf Englisch umstellt... Wäre super, wenn mir jemand helfen könnte. Gruss, Markus
  2. Devilmarkus

    Hilfe gesucht

    Schliesslich habe ich es doch alleine geschafft, die Datei "filelist.txt" zu lesen. Eine kleine Änderung am Code hat es möglich gemacht. import java.io.*; import java.net.URL; import java.util.Vector; import java.applet.Applet; public class e { protected String filePath; public static Vector files; public static Applet applet; public InputStream openFiles(String names) throws Exception { System.out.println("File: " + names); InputStream result; try { URL url = getClass().getResource("filelist.txt"); result = url.openStream(); } catch(Exception e) { URL url = getClass().getResource("filelist.txt"); result = url.openStream(); } return result; } public final void aj(String[] strings) { int c=0; if (files == null) { files = new Vector(); LineNumberReader reader = null; try { reader = new LineNumberReader(new InputStreamReader(openFiles("filelist.txt"))); String line; while((line = reader.readLine()) != null) { System.out.println(line); strings[c]=line; c++; } } catch(Exception ex) { System.out.println("Error " + this); } finally { if (reader != null) try { reader.close(); } catch(Exception ex) { ex.printStackTrace(); } } } } } Vielleicht kann ja der Ein oder Andere dieses für sich gebrauchen... Gruss, Markus
  3. Devilmarkus

    Hilfe gesucht

    Achja, falls jemand wissen möchte, was ein CPC ist: Dies ist ein kleines GIF, welches meinen CPC-Emulator im Einsatz zeigt :cool:
  4. Devilmarkus

    Hilfe gesucht

    Ja genau! Das Applet soll NUR auf die, auf dem Server liegende Datei zugreifen. Ich habe mal den Ursprung der "Computer.java" aus meinem JavaCPC-Emulator hier parat. In dieser Datei wird "Files.txt" vom Server geladen und verarbeitet. package jemu.core.device; import java.applet.*; import java.awt.*; import java.awt.event.*; import java.io.*; import java.util.zip.*; import java.lang.reflect.*; import java.net.*; import java.util.*; import jemu.core.*; import jemu.core.cpu.*; import jemu.core.device.memory.*; import jemu.ui.*; import jemu.util.diss.*; public abstract class Computer extends Device implements Runnable { // Entries are Name, Key, Class, Shown in list public static final ComputerDescriptor[] COMPUTERS = { new ComputerDescriptor("CPC464", "Amstrad CPC464", "jemu.system.cpc.CPC", true), new ComputerDescriptor("CPC664", "Amstrad CPC664", "jemu.system.cpc.CPC", true), new ComputerDescriptor("CPC6128", "Amstrad CPC6128", "jemu.system.cpc.CPC", true) }; public static final String DEFAULT_COMPUTER = "CPC464"; public static final int STOP = 0; public static final int STEP = 1; public static final int STEP_OVER = 2; public static final int RUN = 3; public static final int MAX_FRAME_SKIP = 20; public static final int MAX_FILE_SIZE = 1024 * 1024; // 1024K maximum public Applet applet; protected Thread thread = new Thread(this); protected boolean stopped = false; protected int action = STOP; protected boolean running = false; protected boolean waiting = false; protected long startTime; protected long startCycles; protected String name; protected String romPath; protected String filePath; protected Vector files = null; protected Display display; protected int frameSkip = 0; protected int runTo = -1; protected int mode = STOP; // Listeners for stopped emulation protected Vector listeners = new Vector(1); public static Computer createComputer(Applet applet, String name) throws Exception { for (int index = 0; index < COMPUTERS.length; index++) { if (COMPUTERS[index].key.equalsIgnoreCase(name)) { Class cl = Util.findClass(null,COMPUTERS[index].className); Constructor con = cl.getConstructor(new Class[] { Applet.class, String.class }); return (Computer)con.newInstance(new Object[] { applet, name }); } } throw new Exception("Computer " + name + " not found"); } public Computer(Applet applet, String name) { super("Computer: " + name); this.applet = applet; this.name = name; // thread.setPriority(Thread.MIN_PRIORITY); thread.start(); } protected void setBasePath(String path) { romPath = "system/" + path + "/rom/"; filePath = "system/" + path + "/file/"; } public void initialise() { reset(); } public InputStream openFile(String name) throws Exception { System.out.println("File: " + name); InputStream result; try { result = new URL(applet.getCodeBase(),name).openStream(); } catch(Exception e) { // e.printStackTrace(); result = new FileInputStream(name); } if (name.toLowerCase().endsWith(".zip")) { ZipInputStream str = new ZipInputStream(result); str.getNextEntry(); result = str; } return result; } ~~~~~ gekürzt ~~~~~ protected int readStream(InputStream stream, byte[] buffer, int offs, int size) throws Exception { return readStream(stream,buffer,offs,size,true); } protected int readStream(InputStream stream, byte[] buffer, int offs, int size, boolean error) throws Exception { while(size > 0) { int read = stream.read(buffer,offs,size); if (read == -1) { if (error) throw new Exception("Unexpected end of stream"); else break; } else { offs += read; size -= read; } } return offs; } public byte[] getFile(String name) { return getFile(name,MAX_FILE_SIZE,true); } public byte[] getFile(String name, int size) { return getFile(name,size,false); } public byte[] getFile(String name, int size, boolean crop) { byte[] buffer = new byte[size]; int offs = 0; try { InputStream stream = null; try { stream = openFile(name); while (size > 0) { int read = stream.read(buffer,offs,size); if (read == -1) break; else { offs += read; size -= read; } } } finally { if (stream != null) stream.close(); } } catch (Exception e) { e.printStackTrace(); } if (crop && offs < buffer.length) { byte[] result = new byte[offs]; System.arraycopy(buffer,0,result,0,offs); buffer = result; } return buffer; } ~~~~~ gekürzt ~~~~~ public String getROMPath() { return romPath; } public String getFilePath() { return filePath; } ~~~~~ gekürzt ~~~~~ public Vector getFiles() { if (files == null) { files = new Vector(); LineNumberReader reader = null; try { reader = new LineNumberReader(new InputStreamReader(openFile(filePath + "Files.txt"))); String line; while((line = reader.readLine()) != null) { int iDesc = line.indexOf('='); if (iDesc != -1) { String desc = line.substring(0,iDesc).trim(); int iName = line.indexOf(',',iDesc + 1); if (iName == -1) iName = line.length(); String name = line.substring(iDesc + 1,iName).trim(); String instructions = iName < line.length() ? line.substring(iName + 1).trim().replace('|','\n') : ""; files.addElement(new FileDescriptor(desc,name,instructions)); } } } catch(Exception e) { System.out.println("Cannot get file list for " + this); } finally { if (reader != null) try { reader.close(); } catch(Exception e) { e.printStackTrace(); } } } return files; } public String getFileInfo(String fileName) { String result = null; getFiles(); for (int i = 0; i < files.size(); i++) { FileDescriptor file = (FileDescriptor)files.elementAt(i); if (file.filename.equalsIgnoreCase(fileName)) { result = file.instructions; break; } } return result; } ~~~~~ gekürzt ~~~~~ } Natürlich steht auch noch viel drumherum hier, aber vielleicht hilft es ja, eine Möglichkeit zu finden. Gruss, Markus EDIT: Aufgrund der Länge musste ich Teile aus dem Code entfernen.
  5. Devilmarkus

    Hilfe gesucht

    Nochmal ich: ich habe versucht, die Routine des CPC-Emulators an mein Applet hier anzupassen. import java.io.*; import java.net.URL; import java.util.Vector; import java.applet.Applet; import java.util.zip.ZipInputStream; public class e { protected String filePath; public static Vector files; public static Applet applet; public InputStream openFiles(String names) throws Exception { System.out.println("File: " + names); InputStream result; try { result = new URL(applet.getCodeBase()+"filelist.txt").openStream(); } catch(Exception e) { result = new FileInputStream(names); } if (names.toLowerCase().endsWith(".zip")) { ZipInputStream str = new ZipInputStream(result); str.getNextEntry(); result = str; } return result; } public final void aj(String[] strings) { int c=0; if (files == null) { files = new Vector(); LineNumberReader reader = null; try { reader = new LineNumberReader(new InputStreamReader(openFiles("filelist.txt"))); String line; while((line = reader.readLine()) != null) { System.out.println(line); strings[c]=line; c++; } } catch(Exception ex) { System.out.println("Error " + this); } finally { if (reader != null) try { reader.close(); } catch(Exception ex) { ex.printStackTrace(); } } } } } Auch dieses läuft im Compiler, aber sobald das Applet so online liegt, bekomme ich einen null-Wert zurück :upps
  6. Devilmarkus

    Hilfe gesucht

    Hallo Peter, nein, ich möchte, dass das Applet die Datei vom Server liest. Es liegt sowohl das Applet als .jar in einem Verzeichnis dort, als auch die filelist.txt Es soll also nichts vom heimischen PC gelesen werden. Nur vom Server direkt. In meinem JAVA-CPC-Emulator funktioniert dieses auch (Leider habe ich die Routine dazu nicht programmiert, und es für das andere Projekt umzubasteln, schlug leider auch fehl) Anmerkung: Der Emu verlangt trotzdem eine Sicherheitsabfrage, weil er inzwischen einige Werte in einer .cfg Datei auf dem eigenen PC speichern muss. Diese Sicherheitsabfrage bezieht sich aber nicht auf das einlesen der Files.txt
  7. Devilmarkus

    Hilfe gesucht

    Achja: Die Struktur der filelist.txt sieht folgendermassen aus: Cauldron 2 / Richard Joseph Cauldron2.zip 2 Antiriad / Richard Joseph Antiriad.zip 2 Zombi(UBI Soft) / Philippe Marchiset Zombi.zip 2 Infinity / Beyker Infinity.zip 2 ................ Dabei gibt die erste Zeile den Titel an, die zweite Zeile den Dateinamen und die dritte Zeile sagt dem Player, in welcher Geschwindigkeit der Titel abgespielt werden soll (1 = 1 MHZ, 2 = 2 MHZ) Es handelt sich um einen YM 2149 Soundchip-emulator.
  8. Devilmarkus

    Hilfe gesucht

    Hallo zusammen, ich brauche dringend Hilfe in JAVA. Ich bin dabei, einen Player für alte Computermusik umzubauen. Der alte Player hat die Filelist direkt aus dem Applet gelesen. Ich möchte allerdings, dass der Player die Liste aus einer externen Datei lesen kann (filelist.txt) import java.io.BufferedReader; import java.io.FileReader; public class e { public final void aj(String[] strings) { int c=0; String s; try { FileReader file=new FileReader("filelist.txt"); BufferedReader buffer = new BufferedReader(file); while((s=buffer.readLine()) != null) { strings[c]=s; System.out.println(s); c++; } file.close(); } catch(Exception e) { System.out.println("Error: " + e); } } } Dieser Versuch klappt im Compiler (Netbeans) schon ganz gut, allerdings verliere ich die Zugriffsrechte, sobald ich das Applet auf einen Server lade und von dort aus ausführen möchte. Wie kann ich es also bewerkstelligen, dass die Datei "filelist.txt" auch ohne Änderung der java.policy geladen werden kann? Wäre über jede Hilfe dankbar! MfG Markus

Fachinformatiker.de, 2024 by SE Internet Services

fidelogo_small.png

Schicke uns eine Nachricht!

Fachinformatiker.de ist die größte IT-Community
rund um Ausbildung, Job, Weiterbildung für IT-Fachkräfte.

Fachinformatiker.de App

Download on the App Store
Get it on Google Play

Kontakt

Hier werben?
Oder sende eine E-Mail an

Social media u. feeds

Jobboard für Fachinformatiker und IT-Fachkräfte

×
×
  • Neu erstellen...