Swing Eclipse: Nach Exportieren, Button funktioniert nicht mehr

Diskutiere Eclipse: Nach Exportieren, Button funktioniert nicht mehr im AWT, Swing, JavaFX & SWT Bereich.
J

JustNobody

Bleibt die Frage nach dem resourceAsStream9, denn das scheint null zu sein.
 
L

LimDul

In welchem Verzeichnis in dem Jar ist sie drin? Das mal angeben - inklusive Dateinamen mit korrekter Groß & Kleinschreibung
Und wie wird die resourceAsStream9 erzeugt - das auch mal angeben
 
VPChief

VPChief

Hallo, ich habe mein Programm, dass ich für einen Freund schreiben muss. Jetzt soweit fertiggestellt, dass ich das Projekt Exportiert habe, und als ich es Ausgeführt habe und auf einen Button geklickt habe, habe ich nur noch ein leeres Fenster. Anfangs kam noch Ein Warning Fenster Beim Exportieren, dass jetzt nichtmehr kommt, da ich einen unbenutzten Import gelöscht habe, allerdings ist das Problem jetzt immernoch nicht behoben.
Java:
public class Main_Class {

    //Main

    public static void main(String[] args) throws IOException {
        JFrame window = new JFrame();

        window.addComponentListener(new ComponentListener() {

            @Override
            public void componentHidden(ComponentEvent arg0) {
                // TODO Auto-generated method stub
       
            }

            @Override
            public void componentMoved(ComponentEvent arg0) {
                window.setLocation(0, 0);
       
            }

            @Override
            public void componentResized(ComponentEvent arg0) {
       
            }

            @Override
            public void componentShown(ComponentEvent arg0) {
                // TODO Auto-generated method stub
       
            }
   
        });
        setupContent(window);

        window.setSize(1990, 730);
        window.setMinimumSize(new Dimension(800,500));
        window.setVisible(true);
        window.setResizable(false);
        window.setTitle("Frame");
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );

    }

    private static void setupContent(JFrame window) throws IOException {
        FlowLayout layout = new FlowLayout(FlowLayout.LEFT, 0, 0);
        JButton Einstellungen = new JButton("Einstellungen");
//        JPanel content = new JPanel();
        JPanel panel = new JPanel(layout);
        JLabel startLabel = new JLabel("Willkomen ");
       JButton start = new JButton("Starten");  //<--Dieser Button funktioniert nicht.
        panel.add(startLabel);
        panel.add(start);


        panel.add(Einstellungen);
        window.add(panel);




        start.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
                startLabel.setVisible(false);
                start.setVisible(false);
                Einstellungen.setVisible(false);
                CopyrightuCo.setVisible(false);
                Copyrightco2.setVisible(false);
                InputStream resourceAsStream = (InputStream) Main_Class.class.getResourceAsStream("/textures/Büsche und Sträucher tex/tex1.png");
                Image image = null;
                try {
                    image = ImageIO.read(resourceAsStream);
                } catch (IOException e2) {
                    // TODO Auto-generated catch block
                    e2.printStackTrace();
                }
       
                JButton button1 = new JButton (new ImageIcon(image));
                JButton Speichern = new JButton ("Speichern");
   
                InputStream resourceAsStream2 = (InputStream) Main_Class.class.getResourceAsStream("/textures/Büsche und Sträucher tex/Tex 5.png");
                Image image2 = null;
                try {
                    image2 = ImageIO.read(resourceAsStream2);
                } catch (IOException e2) {
                    // TODO Auto-generated catch block
                    e2.printStackTrace();
                }
       
                JButton button6= new JButton(new ImageIcon(image2));
                InputStream resourceAsStream3 = (InputStream) Main_Class.class.getResourceAsStream("/textures/Büsche und Sträucher tex/tex4.png");
                Image image3 = null;
                try {
                    image3 = ImageIO.read(resourceAsStream3);
                } catch (IOException e2) {
                    // TODO Auto-generated catch block
                    e2.printStackTrace();
                }
                JButton button10= new JButton(new ImageIcon(image3));
                InputStream resourceAsStream4 = (InputStream) Main_Class.class.getResourceAsStream("/textures/Objekte/tex5.png");
                Image image4 = null;
                try {
                    image4 = ImageIO.read(resourceAsStream4);
                } catch (IOException e2) {
                    // TODO Auto-generated catch block
                    e2.printStackTrace();
                }
                JButton button13= new JButton(new ImageIcon(image4));
                InputStream resourceAsStream5 = (InputStream) Main_Class.class.getResourceAsStream("/textures/Objekte/tex6.png");
                Image image5 = null;
                try {
                    image5 = ImageIO.read(resourceAsStream5);
                } catch (IOException e2) {
                    // TODO Auto-generated catch block
                    e2.printStackTrace();
                }
                JButton button14= new JButton(new ImageIcon(image5));
                InputStream resourceAsStream6 = (InputStream) Main_Class.class.getResourceAsStream("/textures/untergrund tex/tex1.png");
                Image image6 = null;
                try {
                    image6 = ImageIO.read(resourceAsStream6);
                } catch (IOException e2) {
                    // TODO Auto-generated catch block
                    e2.printStackTrace();
                }

                JButton button11= new JButton(new ImageIcon(image6));
                InputStream resourceAsStream7 = (InputStream) Main_Class.class.getResourceAsStream("/textures/Objekte/tex2.png");
                Image image7 = null;
                try {
                    image7 = ImageIO.read(resourceAsStream7);
                } catch (IOException e2) {
                    // TODO Auto-generated catch block
                    e2.printStackTrace();
                }
                JButton button8= new JButton(new ImageIcon(image7));
                InputStream resourceAsStream8 = (InputStream) Main_Class.class.getResourceAsStream("/textures/Objekte/tex3.png");
                Image image8 = null;
                try {
                    image8 = ImageIO.read(resourceAsStream8);
                } catch (IOException e2) {
                    // TODO Auto-generated catch block
                    e2.printStackTrace();
                }
                JButton button9= new JButton(new ImageIcon(image8));
                InputStream resourceAsStream9 = (InputStream) Main_Class.class.getResourceAsStream("/textures/Untergrund tex/tex2.png");
                Image image9 = null;
                try {
                    image9 = ImageIO.read(resourceAsStream9);
                } catch (IOException e2) {
                    // TODO Auto-generated catch block
                    e2.printStackTrace();
                }
                InputStream resourceAsStream10 = (InputStream) Main_Class.class.getResourceAsStream("/textures/TransparentTex.png");
                Image image10 = null;
                try {
                    image10 = ImageIO.read(resourceAsStream10);
                } catch (IOException e2) {
                    // TODO Auto-generated catch block
                    e2.printStackTrace();
                }
                JButton button3 = new JButton(new ImageIcon(image10));
                JButton button5 = new JButton(new ImageIcon(image9));
                InputStream resourceAsStream14 = (InputStream) Main_Class.class.getResourceAsStream("/textures/Objekte/tex7.png");
                Image image14 = null;
                try {
                    image14 = ImageIO.read(resourceAsStream14);
                } catch (IOException e2) {
                    // TODO Auto-generated catch block
                    e2.printStackTrace();
                }
                JButton button20 = new JButton(new ImageIcon(image14));
                InputStream resourceAsStream11 = (InputStream) Main_Class.class.getResourceAsStream("/textures/Objekte/tex1.png");
                Image image11 = null;
                try {
                    image11 = ImageIO.read(resourceAsStream11);
                } catch (IOException e2) {
                    // TODO Auto-generated catch block
                    e2.printStackTrace();
                }
                JButton button7 = new JButton(new ImageIcon(image11));
                InputStream resourceAsStream12 = (InputStream) Main_Class.class.getResourceAsStream("/textures/Büsche und Sträucher tex/tex4.png");
                Image image12 = null;
                try {
                    image12 = ImageIO.read(resourceAsStream12);
                } catch (IOException e2) {
                    // TODO Auto-generated catch block
                    e2.printStackTrace();
                }
                InputStream resourceAsStream13 = (InputStream) Main_Class.class.getResourceAsStream("/textures/untergrund tex/tex3.png");
                Image image13 = null;
                try {
                    image13 = ImageIO.read(resourceAsStream13);
                } catch (IOException e2) {
                    // TODO Auto-generated catch block
                    e2.printStackTrace();
                }
                InputStream resourceAsStream15 = (InputStream) Main_Class.class.getResourceAsStream("/textures/untergrund tex/tex3.png");
                Image image15 = null;
                try {
                    image15 = ImageIO.read(resourceAsStream15);
                } catch (IOException e2) {
                    // TODO Auto-generated catch block
                    e2.printStackTrace();
                }
                JButton button2 = new JButton(new ImageIcon(image15));
                JButton button12 = new JButton(new ImageIcon(image13));
                JButton button4 = new JButton(new ImageIcon(image12));
                panel.add(button20);
                panel.add(Speichern);
                panel.add(button1);
                panel.add(button2);
                panel.add(button3);
                panel.add(button5);
                panel.add(button4);
                panel.add(button6);
                panel.add(button7);
                panel.add(button8);
                panel.add(button9);
                panel.add(button10);
                panel.add(button11);
                panel.add(button12);
                panel.add(button13);
                panel.add(button14);
       
                button11.setIcon(new ImageIcon("src\\textures\\untergrund tex\\tex1.png"));
       
                button2.setIcon(new ImageIcon("src\\textures\\Büsche und Sträucher tex\\tex2.png"));
   

                button10.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        JLabel tex5 = new JLabel();
                        tex5.setIcon(new ImageIcon("src\\textures\\Objekte\\tex4.png"));
                        panel.add(tex5);
                        panel.revalidate();
                        panel.repaint();
               
                    }
           
                });
       
                button20.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        InputStream resourceAsStream14 = (InputStream) Main_Class.class.getResourceAsStream("/textures/Objekte/tex7.png");
                        Image image14 = null;
                        try {
                            image14 = ImageIO.read(resourceAsStream14);
                        } catch (IOException e2) {
                            // TODO Auto-generated catch block
                            e2.printStackTrace();
                        }
                        JLabel tex5 = new JLabel(new ImageIcon(image14));
                        panel.add(tex5);
                        panel.revalidate();
                        panel.repaint();
               
                    }
           
                });
       
                button14.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        InputStream resourceAsStream14 = (InputStream) Main_Class.class.getResourceAsStream("/textures/Objekte/tex6.png");
                        Image image14 = null;
                        try {
                            image14 = ImageIO.read(resourceAsStream14);
                        } catch (IOException e2) {
                            // TODO Auto-generated catch block
                            e2.printStackTrace();
                        }
                        JLabel tex5 = new JLabel(new ImageIcon(image14));
                        panel.add(tex5);
                        panel.revalidate();
                        panel.repaint();
               
                    }
           
                });
       
                button13.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        InputStream resourceAsStream14 = (InputStream) Main_Class.class.getResourceAsStream("/textures/Objekte/tex5.png");
                        Image image14 = null;
                        try {
                            image14 = ImageIO.read(resourceAsStream14);
                        } catch (IOException e2) {
                            // TODO Auto-generated catch block
                            e2.printStackTrace();
                        }
                        JLabel tex5 = new JLabel(new ImageIcon(image14));
               
                        panel.add(tex5);
                        panel.revalidate();
                        panel.repaint();
               
                    }
           
                });
       
                button5.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        InputStream resourceAsStream14 = (InputStream) Main_Class.class.getResourceAsStream("/textures/untergrund tex/tex2.png");
                        Image image14 = null;
                        try {
                            image14 = ImageIO.read(resourceAsStream14);
                        } catch (IOException e2) {
                            // TODO Auto-generated catch block
                            e2.printStackTrace();
                        }
                        JLabel tex5 = new JLabel(new ImageIcon(image14));
                        panel.add(tex5);
                        panel.revalidate();
                        panel.repaint();
               
                    }
           
                });
                button12.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        InputStream resourceAsStream14 = (InputStream) Main_Class.class.getResourceAsStream("/textures/untergrund tex/tex3.png");
                        Image image14 = null;
                        try {
                            image14 = ImageIO.read(resourceAsStream14);
                        } catch (IOException e2) {
                            // TODO Auto-generated catch block
                            e2.printStackTrace();
                        }
                        JLabel tex5 = new JLabel(new ImageIcon(image14));
                        panel.add(tex5);
                        panel.revalidate();
                        panel.repaint();
               
                    }
           
                });
                button11.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        InputStream resourceAsStream14 = (InputStream) Main_Class.class.getResourceAsStream("/textures/untergrund tex/tex1.png");
                        Image image14 = null;
                        try {
                            image14 = ImageIO.read(resourceAsStream14);
                        } catch (IOException e2) {
                            // TODO Auto-generated catch block
                            e2.printStackTrace();
                        }
                        JLabel tex5 = new JLabel(new ImageIcon(image14));
               
               
                        panel.add(tex5);
                        panel.revalidate();
                        panel.repaint();
               
                    }
           
                });
                button4.addActionListener(new ActionListener() {
           
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        InputStream resourceAsStream14 = (InputStream) Main_Class.class.getResourceAsStream("/textures/Büsche und Sträucher tex/tex4.png");
                        Image image14 = null;
                        try {
                            image14 = ImageIO.read(resourceAsStream14);
                        } catch (IOException e2) {
                            // TODO Auto-generated catch block
                            e2.printStackTrace();
                        }
                        JLabel tex5 = new JLabel(new ImageIcon(image14));
                        panel.add(tex5);
                        panel.revalidate();
                        panel.repaint();
                    }
                });
                button1.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        InputStream resourceAsStream = (InputStream) Main_Class.class.getResourceAsStream("/textures/Büsche und Sträucher tex/tex1.png");
                        Image image = null;
                        try {
                            image = ImageIO.read(resourceAsStream);
                        } catch (IOException e2) {
                            // TODO Auto-generated catch block
                            e2.printStackTrace();
                        }
               
                        JLabel tex1 = new JLabel(new ImageIcon(image));
               
                        panel.add(tex1);
                        panel.revalidate();
                        panel.repaint();
               
                    }
           
                });
       
                button6.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        InputStream resourceAsStream = (InputStream) Main_Class.class.getResourceAsStream("/textures/Büsche und Sträucher tex/Tex 5.png");
                        Image image = null;
                        try {
                            image = ImageIO.read(resourceAsStream);
                        } catch (IOException e2) {
                            // TODO Auto-generated catch block
                            e2.printStackTrace();
                        }
               
                        JLabel tex1 = new JLabel(new ImageIcon(image));
                        panel.add(tex1);
                        panel.revalidate();
                        panel.repaint();

               
                    }
           
                });
       
       
                button7.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        InputStream resourceAsStream14 = (InputStream) Main_Class.class.getResourceAsStream("/textures/Objekte/tex1.png");
                        Image image14 = null;
                        try {
                            image14 = ImageIO.read(resourceAsStream14);
                        } catch (IOException e2) {
                            // TODO Auto-generated catch block
                            e2.printStackTrace();
                        }
                        JLabel tex1 = new JLabel(new ImageIcon(image14));
                        panel.add(tex1);
                        panel.revalidate();
                        panel.repaint();
               
                    }
                });
       
                button8.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        InputStream resourceAsStream14 = (InputStream) Main_Class.class.getResourceAsStream("/textures/Objekte/tex2.png");
                        Image image14 = null;
                        try {
                            image14 = ImageIO.read(resourceAsStream14);
                        } catch (IOException e2) {
                            // TODO Auto-generated catch block
                            e2.printStackTrace();
                        }
                        JLabel tex1 = new JLabel(new ImageIcon(image14));
                        tex1.setIcon(new ImageIcon("src\\textures\\Objekte\\tex2.png"));
                        panel.add(tex1);
                        panel.revalidate();
                        panel.repaint();
               
                    }
                });
       
                button9.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        InputStream resourceAsStream14 = (InputStream) Main_Class.class.getResourceAsStream("/textures/Objekte/tex3.png");
                        Image image14 = null;
                        try {
                            image14 = ImageIO.read(resourceAsStream14);
                        } catch (IOException e2) {
                            // TODO Auto-generated catch block
                            e2.printStackTrace();
                        }
                        JLabel tex1 = new JLabel(new ImageIcon(image14));
                        panel.add(tex1);
                        panel.revalidate();
                        panel.repaint();
               
                    }
                });
       
       
                button3.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent arg0) {
                        InputStream resourceAsStream14 = (InputStream) Main_Class.class.getResourceAsStream("/textures/TransparentTex.png");
                        Image image14 = null;
                        try {
                            image14 = ImageIO.read(resourceAsStream14);
                        } catch (IOException e2) {
                            // TODO Auto-generated catch block
                            e2.printStackTrace();
                        }
                        JLabel tex5 = new JLabel(new ImageIcon(image14));
                        tex5.setIcon(new ImageIcon("src\\textures\\TransparentTex.png"));
                        panel.add(tex5);
                        panel.revalidate();
                        panel.repaint();

               
                    }
           
           
                });
                button2.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        InputStream resourceAsStream14 = (InputStream) Main_Class.class.getResourceAsStream("/textures/Büsche und Sträucher tex/tex2.png");
                        Image image14 = null;
                        try {
                            image14 = ImageIO.read(resourceAsStream14);
                        } catch (IOException e2) {
                            // TODO Auto-generated catch block
                            e2.printStackTrace();
                        }
                        JLabel tex2 = new JLabel(new ImageIcon(image14));
                        panel.add(tex2);
                        panel.revalidate();
                        panel.repaint();
               
                    }
           
                });
       
                Speichern.addActionListener(new ActionListener(){
           
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Robot screenshot = null;
                        try {
                            screenshot = new Robot ();
                        } catch (AWTException e1) {
                   
                            e1.printStackTrace();
                        }
                        Object i = null;
                        i = screenshot.createScreenCapture(new Rectangle (60,60,1350,665));
               
                        JFileChooser fileChooser = new JFileChooser();
                        fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                        int returnValue = fileChooser.showOpenDialog(null);
                        if (returnValue == JFileChooser.APPROVE_OPTION) {
                          File selectedFile = fileChooser.getSelectedFile();
                          PrintWriter writer = null;
                          try {
                        File targetFile = new File(selectedFile, "saved.png");
                        System.out.println(targetFile);
                            writer = new PrintWriter(targetFile);
                   
                            ImageIO.write((RenderedImage) i, "png", targetFile);
                          } catch (IOException ae) {
                            ae.printStackTrace();
                          }  finally {
                            if (writer != null) {
                              writer.flush();
                              writer.close();
                            }
                          }
                        }
                      }
                    }

               
               
           
           
                );
               
                    }
               
                    }
           
                );
           
                }
       

           
       
   
        ;


    }


