Double Buffering Slow..is it in the code? or..

Hi all..
i make small application which use double buffering..
here's the code:
public void update(Graphics g){
        tys_a=System.currentTimeMillis();
        Dimension d = getSize();       
        if (offscreenImage == null || offscreenImage.getWidth(null) < d.width || offscreenImage.getHeight(null) < d.height){
            if (offscreenImage != null) offscreenImage.flush();
            offscreenImage = createImage(d.width, d.height);
            offscreenSize = d;
            offscreenGraphics = offscreenImage.getGraphics();
        offscreenGraphics.clearRect(0, 0, d.width, d.height);
        paint(offscreenGraphics);
        g.drawImage(offscreenImage, 0, 0, null);
        g.dispose();
        tys_b=System.currentTimeMillis();
        tys_c=tys_b-tys_a;
        System.out.println("DRAW OFFSCREEN GRAPH " + tys_c + " --- " + tys_a + " ---- " + tys_b);
    }then i run it on my desktop PC, which specs are
Core 2 duo E4500 - 2.20Ghz, 2 Gb RAM , Vista Home Premium
its works fine..took 10 ms
but when i try on Sony vaio laptop, which specs are:
core 2 duo T8100 - 2.1Gghz, 2Gb RAM, Vista home premium
its so slow..took average about 800-900ms (80-90 times slower)
did i do something wrong with my code...i've been searching all day...but seems no answer
but all i can think..is not about the code..because it works fine in my desktop...
but i dunno what cause this problem?
any body can help?or ever have this kind of problem willing to share?
Thx,

AndrewThompson64 wrote:
>
Hi,
dunnoIs this a English word???>Is this an English word? No it is not, it is strine* for "I do not know". I understand the Americans also know of this strine abbreviation, but I cannot understand how, since their comprehension of strine is quite low.
* local pronunciation of 'Australian'.
But to the OP. It is a far better idea to phrase your replies in standard English, since many people who understand English do not understand (or will not tolerate) local abbreviations and slang.In the South West of England It can be translated as "I don't know and I don't care" often accompanied by a shrug of the shoulders.

Similar Messages

  • Drawing with double buffering to a JFrame

    I want to create a simple JFrame and draw stuff to it via Graphic object using double buffering.
    If I create a loop and draw constantly using JFrame.getGraphic().xxx, am i doing double buffering. ( 'cause i read somewhere that swing components automaticly use double buffering ). And is this the righ approuch ( or whatever it's spelled ) ?

    I want to create a simple JFrame and draw stuff to it
    Don't do that.
    If you want to do custom rendering then use JPanel or JComponent, not JFrame.
    If I create a loop and draw constantly using JFrame.getGraphic().xxx, am i doing double buffering.
    No.
    You're also painting outside the standard paint cycle, which is a Bad Idea.
    So, essentially, everything your suggesting is the wrong way to go about things.
    In its most simple form, double buffering works something like this, though there are a whole load of subtleties to consider (such as component resizing for a start)
    public class Foo extends JComponent
        private BufferedImage image = null;
        protected void paintComponent(Graphics g)
            if (image != null)
                image = createImage(getWidth(), getHeight());
                paintBuffer(ig);
            g.drawImage(image, 0, 0, this);
        private void paintBuffer()
            Graphics ig = image.getGraphics();
            // do the rendering
            ig.dispose();
    }

  • How does buffer size affect double buffered waveform generation?

    I had originally posted the following question:
    "Why does the double buffered waveform generation pause after the first buffer before continuing?"
    "I am using an AT-AO-10 board to generate a multiple channel waveform in double buffered mode. The board's DAC's are updated by an external clock signal. While the waveform generation performs well, I notice that after the first buffer has been generated there is a time delay before the next buffer is output. However the second buffer and thereafter perform well without any time delays. If anyone can provide me an explanation on why this happens I would appreciate it. I am using NI-DAQ API functions to generate the waveforms and my settings for the WFM_DB_Config function are 1 for oldDataStop to disallow regeneration of data and 0 for partialTransferStop to not stop when a half buffer is partially transferred."
    -posted by Vadi on 6/7/2001
    I received a response from Geneva as follows:
    Geneva L. on 6/11/2001 says:
    "Vadi,
    The first thing is to make sure that you have the latest version of NI-DAQ installed, NI-DAQ 6.9.1. If you need to install it, make sure you completely uninstall any prior versions. Then, you will have examples installed in either the NI-DAQ or the CVI directory. In the AO directory, you should find the WFMdoubleBuf example.
    Start with that to make sure the output appears as you expect. Then, you can modify it to apply your external update clock, following the idea presented in the WFMsingleBufExtUpdate example. You might even want to double-check that your external clock acts as you expect using an oscilloscope.
    Finally, modify the example such that you can update on multiple channels, remembering that you interleave each channels buffer into one buffer for WFM_DB_Transfer. Whatever data is in the buffer will be updated on the output channels.
    Regards,
    Geneva L.
    Applications Engineer
    National Instruments"
    I have checked my version of NI-DAQ and it is 6.9.1. I am generating the double buffered waveform according to the format shown in WFMdoubleBuf and with some modifications from WFMsingleBufExtUpdate to allow me to use my external update clock. However I continue to notice the same phenomena again and again. For a buffer size of 7500 or 10000 points there is a time lag meaning after the first buffer has been output there is a noticeable time delay before the second buffer and buffers there after is output. This time lag doesn't exist for the buffers that are output after the first buffer but it does exist for the first buffer. When I decrease the buffer size down to 5000 points the time lag disappears (Note: this phenomena also occurs when I use an internal time base as opposed to my external clock). Is there a reason for this? I am using a AT-AO-10 board and I know the on board FIFO is 1024 points deep. However from the documentation provided it doesn't indicate that double buffered mode uses the on board FIFO at all. In fact, the functions require that the FIFO mode be turned off (in WFM_Load) for double buffered waveform generation. Is there a reason why when the buffer size is increased that there is a time lag after the first buffer? Is this because of the functions themselves or is this because of the AT-AO-10 board?

    Vadi,
    Make sure that your buffer size is set to the same number of points that you're actually writing to the buffer initially. For instance, if you run the example as-is, the NIDAQMakeBuffer puts exactly the ulCount amount of data into the buffer. Then, it continuously writes out half buffers. Thus, if you are not writing enough data to fill up the buffer the first time, there will be that lag until the section where half buffers are output.
    Regards,
    Geneva L.
    Applications Engineer
    National Instruments
    http://www.ni.com/ask

  • Code for Double Buffering

    Hi.
    I did go through the JAVA tutorial here, but I still am not very clear about how to do double buffering. Can someone just give me a sample code? It would make my understanding clearer.
    Also, for making games like mario or contra, should I use .gif images or .jpg?
    Thanking You all

    private Image offScreenImage;
    private Graphics offScreen;
    public void update(Graphics g){
    offScreenImage=createImage(this.getSize().width, this.getSize().height);
    offScreen=offScreenImage.getGraphics();
    paint(offScreen);
    g.drawImage(offScreenImage,0,0,this);
    there you go... enjoy =)
    Michael

  • JNI slows the code down...

    Hi,
    I've written a piece of jni code, basically to enable my app to handle linux signals. At the moment the jni code does nothing but lunch java VM and calls static function from my class (inside some JAR file). I have noticed that the program executes about 3-4 times slower than as if I started it without the jni part... ("java -jar myjar.jar" ...). Any ideas exlaining such behaviour? I suppose that the program might start a bit slower as all th edynamic libraries need to be loaded, but thats not the thing. Even after all the stuff is loaded it doesnt speed up. I'm using 1.6u6.
    I'll check later today if it'd help to lunch my app from jni, spawn it to new thread, return to jni and sleep. This way, I suppose, the code wouldn't be executed "from" jni but only inside VM? Does that make any sense to anyone?
    Thanks for any feedback?
    Lukasz

    hi, actually this is not what I meant. I am aware that jni calls are quite slow but...
    What I'm doing is that I'm lunching the whole java application using a piece of C code:
    My java app has class Main which has static method void start(String[]) and normal entry method main.
    to initiate the app I can either run my jar normally using "java -jar myjar.jar" or I I can (and did) write a piece of C code which will open JVM and call start() method.
    see bolow:
    JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);//starting JVM
    jclass Main=(*env)->FindClass(env,Java_Main);//looking for class Main
    jmethodID statMethode = (*env)->GetStaticMethodID(env,Main,"start","([Ljava/lang/String;)V");
    (*env)->CallStaticVoidMethod(env, Main, statMethode,args);
    the difference is that when I start my app using the second method, the application works 3-4 times slower. I'm wondering if this is a normal behaviour of JNI or perhaps I'm doing something wrong?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • AP1231G-A-K9 access points - very slow throughput - Is TKIP the issue?

    I recently setup our small office network using the following setup:
    Cablemodem <--> router <--> 1231AP(role root bridge with wireless clients) <-> 1231AP(role non-root bridge with wireless clients)
    Code on both APs: 12.3(8)JEE
    Office network generally has less than 3 wireless clients connected at any one time to either AP.
    AP's are a mere 50' apart; clients are all less than 30' from either AP; they all show excellent signal and connected at 54mbps signaling rates.
    All is/has been working very well & very stable with the exception of speed. We have business class service from RR, approx 25mbps dl, 2mbps ul. Any hardwired client to the router switch ports are able to download at speeds averaging 23mbps. Any wireless client connected to either AP is never able to exceed download speeds of 5mbps. With no other wireless clients connected except my one test client, I was not able to exceed 5mbps throughput from either AP that I connected to.
    I can confirm that the ethernet connection between the router and root bridge is up at 100mbps-FD and not showing any errors:
    ap#sh interfaces FastEthernet0
    FastEthernet0 is up, line protocol is up
      Hardware is PowerPC405GP Ethernet, address is 0013.60cf.bb29 (bia 0013.60cf.bb29)
      MTU 1500 bytes, BW 100000 Kbit, DLY 100 usec,
         reliability 255/255, txload 1/255, rxload 1/255
      Encapsulation ARPA, loopback not set
      Full-duplex, 100Mb/s, MII
      ARP type: ARPA, ARP Timeout 04:00:00
      Last input 00:00:00, output 00:00:00, output hang never
      Last clearing of "show interface" counters never
      Input queue: 0/160/0/0 (size/max/drops/flushes); Total output drops: 0
      Queueing strategy: fifo
      Output queue: 0/40 (size/max)
      5 minute input rate 5000 bits/sec, 0 packets/sec
      5 minute output rate 1000 bits/sec, 1 packets/sec
         8054605 packets input, 3141009145 bytes
         Received 46005 broadcasts, 0 runts, 0 giants, 0 throttles
         0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
         0 watchdog
         0 input packets with dribble condition detected
         4076106 packets output, 411952731 bytes, 0 underruns
         0 output errors, 0 collisions, 4 interface resets
         0 babbles, 0 late collision, 0 deferred
         0 lost carrier, 0 no carrier
         0 output buffer failures, 0 output buffers swapped out
    Wandering thru the cli on either AP shows that all wireless clients are indeed connected at 54mbps to their respective AP and the two AP's are connected happily at 54mbps signaling:
    Address           : 0013.1a37.b3e0     Name             : ap
    IP Address        : 192.168.0.120      Interface        : Dot11Radio 0
    Device            : 11g-bridge         Software Version : 12.3
    CCX Version       : NONE
    State             : Assoc              Parent           : Our Parent        
    SSID              : Tsunami
    VLAN              : 0
    Hops to Infra     : 0                  Association Id   : 44
    Tunnel Address    : 0.0.0.0
    Key Mgmt type     : WPA PSK            Encryption       : TKIP
    Current Rate      : 54.0               Capability       : WMM ShortHdr ShortSlot
    Supported Rates   : 1.0 2.0 5.5 6.0 9.0 11.0 12.0 18.0 24.0 36.0 48.0 54.0
    Voice Rates       : disabled
    Signal Strength   : -51  dBm           Connected for    : 75169 seconds
    Signal to Noise   : 26  dB            Activity Timeout : 14 seconds
    Power-save        : Off                Last Activity    : 1 seconds ago
    Apsd DE AC(s)     : NONE
    Packets Input     : 1050695            Packets Output   : 296536   
    Bytes Input       : 474651248          Bytes Output     : 96734573 
    Duplicates Rcvd   : 0                  Data Retries     : 63646    
    Decrypt Failed    : 0                  RTS Retries      : 0        
    MIC Failed        : 0                  MIC Missing      : 0        
    Packets Redirected: 0                  Redirect Filtered: 0
    Here is a config snippet from the AP non-root bridge with wireless clients:
    dot11 ssid Tsunami
       authentication open
       authentication key-management wpa
       guest-mode
       infrastructure-ssid optional
       wpa-psk ascii 7 (snipped)
    bridge irb
    interface Dot11Radio0
    no ip address
    no ip route-cache
    encryption mode ciphers tkip
    ssid Tsunami
    speed basic-1.0 2.0 5.5 6.0 9.0 11.0 12.0 18.0 24.0 36.0 48.0 54.0
    station-role non-root bridge wireless-clients
    bridge-group 1
    bridge-group 1 subscriber-loop-control
    bridge-group 1 spanning-disabled
    interface FastEthernet0
    no ip address
    no ip route-cache
    duplex auto
    speed auto
    bridge-group 1
    bridge-group 1 spanning-disabled
    interface BVI1
    ip address dhcp client-id FastEthernet0
    no ip route-cache
    bridge 1 route ip
    (The AP root-bridge with wireless clients config is identical to this config with the exception of the station-role and a static IP on the BVI1 interface.)
    Are these very slow thoughput speeds normal of this hardware combination?
    I did much searching/googling and found claims that by eliminating TKIP it almost doubles the actual wireless speeds our clients can obtain. Is there any truth to this?
    Any suggestions or recommendations without changing hardware would be very welcome.
    Thanks in Advance!
    D.
    =============

    Ok, thanks for the explanation - I understand. But even at a 22mbps signaling rate shouldn't I be seeing throughputs greater than 5-5.5mbps especially since this location is literally 100% free of any outside interference and the interfaces definitely show the clients and non-root bridge (when connected) all being at the highest rate of 54mbps? I tried even in the same room, approximately 40' away, total line of sight, no obstructions, between my laptop and the root AP.
    I disconnected the non-root bridge and connected directly to the root bridge during my testing. I was still only able to achieve approx 5.5mbps download. Adding back in the non-root bridge and re-connecting to it I notice slightly lower throughput, approx 5mbps. During testing, my laptop was the only device connected to the network, all other clients were shut off.
    Here are the int stats (I've never reset the counters):
    Root Bridge:
    RATE 1.0 Mbps
    Rx Packets:           2178725 /  49    Tx Packets:                   39 /   0
    Rx Bytes:            335124036 /7595    Tx Bytes:                   4965 /   0
    RTS Retries:               61 /   0    Data Retries:                  5 /   0
    Non-Root-Bridge:
    RATE 1.0 Mbps
    Rx Packets:           2323120 /  50    Tx Packets:                  141 /   0
    Rx Bytes:            336455923 /7595    Tx Bytes:                  17869 /   0
    RTS Retries:                2 /   0    Data Retries:                 56 /   0
    All the other rates, 2-12mbps show single or double digit packet/byte counts until I get to the 36mbps section of each interface:
    ap#sh int Dot11Radio0 stati
            DOT11 Statistics        (Cumulative Total/Last 5 Seconds):
    (snipped for brevity)
    Root Bridge:
    RATE 36.0 Mbps
    Rx Packets:            915395 /   1    Tx Packets:              2345589 /   9
    Rx Bytes:            93420936 /  70    Tx Bytes:             3370791285 / 874
    RTS Retries:                0 /   0    Data Retries:             573981 /   4
    RATE 48.0 Mbps
    Rx Packets:           2163192 /   2    Tx Packets:               216861 /   0
    Rx Bytes:            222455730 / 404    Tx Bytes:              182817967 /   0
    RTS Retries:                0 /   0    Data Retries:             106808 /   0
    RATE 54.0 Mbps
    Rx Packets:            987986 /   0    Tx Packets:               168923 /   0
    Rx Bytes:            190467269 /   0    Tx Bytes:               61665042 /   0
    RTS Retries:                0 /   0    Data Retries:              34424 /   0
    Non-Root Bridge:
    RATE 36.0 Mbps
    Rx Packets:           2368679 /   0    Tx Packets:               965419 /   0
    Rx Bytes:            3396819830 /   0    Tx Bytes:               90880825 /   0
    RTS Retries:                0 /   0    Data Retries:             242686 /   0
    RATE 48.0 Mbps
    Rx Packets:            341870 /   0    Tx Packets:              2156282 /   1
    Rx Bytes:            216497093 /   0    Tx Bytes:              215775536 / 210
    RTS Retries:                0 /   0    Data Retries:             478619 /   0
    RATE 54.0 Mbps
    Rx Packets:           1469926 /  15    Tx Packets:              2529678 /  15
    Rx Bytes:            411722698 /1122    Tx Bytes:             1366306113 /5159
    RTS Retries:                0 /   0    Data Retries:             198532 /   0
    I will try disabling the rates below 12mbps and re-test.
    I would like to try disabling all encryption and try as well.
    Do you know if the AP's will associate if there is zero encryption?

  • Speeding up FileIO - Double Buffered File Copy?

    We are trying to speed up file copy from disk to tape, and I need a little more speed. I have tried playing with the size of the buffer, but that isn't changing much (makeing it slower if anything).
    I'm trying to make a double buffered file copy and I can't figure out how to do it. I figured this would be a good place to get speed. Right now, my write is very simple:
    byte buffer = new buffer[8 * 1024 * 1024];
    FileInputStream in = new FileInputStream(srcFile);
    while(true) {
      int amountRead = in.read(buffer);
      if (amountRead == -1) { break; }
      write(buffer, 0, length);
    }So what i need to do it be able to read and write at the same time. So I was thinking that I could either make the write method a sperate thread, or some how make threaded buffers that read while the other is being writen. Has anyone tackled this problem before?
    If this isn't the right way to speed up File IO, can you let me know other ideas? Thanks in advance!
    Andrew

    Once again: I wish I could claim credit for these classes, but they were in fact posted a year or so ago by someone lese. If I had the name I would give credit.
    I've used these for two heavy-duty applications with never a problem.
    <code>
    package pipes;
    import java.io.IOException;
    import java.io.InputStream;
    * This class is equivalent to <code>java.io.PipedInputStream</code>. In the
    * interface it only adds a constructor which allows for specifying the buffer
    * size. Its implementation, however, is much simpler and a lot more efficient
    * than its equivalent. It doesn't rely on polling. Instead it uses proper
    * synchronization with its counterpart PipedOutputStream.
    * Multiple readers can read from this stream concurrently. The block asked for
    * by a reader is delivered completely, or until the end of the stream if less
    * is available. Other readers can't come in between.
    public class PipedInputStream extends InputStream {
    byte[] buffer;
    boolean closed = false;
    int readLaps = 0;
    int readPosition = 0;
    PipedOutputStream source;
    int writeLaps = 0;
    int writePosition = 0;
    * Creates an unconnected PipedInputStream with a default buffer size.
    * @exception IOException
    public PipedInputStream() throws IOException {
    this(null);
    * Creates a PipedInputStream with a default buffer size and connects it to
    * source.
    * @exception IOException It was already connected.
    public PipedInputStream(PipedOutputStream source) throws IOException {
    this(source, 0x10000);
    * Creates a PipedInputStream with buffer size <code>bufferSize</code> and
    * connects it to <code>source</code>.
    * @exception IOException It was already connected.
    public PipedInputStream(PipedOutputStream source, int bufferSize) throws IOException {
    if (source != null) {
    connect(source);
    buffer = new byte[bufferSize];
    * Return the number of bytes of data available from this stream without blocking.
    public int available() throws IOException {
    // The circular buffer is inspected to see where the reader and the writer
    // are located.
    return writePosition > readPosition ? // The writer is in the same lap.
    writePosition - readPosition : (writePosition < readPosition ? // The writer is in the next lap.
    buffer.length - readPosition + 1 + writePosition :
    // The writer is at the same position or a complete lap ahead.
    (writeLaps > readLaps ? buffer.length : 0)
    * Closes the pipe.
    * @exception IOException The pipe is not connected.
    public void close() throws IOException {
    if (source == null) {
    throw new IOException("Unconnected pipe");
    synchronized (buffer) {
    closed = true;
    // Release any pending writers.
    buffer.notifyAll();
    * Connects this input stream to an output stream.
    * @exception IOException The pipe is already connected.
    public void connect(PipedOutputStream source) throws IOException {
    if (this.source != null) {
    throw new IOException("Pipe already connected");
    this.source = source;
    source.sink = this;
    * Closes the input stream if it is open.
    protected void finalize() throws Throwable {
    close();
    * Unsupported - does nothing.
    public void mark(int readLimit) {
    return;
    * returns whether or not mark is supported.
    public boolean markSupported() {
    return false;
    * reads a byte of data from the input stream.
    * @return the byte read, or -1 if end-of-stream was reached.
    public int read() throws IOException {
    byte[] b = new byte[0];
    int result = read(b);
    return result == -1 ? -1 : b[0];
    * Reads data from the input stream into a buffer.
    * @exception IOException
    public int read(byte[] b) throws IOException {
    return read(b, 0, b.length);
    * Reads data from the input stream into a buffer, starting at the specified offset,
    * and for the length requested.
    * @exception IOException The pipe is not connected.
    public int read(byte[] b, int off, int len) throws IOException {
    if (source == null) {
    throw new IOException("Unconnected pipe");
    synchronized (buffer) {
    if (writePosition == readPosition && writeLaps == readLaps) {
    if (closed) {
    return -1;
    // Wait for any writer to put something in the circular buffer.
    try {
    buffer.wait();
    catch (InterruptedException e) {
    throw new IOException(e.getMessage());
    // Try again.
    return read(b, off, len);
    // Don't read more than the capacity indicated by len or what's available
    // in the circular buffer.
    int amount = Math.min(len,
    (writePosition > readPosition ? writePosition : buffer.length) - readPosition);
    System.arraycopy(buffer, readPosition, b, off, amount);
    readPosition += amount;
    if (readPosition == buffer.length) {
    // A lap was completed, so go back.
    readPosition = 0;
    ++readLaps;
    // The buffer is only released when the complete desired block was
    // obtained.
    if (amount < len) {
    int second = read(b, off + amount, len - amount);
    return second == -1 ? amount : amount + second;
    } else {
    buffer.notifyAll();
    return amount;
    package pipes;
    import java.io.IOException;
    import java.io.OutputStream;
    * This class is equivalent to java.io.PipedOutputStream. In the
    * interface it only adds a constructor which allows for specifying the buffer
    * size. Its implementation, however, is much simpler and a lot more efficient
    * than its equivalent. It doesn't rely on polling. Instead it uses proper
    * synchronization with its counterpart PipedInputStream.
    * Multiple writers can write in this stream concurrently. The block written
    * by a writer is put in completely. Other writers can't come in between.
    public class PipedOutputStream extends OutputStream {
    PipedInputStream sink;
    * Creates an unconnected PipedOutputStream.
    * @exception IOException
    public PipedOutputStream() throws IOException {
    this(null);
    * Creates a PipedOutputStream with a default buffer size and connects it to
    * <code>sink</code>.
    * @exception IOException It was already connected.
    public PipedOutputStream(PipedInputStream sink) throws IOException {
    this(sink, 0x10000);
    * Creates a PipedOutputStream with buffer size <code>bufferSize</code> and
    * connects it to <code>sink</code>.
    * @exception IOException It was already connected.
    public PipedOutputStream(PipedInputStream sink, int bufferSize) throws IOException {
    if (sink != null) {
    connect(sink);
    sink.buffer = new byte[bufferSize];
    * Closes the input stream.
    * @exception IOException The pipe is not connected.
    public void close() throws IOException {
    if (sink == null) {
    throw new IOException("Unconnected pipe");
    synchronized (sink.buffer) {
    sink.closed = true;
    flush();
    * Connects the output stream to an input stream.
    * @exception IOException The pipe is already connected.
    public void connect(PipedInputStream sink) throws IOException {
    if (this.sink != null) {
    throw new IOException("Pipe already connected");
    this.sink = sink;
    sink.source = this;
    * Closes the output stream if it is open.
    protected void finalize() throws Throwable {
    close();
    * forces any buffered data to be written.
    * @exception IOException
    public void flush() throws IOException {
    synchronized (sink.buffer) {
    // Release all readers.
    sink.buffer.notifyAll();
    * writes a byte of data to the output stream.
    * @exception IOException
    public void write(int b) throws IOException {
    write(new byte[] {(byte) b});
    * Writes a buffer of data to the output stream.
    * @exception IOException
    public void write(byte[] b) throws IOException {
    write(b, 0, b.length);
    * writes data to the output stream from a buffer, starting at the named offset,
    * and for the named length.
    * @exception IOException The pipe is not connected or a reader has closed
    * it.
    public void write(byte[] b, int off, int len) throws IOException {
    if (sink == null) {
    throw new IOException("Unconnected pipe");
    if (sink.closed) {
    throw new IOException("Broken pipe");
    synchronized (sink.buffer) {
         if (sink.writePosition == sink.readPosition &&
         sink.writeLaps > sink.readLaps) {
         // The circular buffer is full, so wait for some reader to consume
         // something.
         try {
         sink.buffer.wait();
         catch (InterruptedException e) {
         throw new IOException(e.getMessage());
         // Try again.
         write(b, off, len);
         return;
         // Don't write more than the capacity indicated by len or the space
         // available in the circular buffer.
         int amount = Math.min(len,
         (sink.writePosition < sink.readPosition ?
         sink.readPosition : sink.buffer.length)
    - sink.writePosition);
         System.arraycopy(b, off, sink.buffer, sink.writePosition, amount);
         sink.writePosition += amount;
         if (sink.writePosition == sink.buffer.length) {
         sink.writePosition = 0;
         ++sink.writeLaps;
         // The buffer is only released when the complete desired block was
         // written.
         if (amount < len) {
         write(b, off + amount, len - amount);
         } else {
         sink.buffer.notifyAll();
    </code>

  • Fine Tuning Java 1.1 Double Buffering?

    Dear Java gurus,
    Hi, I'm looking for suggestions on improving the performance of my double buffering technique for pure Java 1.1 applets.
    My current method seems to eat up more CPU & RAM than it should. I fear that real implementations (with far more drawing to the buffer before update), would be impractically slow and choke using double buffering the way I am now.
    I have programmed a simple applet demonstrating my current method (code below), which runs at 20 fps. I tried to keep it short and sweet.
    I'm only looking for pure Java 1.1 code.
    Thanks in advance. =)
    import java.awt.*;
    import java.applet.*;
    public class ColourFader extends Applet implements Runnable {
    // Class Variables
         int appletWidth = 600;
         int appletHeight = 300;
         int fps = 20;
         int delay = 1000 / fps;
         int nextRGB [] = {255, 0, 255};
         int currRGB [] = {0, 255, 0};
    // Class Objects
         Image offImage;
         Graphics offGraphics;
         Thread animator;
    // Applet Methods          
         public void start() {
              animator = new Thread(this);
              animator.start();
              offImage = createImage(appletWidth, appletHeight);
              offGraphics = offImage.getGraphics();
         public void stop() {
              animator = null;
              offImage = null;
              offGraphics = null;
         public void paint(Graphics g) {
              g.drawImage(offImage, 0, 0, null);
              update(g);
    // Runnable Method
         public void run() {
              while(Thread.currentThread() == animator) {
                   long tm = System.currentTimeMillis();
                   repaint();
                   try {
                        tm += delay;
                        Thread.sleep(Math.max(0, tm - System.currentTimeMillis()));
                   } catch (InterruptedException e) {
                        break;
    // Convenience Methods
         public void update(Graphics g) {
              fadeRGBValues();
              paintFrame(offGraphics);
              g.drawImage(offImage, 0, 0, null);
         public void paintFrame(Graphics g) {
              g.setColor(new Color(currRGB[0], currRGB[1], currRGB[2]));
              g.fillRect(0, 0, appletWidth, appletHeight);          
         public void fadeRGBValues() {
              for(int i = 0; i <= 2; i++) {
                   if(currRGB[i] < nextRGB) {
                        currRGB[i] += 1;
                   } else if (currRGB[i] > nextRGB[i]) {
                        currRGB[i] -= 1;
                   } else {
                        nextRGB[i] = randomNum();
         public int randomNum() {
              double randomDouble = Math.random() * 255.0;
              int randomInt = (int) randomDouble;
              return(randomInt);

    Usually first update is called, then paint. In your paint method you call update, I don't see any reason for that. You want your paint method to be fast, so I would remove the update call.
    Instead I would call paint from the update method. Update is not needed to be called as often as the paint method. I think I would make the update method do nothing (just call the paint method). Then I would make another method I could call when I need to make some updates, and which did not take any graphics object as argument, becuase you dont need it.
    So something like this:
    public void update(Graphics g) {
      paint(g);
    public void paint(Graphics g) {
      g.drawImage(offImage, 0, 0, null);
    public void update() {
      fadeRGBValues();
      paintFrame(offGraphics); 
    }Then in your run method, just before repaint(), I would call update().
    Thread.sleep(0) would sleep forever I think. So be careful with that. A better way to do it:
    public void run() {
      long start = System.currentTimeMillis();
      int count = 0;
      while (Thread.currentThread() == animator) {
        update();
        repaint();
        count++;
        long sleep = count*delay-(System.currentTimeMillis()-start);
        if (sleep > 0) {
          try {
            Thread.sleep(sleep);
          } catch (InterruptedException e) {
            break;
    }

  • Speed of Swing versus double buffered AWT

    Hello
    I've noticed that drawing in a JPanel.paintComponent() takes about 4 times longer than drawing into an offscreen image in AWT Canvas.paint()
    Essential code excerpts follow
    // SWING, takes about 400 millis on my machine
    public void paintComponent(Graphics g) {
    g.setColor(Color.red);
    long startTime = System.currentTimeMillis();
    for (int i = 0; i < 10000; i++)
    g.draw3DRect((int) (Math.random() * 200), 20, 30, 40, true);
    long endTime = System.currentTimeMillis();
    System.out.println("paintComponent() took " + (endTime - startTime) + " millis");
    // AWT, takes about 100 millis on same machine
    public void paint(Graphics g) {
    if (offscreenGraphics == null || offscreenImage == null) {
    offscreenImage = createImage(getWidth(), getHeight());
    offscreenGraphics = offscreenImage.getGraphics();
    long startTime = System.currentTimeMillis();
    if (offscreenGraphics != null) {
    offscreenGraphics.setColor(Color.red);
    for (int i = 0; i < 10000; i++)
    offscreenGraphics.draw3DRect((int) (Math.random() * 200), 20, 30, 40, true);
    g.drawImage(offscreenImage, 0, 0, this);
    long endTime = System.currentTimeMillis();
    System.out.println("paint() took " + (endTime - startTime) + " millis");
    Note that I also tried drawLine() instead of draw3DRect() and experienced similar results
    Can someone explain why doing this in Swing is so slow?
    I'd hoped to take advantage of Swing's double buffering, but I ended up using the same old offscreen image technique in Swing.
    Nick Didkovsky

    Silly question, but did you turn on double buffering or extend a Swing component which has it on by default?
    Not all of them do.
    : jay

  • Problem with Double Buffering and Swing

    Hi
    I made a game and basically it works pretty well, my only problem is it flickers really badly right now. I read up on a whole lot of forums about double buffering and none of those methods seemed to work. Then I noticed that Swing has double buffering built in so I tried that but then I get compilation errors and I'm really not sure why. My original code was a console application and worked perfectly, then I ported it into a JApplet and it still works but it flickers and thats what I'm tryign to fix now.
    The code below is in my main class under the constructor.
    Heres the double buffering code I'm trying to use, I'm sure you all seen it before lol
    public void update(Graphics g)
              // initialize buffer
              if (dbImage == null)
                   dbImage = createImage(this.getSize().width, this.getSize().height);
                   dbg = dbImage.getGraphics();
              // clear screen in background
              dbg.setColor(getBackground());
              dbg.fillRect(0, 0, this.getSize().width, this.getSize().height);
              // draw elements in background
              dbg.setColor(getForeground());
              paint(dbg);
              // draw image on the screen
              g.drawImage(dbImage, 0, 0, this);
         }My paint is right under neath and heres how it looks
    This snipet of code works but when I change the method to
    public paintComponent(Graphics g){
    super.paintComponent(g)...
    everythign stops working and get a compilation error and says that it can't find paintComponent in javax.swing.JFrame.
    public void paint(Graphics g)
              super.paint(g);
              //if game starting display menue
              if (show_menue)
                   //to restart lives if player dies
                   lives = 3;
                   menue.draw_menue(g);
                   menue_ufo1.draw_shape(g);
                   menue_ufo2.shape_color = Color.DARK_GRAY;
                   menue_ufo2.draw_shape(g);
                   menue_ufo3.shape_color = Color.BLUE;
                   menue_ufo3.draw_shape(g);
                   menue_ufo4.shape_color = new Color(82, 157, 22);
                   menue_ufo4.draw_shape(g);
                   menue_ufo5.draw_shape(g);
                   menue_ufo6.shape_color = new Color(130, 3, 3); ;
                   menue_ufo6.draw_shape(g);
                   menue_turret.draw_ship(g);
                   menue_ammo.draw_ammo(g);
              else
                   //otherwise redraw game objects
                   gunner.draw_ship(g);
                   y_ammo.draw_ammo(g);
                   grass.draw_bar(g);
                   o_ufo.draw_shape(g);
                   b_ufo.draw_shape(g);
                   m_ufo.draw_shape(g);
                   s_ufo.draw_shape(g);
                   z_ufo.draw_shape(g);
                   xx_ufo.draw_shape(g);
                   info.draw_bar(g);
                   live_painter.draw_lives(g, lives);
                   score_painter.draw_score(g, score);
                   level_display.draw_level(g, level);
                   explosion.draw_boom(g);
         }I just want to get rid of the flickering for now so any help will be greatly appreciated. Depending which will be simpler I can either try to double buffer this program or port it all to swing but I'm not sure which elements are effected by AWT and which by Swing. Also I read some of the Java documentation but couldn't really understand how to implement it to fix my program.
    Thanks in advance
    Sebastian

    This is a simple animation example quickly thrown together. I have two classes, an animation panel which is a JPanel subclass that overrides paintComponent and draws the animation, and a JApplet subclass that simply holds the animation panel in the applet's contentpane:
    SimpleAnimationPanel.java
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Point;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.image.BufferedImage;
    import java.io.IOException;
    import java.net.MalformedURLException;
    import java.net.URL;
    import javax.imageio.ImageIO;
    import javax.swing.JPanel;
    import javax.swing.Timer;
    class SimpleAnimationPanel extends JPanel
        private static final int DELAY = 20;
        public static final int X_TRANSLATION = 2;
        public static final int Y_TRANSLATION = 2;
        private Point point = new Point(5, 32);
        private BufferedImage duke = null;
        private Timer timer = new Timer(DELAY, new TimerAction());
        public SimpleAnimationPanel()
            try
                // borrow an image from sun.com
                duke = ImageIO.read(new URL(
                        "http://java.sun.com/products/plugin/images/duke.wave.med.gif"));
            catch (MalformedURLException e)
                e.printStackTrace();
            catch (IOException e)
                e.printStackTrace();
            setPreferredSize(new Dimension(600, 400));
            timer.start();
        // do our drawing here in the paintComponent override
        @Override
        protected void paintComponent(Graphics g)
            super.paintComponent(g);
            if (duke != null)
                g.drawImage(duke, point.x, point.y, this);
        private class TimerAction implements ActionListener
            @Override
            public void actionPerformed(ActionEvent e)
                int x = point.x;
                int y = point.y;
                Dimension size = SimpleAnimationPanel.this.getSize();
                if (x > size.width)
                    x = 0;
                else
                    x += X_TRANSLATION;
                if (y > size.height)
                    y = 0;
                else
                    y += Y_TRANSLATION;
                point.setLocation(new Point(x, y)); // update the point
                SimpleAnimationPanel.this.repaint();
    }AnimationApplet.java
    import java.lang.reflect.InvocationTargetException;
    import javax.swing.JApplet;
    import javax.swing.JPanel;
    import javax.swing.SwingUtilities;
    public class AnimationApplet extends JApplet
        public void init()
            try
                SwingUtilities.invokeAndWait(new Runnable()
                    public void run()
                        // construct the panel
                        JPanel simpleAnimation = new SimpleAnimationPanel();
                        // put it in the contentPane of the JApplet
                        getContentPane().add(simpleAnimation);
                        setSize(simpleAnimation.getPreferredSize());
            catch (InterruptedException e)
                e.printStackTrace();
            catch (InvocationTargetException e)
                e.printStackTrace();
    }Here's a 3rd bonus class that shows how to put the JPanel into a stand-alone program, a JFrame. It's very similar to doing it in the JApplet:
    AnimationFrame.java
    import javax.swing.JFrame;
    public class AnimationFrame
        private static void createAndShowUI()
            JFrame frame = new JFrame("SimpleAnimationPanel");
            frame.getContentPane().add(new SimpleAnimationPanel());
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        public static void main(String[] args)
            java.awt.EventQueue.invokeLater(new Runnable()
                public void run()
                    createAndShowUI();
    }Edited by: Encephalopathic on Mar 15, 2008 11:01 PM

  • Alternative to Double-Buffered Canvas

    I am working on a program in which I use a double-buffered Canvas inside a JScrollPane. The problem is that the Canvas draws over the scrollbars. I have tried extending JComponent, JPanel, JApplet, and Component instead of Canvas, and none of them are double buffered. Here is the code I used to debug this problem:
    import java.awt.*;
    import java.awt.geom.*;
    import java.awt.image.*;
    import javax.swing.*;
    public class Test implements  Runnable
         JFrame f;
         JScrollPane scroller;
         JPanel panel;
         TestCanvas canvas;
         Thread runner;
         BufferStrategy strategy;
         public static void main (String[] args) {
              Test app = new Test();
              app.init();
         public void init() {
              f = new JFrame();
              f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              panel = new JPanel();
              canvas = new TestCanvas();
              panel.add(canvas);
              scroller = new JScrollPane(panel);
              scroller.setWheelScrollingEnabled(true);
              f.getContentPane().add(scroller);
              f.pack();
              f.setSize(300,300);
              f.setVisible(true);
              canvas.createBufferStrategy(2);
              strategy = canvas.getBufferStrategy();
              runner = new Thread(this);
              runner.run();
         public void run() {
              int x = 0;
              while(x != 65536) {
                   Graphics2D g = (Graphics2D)strategy.getDrawGraphics().create();
                   g.setColor(new Color(x%256,0,0));
                   g.fill(new Ellipse2D.Double(0,0,600,600));
                   strategy.show();
                   x++;
    }Any suggestions?

    The main culprit is that you are mixing AWT components with Swing ones.
    In addition, your are doing so many of useless things and wrong things in your code.
    Swing components are defaulted for using double-buffering.
    See: http://java.sun.com/products/jfc/tsc/articles/painting/index.html
    Try and study this code.
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.awt.image.*;
    import javax.swing.*;
    public class Fox1229{
      JFrame f;
      JScrollPane scroller;
      TestCanvas canvas;
      int x;
      Timer t;
      public static void main (String[] args) {
        Fox1229 app = new Fox1229();
        app.init();
      public void init() {
        x = 0;
        f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        canvas = new TestCanvas();
        scroller = new JScrollPane(canvas);
        scroller.setWheelScrollingEnabled(true);
        f.getContentPane().add(scroller, BorderLayout.CENTER);
        f.setSize(300, 300);
        f.setVisible(true);
        t = new Timer(50, new ActionListener(){
          public void actionPerformed(ActionEvent e){
            canvas.setOc(new Color(x % 256, 0, 0));
            canvas.repaint();
            if (++x == 1024){
              t.stop();
        t.start();
    class TestCanvas extends JPanel{
      Color oc;
      public TestCanvas (){
        oc = new Color(0, 0, 0);
      public void setOc(Color c){
        oc = c;
      public Dimension getPreferredSize(){
        return new Dimension(600, 600);
      public void paintComponent(Graphics g){
        super.paintComponent(g);
        Graphics2D g2d = (Graphics2D)g;
        g2d.setColor(Color.blue);
        g2d.fill(new Rectangle(0, 0, 600, 600));
        g2d.setColor(oc);
        g2d.fill(new Ellipse2D.Double(0, 0, 600, 600));
    }

  • Double buffering

    I was searching through posts to find an answer to my problem of getting double buffering working without flickering when I came across this response:
    Upgrade your SDK, early 1.4 implementations had this problem on Windows2k (It's a bug). Pretty much the second buffer will point to an empty portion of video memory always, the solution to this without updating is to fill the entire backbuffer completely, flip it, fill it again, and then flip it again. You should then be able to use it normaly.
    -Jason Thomas.
    Since I am on dialup I can't really download the SDK, so could someone give me some code to do what Jason has suggested?
    Jonathan O'Brien

    No I am not recreating the bufferstrategy every frame. Overriding update didn't work either. Here is my code for main:
              GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
              GraphicsDevice device = env.getDefaultScreenDevice();
              GraphicsConfiguration gc = device.getDefaultConfiguration();
              Frame myFrame = new Frame(gc);
    BufferCapabilities bufferCaps = gc.getBufferCapabilities();
              boolean multiBuffer = bufferCaps.isMultiBufferAvailable();
              boolean fullScreen = device.isFullScreenSupported();
              System.out.println("Full screen supported = " + fullScreen);
              System.out.println("Multi buffer available = " + multiBuffer);
              System.out.println("Page flipping = " + bufferCaps.isPageFlipping());
              myFrame.setUndecorated(true);
              myFrame.setIgnoreRepaint(true);
              if ((fullScreen) && (multiBuffer))
                   device.setFullScreenWindow(myFrame);
                   device.setDisplayMode(new DisplayMode(800, 600, 16, 0));
                   rectBounds = myFrame.getBounds();
                   myFrame.createBufferStrategy(2);
                   bufferStrategy = myFrame.getBufferStrategy();
                   bufferReady = true;
              Game thisGame = new Game(args[0]);
              myFrame.add(thisGame);
    //          myFrame.getContentPane().add(thisGame);
              myFrame.show();
    And here is the relevant code for my run method:
              if (bufferReady)
                   Graphics g = bufferStrategy.getDrawGraphics();
                   if (!bufferStrategy.contentsLost()) {
                        g.fillRect(0,0,getWidth(),getHeight());
                        g.dispose();
                        bufferStrategy.show();

  • Double buffering still gives flickering graphics.

    I copied code from a tutorail which is supposed to illustrate double buffering.
    After I run it, it still flickers though.
    I use applet viewer, which is part of netbeans to run my applet.
    Link to tutorial: http://www.javacooperation.gmxhome.de/TutorialStartEng.html
    My questions are:
    Is the strategy used for double buffering correct?
    Why does it flicker?
    Why does the program change the priority a couple of times?
    Can you make fast games in JApplets or is there a better way to make games? (I think C++ is too hard)
    Here is the code:
    package ballspel;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Image;
    import javax.swing.JApplet;
    //import java.applet.*;
    * @author Somelauw
    public class BallApplet extends /*Applet*/ JApplet implements Runnable {
    private Image dbImage;
    private Graphics dbg;
    private int radius = 20;
    private int xPos = 10;
    private int yPos = 100;
    * Initialization method that will be called after the applet is loaded
    * into the browser.
    @Override
    public void init() {
    //System.out.println(this.isDoubleBuffered()); //returns false
    // Isn't there a builtin way to force double buffering?
    // TODO start asynchronous download of heavy resources
    @Override
    public void start() {
    Thread th = new Thread(this);
    th.start();
    public void run() {
    Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
    while (true) {
    xPos++;
    repaint();
    try {
    Thread.sleep(20);
    } catch (InterruptedException ex) {
    ex.printStackTrace();
    Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
    @Override
    public void paint(Graphics g) {
    super.paint(g);
    //g.clear();//, yPos, WIDTH, WIDTH)
    g.setColor(Color.red);
    g.fillOval(xPos - radius, yPos - radius, 2 * radius, 2 * radius);
    @Override
    public void update(Graphics g) {
    super.update(g);
    // initialize buffer
    if (dbImage == null) {
    dbImage = createImage(this.getSize().width, this.getSize().height);
    dbg = dbImage.getGraphics();
    // clear screen in background
    dbg.setColor(getBackground());
    dbg.fillRect(0, 0, this.getSize().width, this.getSize().height);
    // draw elements in background
    dbg.setColor(getForeground());
    paint(dbg);
    // draw image on the screen
    g.drawImage(dbImage, 0, 0, this);
    // TODO overwrite start(), stop() and destroy() methods
    }

    Somelauw wrote:
    I copied code from a tutorail which is supposed to illustrate double buffering.
    After I run it, it still flickers though.
    I use applet viewer, which is part of netbeans.. AppletViewer is part of the JDK, not NetBeans.
    ..to run my applet.
    Link to tutorial: http://www.javacooperation.gmxhome.de/TutorialStartEng.html
    Did you specifically mean the code mentioned on this page?
    [http://www.javacooperation.gmxhome.de/BildschirmflackernEng.html]
    Don't expect people to go hunting around the site, looking for the code you happen to be referring to.
    As an aside, please use the code tags when posting code, code snippets, XML/HTML or input/output. The code tags help retain the formatting and indentation of the sample. To use the code tags, select the sample and click the CODE button.
    Here is the code you posted, as it appears in code tags.
    package ballspel;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Image;
    import javax.swing.JApplet;
    //import java.applet.*;
    * @author Somelauw
    public class BallApplet extends /*Applet*/ JApplet implements Runnable {
        private Image dbImage;
        private Graphics dbg;
        private int radius = 20;
        private int xPos = 10;
        private int yPos = 100;
         * Initialization method that will be called after the applet is loaded
         * into the browser.
        @Override
        public void init() {
            //System.out.println(this.isDoubleBuffered()); //returns false
            // Isn't there a builtin way to force double buffering?
            // TODO start asynchronous download of heavy resources
        @Override
        public void start() {
            Thread th = new Thread(this);
            th.start();
        public void run() {
            Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
            while (true) {
                xPos++;
                repaint();
                try {
                    Thread.sleep(20);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
        @Override
        public void paint(Graphics g) {
            super.paint(g);
            //g.clear();//, yPos, WIDTH, WIDTH)
            g.setColor(Color.red);
            g.fillOval(xPos - radius, yPos - radius, 2 * radius, 2 * radius);
        @Override
        public void update(Graphics g) {
            super.update(g);
            // initialize buffer
            if (dbImage == null) {
                dbImage = createImage(this.getSize().width, this.getSize().height);
                dbg = dbImage.getGraphics();
            // clear screen in background
            dbg.setColor(getBackground());
            dbg.fillRect(0, 0, this.getSize().width, this.getSize().height);
            // draw elements in background
            dbg.setColor(getForeground());
            paint(dbg);
            // draw image on the screen
            g.drawImage(dbImage, 0, 0, this);
        // TODO overwrite start(), stop() and destroy() methods
    }Edit 1:
    - For animation code, it would be typical to use a javax.swing.Timer for triggering updates, rather than implementing Runnable (etc.)
    - Attempting to set the thread priority will throw a SecurityException, though oddly it occurs when attempting to set the Thread priority to maximum, whereas the earlier call to set the Thread priority to minimum passed without comment (exception).
    - The paint() method of that applet is not double buffered.
    - It is generally advisable to override paintComponent(Graphics) in a JPanel that is added to the top-level applet (or JFrame, or JWindow, or JDialog..) rather than the paint(Graphics) method of the top-level container itself.
    Edited by: AndrewThompson64 on Jan 22, 2010 12:47 PM

  • Double buffering images

    HELP!!! lol i'm trying to figure out how to get the whole double buffering thing to work with a picture like a gif image i drew in paint. i can't quite understand anything aobut how to do it. lol i've read some things and looked at some code samples but they all do it with a polygon. i just can't seem to get it right. i learn best from code snipets if that helps. don't give me a whole program i just want some lines that will help me learn it like what i have to import. and other things. i know a little about using images but not a whole lot. if anyone can help it will be appreciated.
    andy

    Psst... Tell you teacher that one can read an image with ImageIO, often in one line:
    BufferedImage image = ImageIO.read(file_or_url_or_inputstream);(No need for a MediaTracker!) And the resulting BufferedImage (a subclass of Image)
    is easier to work with than Image and has more useful features.
    Welcome to Java 2D.

  • Double buffering circle not round anymore

    I am making an applet where some circles are painted to the screen. When not using the double buffering scenario, the shapes appear correctly.
    The problem is when i use the double-buffering technique, the circles are still there, but they look like very ugly. I would call that some "squarcles".
    What is the bug here and how to get some decent double buffering with thoses circles?

    Ok, i had some problem with the running thread when closing the applet viewer, but now this situation is corrected by setting the animation thread to null before calling stop().
    Maybe explanation of the problem is not clear, so i made two versions of the same applet with only 2 lines of code different so that there is one applet that is not double buffered.
    You can check these by yourself at this place:
    Double buffered circles: http://www.geocities.com/xeneve/cooltrail/ demo_cooltrail.htm
    No double buffer:
    http://www.geocities.com/xeneve/cooltrail/demo_cooltrail_ndb.htm
    This is just annoying to get this result. I realise that maybe not many peoples are coding applets so i guess there is few people that may have a workaround for this.

Maybe you are looking for

  • I have just updated to iOS 5.1 for iphone 4s. I have problem sending sms or make call. Can anyone please help

    I just updated my iPhone 4s to iOS 5.1. Since the update, I am not able to make calls or send sms. I reset network settings several times but not luck. I have also turned off data and 3G but no luck. Could anyone please help me? Right now, my iPhone

  • Regarding BDC's, BAPI's, ALE ,IDOCs, BADI's

    Hi all, can any one send materials with screen shots having example programs for BDC's, BAPI's, ALE ,IDOCs, BADI's to my mail id <b><REMOVED BY MODERATOR></b> regards and thanks venu Message was edited by:         Alvaro Tejada Galindo

  • Clip resolution vs Final Cut Resolution?

    I'm using an older version of Final Cut Express (came with the computer when I got it, Dual G4 867Mhz) to try to edit and add a sound track to some video captures I've made using FRAPS on my PC. Fraps natively uses a raw DV format that seems to be so

  • WRT54G IP Address conflict...

    After 3 sessions with Linksys live chat I have done everything suggested and nothing has worked. Here is the situation: the router(WRT54G v.3 firmware 4.21.1) is working. I can connect to the internet through the router with my notebook(Windows XP Ho

  • Why have all last years events disappeared from my calendar

    I Use tha calendar all the time on my iPad but when I have gone back to before Dec 2012 most of the entries I had in there have gone, birthdays are still there and most Tuesday events that are constant through the year but the rest have vanished.