Auf Thema antworten

hallo, ich habe mal ne frage...ich habe einen timer programmiert der von 9 runterzählt und wenn er bei 0 ist wieder von vorne anfängt...bei mir ist das problem das ich die zahlen als imagedatei habe. habe sie im img-ordner angelegt und es  funktioniert auch.

wenn ich die imagedatei in dem resourcordner anlege und sie aus dem resource-ordner hole, da funktioniert es nicht.

weiss nicht woran es liegt...

die zeile 85 mit der ausgeblendeten zeile ist der resource-ordner...könnte mir dafür einer die codezeile geben.

[code=java]package de.main.java;


import java.awt.Color;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;


import javax.swing.Icon;

import javax.swing.ImageIcon;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.Timer;




public class Main extends JFrame {

 

    public final static int SHOW_TIME_PER_SLIDE = 600;

 

    Timer timer = new Timer(SHOW_TIME_PER_SLIDE, new ButtonHaendler());

 

    JLabel bild1;

    Icon textPause;

 

    JLabel bild2;

    Icon timerZahlen;

 

    JButton buttonPause;

 

    JButton buttonPlay;

 

 

    public Main(){

     

        Icon a = new ImageIcon(getClass().getResource("button pause orange.jpg"));

        Icon b = new ImageIcon(getClass().getResource("button pause blau.jpg"));

        buttonPause = new JButton("", a);

        buttonPause.setRolloverIcon(b);

        buttonPause.setBounds(750, 20, 59, 84);

        buttonPause.setBorder(null);

        buttonPause.addActionListener(new ButtonHaendler());

        add(buttonPause);

     

        Icon c = new ImageIcon(getClass().getResource("button play orange.jpg"));

        Icon d = new ImageIcon(getClass().getResource("button play blau.jpg"));

        buttonPlay = new JButton("", c);

        buttonPlay.setRolloverIcon(d);

        buttonPlay.setBounds(650, 20, 75, 84);

        buttonPlay.setBorder(null);

        buttonPlay.addActionListener(new ButtonHaendler());

        add(buttonPlay);

     

        textPause = new ImageIcon(getClass().getResource("text pause.png"));

        bild1 = new JLabel(textPause);

        bild1.setBounds(150, 180, 1205, 284);

        bild1.setVisible(false);

        add(bild1);

     

        timerZahlen = new ImageIcon(getClass().getResource("timer9.jpg"));

        bild2 = new JLabel(timerZahlen);

        bild2.setBounds(620, 120, 225, 400);

        add(bild2);

    }

 

 

    class ButtonHaendler implements ActionListener{

     

        int ziffer = 9;


        @Override

        public void actionPerformed(ActionEvent e) {

         

            if(e.getSource()== buttonPause){

                bild1.setVisible(true);

                timer.setRepeats(false);

            }

         

            if(e.getSource()== buttonPlay){

                 timer.start();

                 timer.setRepeats(true);

                bild1.setVisible(false);

            }

         

            bild2.setIcon(new ImageIcon("img/timer" + ziffer + ".jpg"));

//            timerZahlen = new ImageIcon(getClass().getResource("timer" + ziffer ".jpg"));

         

            ziffer = ziffer -1;

         

            if( ziffer == -1){

                ziffer = 10;

                ziffer = ziffer -1;

            }

        }

     

    }


    public static void main(String[] args) {

        Main frame = new Main();

        frame.setTitle("main");

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        frame.setSize(1500, 600);

        frame.getContentPane().setLayout(null);

        frame.setLocationRelativeTo(null);

        frame.setVisible(true);

        frame.getContentPane().setBackground(new Color(0, 0, 0));

    }

}

[/code]



Oben