HELP - Java-Problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Patrick & Judith

    #1

    HELP - Java-Problem

    Hello,

    I'm facing the following problem:
    I've two classes named Plaatje and DiaShow (see below) I want to display the
    Image plaatje in the method run (which is in the class DiaShow) but it's not
    working although the path is correct. What's the problem. Can someone help
    me ? Thanks in advance.

    Patrick


    import java.io.*;
    import java.awt.*;

    public class Plaatje extends Canvas
    {
    protected Image plaatje;
    protected MediaTracker tracker;

    public Plaatje(File bestand) throws IOException

    try
    {
    String bestandsnaam = bestand.getCano nicalPath();
    plaatje = getToolkit().ge tImage(bestands naam);
    tracker = new MediaTracker(th is);
    tracker.addImag e(plaatje, 0);
    tracker.waitFor ID(0);
    }
    catch (Exception ex)
    {
    throw new IOException("Pl aatjesException : " + ex);
    }
    }

    public void paint(Graphics g)
    {
    g.drawImage(pla atje, 0, 0, this);
    }
    }



    This is the method run of class DiaShow

    public void run()
    {
    String padNaam = directoryVeld.g etText();

    try
    {
    int slaaptijd = Integer.parseIn t(tempoVeld.get Text());
    PlaatjesDirecto ry file = new PlaatjesDirecto ry(padNaam);
    File[] lijst = file.bestanden( );
    for (int i=0; i < lijst.length; i++)
    {
    textField1.setT ext(lijst[i].getPath());
    labelBestand.se tText(lijst[i].getName());
    Plaatje tekening = new Plaatje(lijst[i]);
    tekening.setLoc ation(150, 150);
    add(tekening);
    try
    {
    Thread.sleep(sl aaptijd*1000);}
    catch (InterruptedExc eption ignored){};
    }
    }
    catch (IOException ex)
    {
    }
    }


  • EricF

    #2
    Re: HELP - Java-Problem

    In article <432c3ceb$0$110 79$e4fe514c@new s.xs4all.nl>, "Patrick & Judith" <pmooij@xs4all. nl> wrote:[color=blue]
    >Hello,
    >
    >I'm facing the following problem:
    >I've two classes named Plaatje and DiaShow (see below) I want to display the
    >Image plaatje in the method run (which is in the class DiaShow) but it's not
    >working although the path is correct. What's the problem. Can someone help
    >me ? Thanks in advance.
    >
    >Patrick
    >
    >
    >import java.io.*;
    >import java.awt.*;
    >
    >public class Plaatje extends Canvas
    >{
    > protected Image plaatje;
    > protected MediaTracker tracker;
    >
    > public Plaatje(File bestand) throws IOException
    >
    > try
    > {
    > String bestandsnaam = bestand.getCano nicalPath();
    > plaatje = getToolkit().ge tImage(bestands naam);
    > tracker = new MediaTracker(th is);
    > tracker.addImag e(plaatje, 0);
    > tracker.waitFor ID(0);
    > }
    > catch (Exception ex)
    > {
    > throw new IOException("Pl aatjesException : " + ex);
    > }
    > }
    >
    > public void paint(Graphics g)
    > {
    > g.drawImage(pla atje, 0, 0, this);
    > }
    >}
    >
    >
    >
    >This is the method run of class DiaShow
    >
    > public void run()
    >{
    > String padNaam = directoryVeld.g etText();
    >
    > try
    > {
    > int slaaptijd = Integer.parseIn t(tempoVeld.get Text());
    > PlaatjesDirecto ry file = new PlaatjesDirecto ry(padNaam);
    > File[] lijst = file.bestanden( );
    > for (int i=0; i < lijst.length; i++)
    > {
    > textField1.setT ext(lijst[i].getPath());
    > labelBestand.se tText(lijst[i].getName());
    > Plaatje tekening = new Plaatje(lijst[i]);
    > tekening.setLoc ation(150, 150);
    > add(tekening);
    > try
    > {
    > Thread.sleep(sl aaptijd*1000);}
    > catch (InterruptedExc eption ignored){};
    > }
    > }
    > catch (IOException ex)
    > {
    > }
    > }[/color]

    I don't know why it doesn't work - but you might want to display the
    IOException if it's thrown instead of silently consuming it.

    Comment

    • Oliver Wong

      #3
      Re: HELP - Java-Problem

      "Patrick & Judith" <pmooij@xs4all. nl> wrote in message
      news:432c3ceb$0 $11079$e4fe514c @news.xs4all.nl ...[color=blue]
      > I've two classes named Plaatje and DiaShow (see below) I want to display
      > the
      > Image plaatje in the method run (which is in the class DiaShow) but it's
      > not
      > working although the path is correct. What's the problem. Can someone help
      > me ? Thanks in advance.[/color]

      What makes you think it's not working? I.e., is there an error message?
      If so, what does it say?

      - Oliver


      Comment

      Working...