Erste Schritte Importieren funktioniert nicht

MrsLucida

Mitglied
Hellö,
ich bin noch kompletter Anfänger im Programmieren und versuche gerade mein erstes Programm zu kompilieren (über CMD). Leider kommen Fehlermeldungen, weil die Imports nicht ausgeführt werden können :/... Ich hab die Umgebungsvariable Path schon auf den bin-Ordner gesetzt, aber es funktioniert trotzdem nicht.
Ich würde mich freuen, wenn mir jemand helfen könnte 😀
 
Hast du denn schon probiert ein simples "Hello World" Programm zu kompilieren?
Wenn nicht, versuche das doch mal.
Ansonsten mal Fehlermeldung und evtl. auch Code posten. Dazu bitte die passenden Code-Tags verwenden.
 
Ja, ohne Imports funktioniert jedes Programm...

hier mal mein code:

Java:
import java.awt.*;
import java.swing.*;
public class Bido6 extends JFrame
{
    public Bido6()
    {
        super("Hallo");
        Icon icon = new ImageIcon ("Bild1.jpg");
        JLabel label1 = new JLabel("Marvel", JLabel.CENTER);
        JLabel label2 = new JLabel("the Avengers", JLabel.CENTER);
        JLabel label3 = new JLabel(icon);
        Font schrift = new Font("SansSerif", Font.BOLD, 24);
        label1.setFont(schrift);
        label1.setForeground(Color.red);
        label2.setFont(schrift);
        label2.setForegrounf(Color.black);
        Container c = getContentPane();
        c.setLayout(new FlowLayout());
        c.setBackground(Color.white);
        c.add(label1);
        c.add(label2);
        c.add(label3);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(300,250);
        setVisible(true);
    }
  
    public static void main(String[] args)
    {
        new Bido6();
    }
}

Und dann kam die Fehlermeldung:
Code:
Bido6.java:4: error: cannot find symbol
public class Bido6 extends JFrame
                           ^
  symbol: class JFrame
Bido6.java:2: error: package java.swing does not exist
import java.swing.*;
^
Bido6.java:10: error: cannot find symbol
                Icon icon = new ImageIcon ("Bild1.jpg");
                ^
  symbol:   class Icon
  location: class Bido6
Bido6.java:10: error: cannot find symbol
                Icon icon = new ImageIcon ("Bild1.jpg");
                                ^
  symbol:   class ImageIcon
  location: class Bido6
Bido6.java:11: error: cannot find symbol
                JLabel label1 = new JLabel("Marvel", JLabel.CENTER);
                ^
  symbol:   class JLabel
  location: class Bido6
Bido6.java:11: error: cannot find symbol
                JLabel label1 = new JLabel("Marvel", JLabel.CENTER);
                                    ^
  symbol:   class JLabel
  location: class Bido6
Bido6.java:11: error: cannot find symbol
                JLabel label1 = new JLabel("Marvel", JLabel.CENTER);
                                                     ^
  symbol:   variable JLabel
  location: class Bido6
Bido6.java:12: error: cannot find symbol
                JLabel label2 = new JLabel("the Avengers", JLabel.CENTER);
                ^
  symbol:   class JLabel
  location: class Bido6
Bido6.java:12: error: cannot find symbol
                JLabel label2 = new JLabel("the Avengers", JLabel.CENTER);
                                    ^
  symbol:   class JLabel
  location: class Bido6
Bido6.java:12: error: cannot find symbol
                JLabel label2 = new JLabel("the Avengers", JLabel.CENTER);
                                                           ^
  symbol:   variable JLabel
  location: class Bido6
Bido6.java:13: error: cannot find symbol
                JLabel label3 = new JLabel(icon);
                ^
  symbol:   class JLabel
  location: class Bido6
Bido6.java:13: error: cannot find symbol
                JLabel label3 = new JLabel(icon);
                                    ^
  symbol:   class JLabel
  location: class Bido6
Bido6.java:19: error: cannot find symbol
                Container c = getContentPane();
                              ^
  symbol:   method getContentPane()
  location: class Bido6
Bido6.java:25: error: cannot find symbol
                setDefaultCloseOperation(EXIT_ON_CLOSE);
                                         ^
  symbol:   variable EXIT_ON_CLOSE
  location: class Bido6
Bido6.java:26: error: cannot find symbol
                setSize(300,250);
                ^
  symbol:   method setSize(int,int)
  location: class Bido6
Bido6.java:27: error: cannot find symbol
                setVisible(true);
                ^
  symbol:   method setVisible(boolean)
  location: class Bido6
16 errors

Sorry ist ein bisle arg lang :/....
 
Zuletzt bearbeitet von einem Moderator:
Hier:
Java:
import java.awt.*;
import javax.swing.*;

public class Bido6 extends JFrame
{

    public Bido6()
    {
        super("Hallo");
        Icon icon = new ImageIcon("Bild1.jpg");
        JLabel label1 = new JLabel("Marvel", JLabel.CENTER);
        JLabel label2 = new JLabel("the Avengers", JLabel.CENTER);
        JLabel label3 = new JLabel(icon);
        Font schrift = new Font("SansSerif", Font.BOLD, 24);
        label1.setFont(schrift);
        label1.setForeground(Color.red);
        label2.setFont(schrift);
        label2.setForeground(Color.black);
        java.awt.Container c = getContentPane();
        c.setLayout(new FlowLayout());
        c.setBackground(Color.white);
        c.add(label1);
        c.add(label2);
        c.add(label3);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(300, 250);
        setVisible(true);
    }

    public static void main(String[] args)
    {
        new Bido6();
    }
}

Büdde 🙂

Und hier lesen https://docs.oracle.com/javase/7/docs/api/javax/swing/package-summary.html .
 

Neue Themen


Zurück
Oben