Hi,

I wonder do I have Java-Linux problem or it is my fault. I run
JDK1.2.2 RC4 with kernel 2.2.12-20 and libc 2.1.2 on PIII machine. 
I wrote a small program which creates two buttons and generates 
different images depends on which button is pressed. The images 
are painted on the JPanel component.

I have exactly the same code for both buttons, but the images
they produce and paint are very different. My "Stop" button does
not produce the image at all and instead draws the image of the
button.

My "Start" button works well but creates the image located
slightly differently than the one created during initialization.
All images suppose to be exactly the same because I use the same 
paintComponent routine for all drawing - so the result should be 
the same. I don't remember that I had this problem when I used 
my NT machine some time ago.

Any help is very appreciated,

Thank you,

Jacob Nikom

---------------------------------------------------------------
Here is the code (rather small, little more than 50 lines in 
the each module):

// ====== beginning of the main file GuiPanel.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class GuiPanel extends JPanel
{
  MeteorImageInterface meteorImageInterface;

  JButton startButton, stopButton;

  Color backgroundColor = new Color(0.433f,0.691f,0.641f);

  GuiPanel()
  {
    super();
    System.out.println("Start  GuiPanel constructor");
    this.setLayout(null);
    this.setBounds(0,0, 266,250);
    this.setBackground(Color.blue);

    startButton = new JButton("Start");
    startButton.setBounds(5, 5, 125, 30);
    startButton.setBackground(Color.green);
    startButton.addActionListener(startListener);
    startButton.setEnabled(true);

    stopButton = new JButton("Stop");
    stopButton.setBounds(135, 5, 124, 30);
    stopButton.setBackground(Color.red);
    stopButton.addActionListener(stopListener);
    stopButton.setEnabled(true);

    meteorImageInterface = new MeteorImageInterface();
    meteorImageInterface.setBounds(5,40, 128,128);
    meteorImageInterface.setBackground(new Color(0.433f,0.691f,0.641f));
    meteorImageInterface.setForeground(new Color(0.001f,0.300f,0.900f));
  
    this.add(startButton);
    this.add(stopButton);
    this.add(meteorImageInterface);
  
    System.out.println("Finish GuiPanel constructor");
  } 
  ActionListener startListener = new ActionListener()
  {
    public void actionPerformed(ActionEvent event)
    {
      meteorImageInterface.imageStart();
    };
  };

  ActionListener stopListener = new ActionListener()
  {
    public void actionPerformed(ActionEvent event)
    {
      meteorImageInterface.imageStop();
    }
  };

  public static void main(String[] args)
  {
    JFrame frame = new JFrame("Swing Worker Thread Motion Example");
    frame.setBounds(100,100, 286, 310);

    frame.addWindowListener(new WindowAdapter()
    {
      public void windowClosing(WindowEvent e)
      {
        System.exit(0);
      }
    });

    Container container = frame.getContentPane();

    container.setLayout(null);

    GuiPanel guiPanel = new GuiPanel();

    container.add(guiPanel);
    frame.setVisible(true);
    frame.validate();
  }
}
// ====== end of the main file GuiPanel.java

// ====== beginning of the class file MeteorImageInterface.java
import javax.swing.*;
import java.awt.*;
import java.awt.image.*;

public class MeteorImageInterface extends JPanel
{
  public static Image videoImage;
  MediaTracker myTracker;

  public static int imageWidth  = 160, imageHeight = 120;

  static int intArr[];

  MeteorImageInterface()
  {
    super();

    intArr = new int[imageWidth * imageHeight];

    for (int i = 0; i < imageWidth * imageHeight; i++)
    {
      intArr[i] = 0Xff00ffff;
    }

    videoImage =
      createImage(
        new MemoryImageSource(imageWidth, imageHeight, intArr, 0,
imageWidth));
  }

  public synchronized void imageStart()
  {
    System.out.println("Start  imageStart");

//  Filling the arrays with colors
    for (int i = 0; i < imageWidth * imageHeight; i++)
    {
      intArr[i] = 0Xffff00ff;
    }

//  Create the video images
    videoImage = 
      createImage(
         new MemoryImageSource(imageWidth, imageHeight, intArr, 0,
imageWidth));


//  Load the video image
    myTracker = new MediaTracker(this);
    myTracker.addImage(videoImage, 0);

    try
    {
      if (!myTracker.waitForID(0, 1000)) { return; }
    } catch (Exception ignore) { }

    repaint();
  }

  public synchronized void imageStop()
  {
//  Filling the arrays with colors
    for (int i = 0; i < imageWidth * imageHeight; i++)
    {
      intArr[i] = 0X00f000ff;
    }

//  Create the video images
    videoImage =
      createImage(
         new MemoryImageSource(imageWidth, imageHeight, intArr, 0,
imageWidth));

//  Load the video image
    myTracker = new MediaTracker(this);
    myTracker.addImage(videoImage, 0);

    try
    {
      if (!myTracker.waitForID(0, 1000)) { return; }
    } catch (Exception ignore) { }

    repaint();
  }

//Paint simply draws the video image
  public void paintComponent(Graphics g)
  {
     g.drawImage(videoImage, 0, 0, imageWidth, imageHeight, this);
  }
}
// ====== end of the class file MeteorImageInterface.java


----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to