Show Posts
|
|
Pages: [1]
|
|
1
|
Discussions / General Discussions / can not write streams to file ?
|
on: 2005-03-23 07:58:58
|
howdy~ i did some exercises on file I/O, but weird that i can only read but not write. here is my code below: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| import java.io.*;
class TestFile_001 { public static void main(String[] args) throws Exception { copy(); }
public static void copy() throws IOException { File fIn = new File("TestFileStreamRead.txt"); File fOut = new File("TestFileStreamWrite.txt");
FileReader fr = new FileReader(fIn); FileWriter fw = new FileWriter(fOut);
int n; while(true) { n = fr.read(); if (n != -1) { fw.write(n); } else { break; } } } } |
TestFileStreamWrite.txt is always empty after running the code, which is supposed to have same content as TestFileStreamRead.txt, i'm sticked here. any solution pls ?
|
|
|
|
|
3
|
Discussions / General Discussions / sound volume control help !
|
on: 2005-02-18 00:59:07
|
hi all~ i'm developing a J2ME game based on MotoE680, my boos just requires in the game the user can control volume of bg sounds, i found an interface "VolumeControl" can help but dunno how to derive its getLevel and setLevel to increase or decrease volume. here is the code: 1 2 3 4 5 6 7 8 9
| public SoundControl implements VolumeControl { ...
public int getLevel() { } } |
any help ?
|
|
|
|
|
4
|
Discussions / General Discussions / Re: inner class problem~
|
on: 2005-02-04 00:23:26
|
|
tks guys and i already find another different solution, just remove main method in TestThread class and put initialization code inside it's constructor, then create another class named say, Test, and build instance of TestThread within Test's main method, it really works, ha!
to gamehacer2000: make it static seems a wonderful trick, i'd like to try it out, and this is the first time i got inner class can be implemented static :p
|
|
|
|
|
5
|
Discussions / General Discussions / Re: inner class problem~
|
on: 2005-02-03 07:38:59
|
All inner (private) classes require an outer (public) class when created because they have an implicit 'this' pointer to the outer object. So you can only really create instances of inner classes from an object of the outer class.
Ditch MyThread and move all its methods into TestThread, then just create an instance of that in main(). u mean to put inner class within the constructor ? i tried but it does not work yet, compiler just reports this: ---------- Java compiler ---------- TestThread1.java:7: illegal start of expression private class MyThread extends Thread ^ TestThread1.java:7: ';' expected private class MyThread extends Thread ^ 2 errors Output completed (1 sec consumed) - Normal Termination
what's the problem here ?
|
|
|
|
|
6
|
Discussions / General Discussions / Re: inner class problem~
|
on: 2005-02-03 05:00:19
|
|
and here is the output looks like:
TestThread.java:7: non-static variable this cannot be referenced from a static context MyThread thread1 = new MyThread("black", 5); ^ TestThread.java:8: non-static variable this cannot be referenced from a static context MyThread thread2 = new MyThread("white", 3); ^ 2 errors Output completed (0 sec consumed) - Normal Termination
anyone could figure it out... tks !
|
|
|
|
|
7
|
Discussions / General Discussions / inner class problem~
|
on: 2005-02-03 04:57:49
|
my test code can not work properly, the matter is compiler forbid me from creating instances of the inner class within main method, how to fix it pls ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| public class TestThread { public static void main(String[] args) { MyThread thread1 = new MyThread("black", 5); MyThread thread2 = new MyThread("white", 3); thread1.start(); thread2.start(); }
private class MyThread extends Thread { public MyThread(String name, int num) { this.name = name; this.num = num; }
public void run() { for (int i=0; i<num; i++) { try { sleep((long)100); } catch (Exception e) {}; System.out.println(name + "\trunning: " + i); } }
private String name; private int num; public int xxx = 5; } } |
regards~
|
|
|
|
|
8
|
Discussions / General Discussions / Re: how to stop a thread safety ?
|
on: 2005-02-03 03:50:37
|
|
tks, and another problem comes, myThread.sleep is handy to pause the running thread, however what if we do not know exactly time thread sleeping ? although passing a very big number to myThread.sleep is helpful i still prefer the way to stop current thread simply(better if we could run it from the point it stops), any suggestions ?
thanx in adv~
|
|
|
|
|
9
|
Discussions / General Discussions / how to stop a thread safety ?
|
on: 2005-02-03 01:40:34
|
hi all~ i start running a thread by calling myThread.start method but there seems no something like myThread.stop() or myThread.die to stop it eternally, of course i could do this by setting the thread to null(like the code below): and is this the only way we could stop the running thread ? regards~
|
|
|
|
|
11
|
Discussions / General Discussions / what neccesary when developing a game with Java ?
|
on: 2005-02-02 01:08:10
|
|
howdy~
im experienced on programming games with J2ME, but it is not such independant and i wonder are there any other ways to developing games with Java, i know awt and swing may help, but it seems those two are not enough and making games are not really their goals, any one could tell me about what tools and packages used for games ?
regards~
|
|
|
|
|
13
|
Java Game APIs & Engines / J2ME / sound problem
|
on: 2005-01-26 00:43:43
|
|
howdy~
i created some midi streams into the game and so when the time i wanted i stopped and play from its head again, i tried player.stop(javax.microedition.media.Player class) method but it only get sounds paused and when i played that sound again by player.start it would go on from the place get paused, i hated this way and want it play from the beginning, any suggestions ?
tks~
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|