P
Peter55k
Gast
Kurz eine Frage, ich hab ein kleines Programm geschrieben, es geht nur um das ImageIcon. In der Schule wird das Icon angezeigt, bei mir zu hause aber leider nicht, obwohl das der gleiche quellcode ist, wieso nicht? Hab ich was falsch gemacht und das object wird vllt nicht von jeder JVM gleich interpretiert oder so?
geht nur um die das imageicon, bitte ein mal gucken
:/
geht nur um die das imageicon, bitte ein mal gucken
:/
Code:
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Spiel_brett_2 extends JFrame{
ImageIcon bild = new ImageIcon("punkt.png");
ImageIcon nix = new ImageIcon();
int zaehler = 0;
boolean A1_WERT = false;
boolean A2_WERT = false;
boolean A3_WERT = false;
boolean A4_WERT = false;
Object a = new Object();
Object b = new Object();
Weisser_Panel A1 = new Weisser_Panel();
Schwarzer_Panel A2 = new Schwarzer_Panel();
Schwarzer_Panel A3 = new Schwarzer_Panel();
Weisser_Panel A4 = new Weisser_Panel();
public void Button_A1()
{
if(A1_WERT == true)
{
System.out.println("A1");
if(zaehler == 0)
{
a = A1.b.getIcon();
A1.b.setIcon(nix);
}
if(zaehler == 1)
{
A1.b.setIcon((Icon) a);
}
zaehler++;
if (zaehler == 2)
{
zaehler = 0;
}
}
if(A2_WERT == true)
{
System.out.println("A2");
if(zaehler == 0)
{
a = A2.b.getIcon();
A2.b.setIcon(nix);
}
if(zaehler == 1)
{
A2.b.setIcon((Icon) a);
}
zaehler++;
if (zaehler == 2)
{
zaehler = 0;
}
}
if(A3_WERT == true)
{
if(zaehler == 0)
{
a = A3.b.getIcon();
A3.b.setIcon(nix);
}
if(zaehler == 1)
{
A3.b.setIcon((Icon) a);
}
zaehler++;
if (zaehler == 2)
{
zaehler = 0;
}
System.out.println("A3");
}
if(A4_WERT == true)
{
if(zaehler == 0)
{
a = A4.b.getIcon();
A4.b.setIcon(nix);
}
if(zaehler == 1)
{
A4.b.setIcon((Icon) a);
}
zaehler++;
if (zaehler == 2)
{
zaehler = 0;
}
System.out.println("A4");
}
}
public Spiel_brett_2()
{
Container cp = getContentPane();
cp.setLayout(new GridLayout(2,2));
A1.b.setIcon(bild);
cp.add(A1); cp.add(A2); cp.add(A3); cp.add(A4);
A1.b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
A1_WERT = true;
Button_A1();
A1_WERT = false;
}
});
A2.b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
A2_WERT = true;
Button_A1();
A2_WERT = false;
}
});
A3.b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
A3_WERT = true;
Button_A1();
A3_WERT = false;
}
});
A4.b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
A4_WERT = true;
Button_A1();
A4_WERT = false;
}
});
this.setSize(172,168);
this.setTitle("Schach 5000");
this.setResizable(false);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
}
}
class Weisser_Panel extends JPanel
{
JButton b = new JButton();
public Weisser_Panel()
{
setLayout(null);
b.setBounds(0,0, 86, 84);
b.setBackground(Color.WHITE);
add(b);
}
}
class Schwarzer_Panel extends JPanel
{
JButton b = new JButton();
public Schwarzer_Panel()
{
setLayout(null);
b.setBounds(0,0, 86, 84);
b.setBackground(Color.black);
add(b);
}
}