[?/CODE]
Beim Starten in der Entwiklungsugebung funktioniert es. Hat jemand ne Idee, woran das liegt?
Danke schonmal für Eure Antworten
Erstmal danke für eure Antworten, In dieser Nachricht ist der Komplette Code. ^^ Daran sieht man wie der Erzeugt wird oder wie meinst du das
In welchem Verzeichnis in dem Jar ist sie drin? Das mal angeben - inklusive Dateinamen mit korrekter Groß & Kleinschreibung
Und wie wird die resourceAsStream9 erzeugt - das auch mal angeben
Du meinst das Bild das ich in dem resourceAsStream9 erzeuge?
textures\untergrund tex\tex2.png
Das ist der Pfad
 
Zuletzt bearbeitet:
VPChief

VPChief

Ich muss mich korrigieren, es ist blos ein Bild drin. Insgesamt im JAR, weil die anderen ja nach dem Startbutton sind, und der ja nich t funktioniert
 
J

JustNobody

Wieso muss man immer alles aus der Nase ziehen? Kopier den Codeabschnitt komplett hier rein und wie LimDul geschrieben hat: wo und wie ist das Bild? Inkl. Groß/Kleinschreibung.

Ohne Details können wirnDir nur sagen: Du hast ganz offensichtlich etwas falsch gemacht....
 
L

LimDul

Ich muss mich korrigieren, es ist blos ein Bild drin. Insgesamt im JAR, weil die anderen ja nach dem Startbutton sind, und der ja nich t funktioniert
Das hat doch damit nix zu tun. Ob der funktioniert oder nicht, ist egal - wenn die nicht im jar drin sind hat, das packen nicht geklappt.

Java:
                InputStream resourceAsStream6 = (InputStream) Main_Class.class.getResourceAsStream("/textures/untergrund tex/tex1.png");
                InputStream resourceAsStream9 = (InputStream) Main_Class.class.getResourceAsStream("/textures/Untergrund tex/tex2.png");
Fällt dir was auf? Im Jar File ist Groß/Kleinschreibung relevant.
 
VPChief

VPChief

Habe ich echt übersehen🤦‍♂️ Jetzt funktionierts auf jedenfall, :) Danke.
 
Thema: 

Eclipse: Nach Exportieren, Button funktioniert nicht mehr

Passende Stellenanzeigen aus deiner Region:
Anzeige

Neue Themen

Anzeige

Anzeige
Oben