Hallo,
würde gerne wissen ob es auch eine elegantere Methode gibt diesen Code zu schreiben als ich es hier getan hab:
Bin für jeden Tip und jede Meinung offen!
Mit freundlichen Grüßen
najjannaj
würde gerne wissen ob es auch eine elegantere Methode gibt diesen Code zu schreiben als ich es hier getan hab:
Code:
import java.awt.GridLayout;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Pic5on5 extends JPanel{
JLabel P1x1=new JLabel();
JLabel P1x2=new JLabel();
JLabel P1x3=new JLabel();
JLabel P1x4=new JLabel();
JLabel P1x5=new JLabel();
JLabel P2x1=new JLabel();
JLabel P2x2=new JLabel();
JLabel P2x3=new JLabel();
JLabel P2x4=new JLabel();
JLabel P2x5=new JLabel();
JLabel P3x1=new JLabel();
JLabel P3x2=new JLabel();
JLabel P3x3=new JLabel();
JLabel P3x4=new JLabel();
JLabel P3x5=new JLabel();
JLabel P4x1=new JLabel();
JLabel P4x2=new JLabel();
JLabel P4x3=new JLabel();
JLabel P4x4=new JLabel();
JLabel P4x5=new JLabel();
JLabel P5x1=new JLabel();
JLabel P5x2=new JLabel();
JLabel P5x3=new JLabel();
JLabel P5x4=new JLabel();
JLabel P5x5=new JLabel();
public Pic5on5(){
GridLayout layout = new GridLayout(5, 5);
setLayout(layout);
Init5x5();
setIcon(P1x1,"gold");
setIcon(P3x4,"haus");
setIcon(P1x5,"wald");
setIcon(P2x3,"gebaeude");
setIcon(P4x3,"gold");
}
public void setIcon(JLabel ico, String pic){
String strGold="C://gold.gif";
String strOedland="C://oedland.gif";
String strHaus="C://haus.gif";
String strWald="C://wald.gif";
String strGebaeude="C://gebaeude.gif";
String strPath=null;
if(pic == "gold"){
strPath = strGold;
}else if(pic == "oedland"){
strPath = strOedland;
}else if(pic == "haus"){
strPath = strHaus;
}else if(pic == "wald"){
strPath = strWald;
}else if(pic == "gebaeude"){
strPath = strGebaeude;
}else{
return;
}
ico.setIcon(new ImageIcon(strPath));
ico.repaint();
}
public void Init5x5(){
P1x1.setIcon(new ImageIcon("C://oedland.gif"));
P1x2.setIcon(new ImageIcon("C://oedland.gif"));
P1x3.setIcon(new ImageIcon("C://oedland.gif"));
P1x4.setIcon(new ImageIcon("C://oedland.gif"));
P1x5.setIcon(new ImageIcon("C://oedland.gif"));
P2x1.setIcon(new ImageIcon("C://oedland.gif"));
P2x2.setIcon(new ImageIcon("C://oedland.gif"));
P2x3.setIcon(new ImageIcon("C://oedland.gif"));
P2x4.setIcon(new ImageIcon("C://oedland.gif"));
P2x5.setIcon(new ImageIcon("C://oedland.gif"));
P3x1.setIcon(new ImageIcon("C://oedland.gif"));
P3x2.setIcon(new ImageIcon("C://oedland.gif"));
P3x3.setIcon(new ImageIcon("C://oedland.gif"));
P3x4.setIcon(new ImageIcon("C://oedland.gif"));
P3x5.setIcon(new ImageIcon("C://oedland.gif"));
P4x1.setIcon(new ImageIcon("C://oedland.gif"));
P4x2.setIcon(new ImageIcon("C://oedland.gif"));
P4x3.setIcon(new ImageIcon("C://oedland.gif"));
P4x4.setIcon(new ImageIcon("C://oedland.gif"));
P4x5.setIcon(new ImageIcon("C://oedland.gif"));
P5x1.setIcon(new ImageIcon("C://oedland.gif"));
P5x2.setIcon(new ImageIcon("C://oedland.gif"));
P5x3.setIcon(new ImageIcon("C://oedland.gif"));
P5x4.setIcon(new ImageIcon("C://oedland.gif"));
P5x5.setIcon(new ImageIcon("C://oedland.gif"));
add(P1x1);
add(P1x2);
add(P1x3);
add(P1x4);
add(P1x5);
add(P2x1);
add(P2x2);
add(P2x3);
add(P2x4);
add(P2x5);
add(P3x1);
add(P3x2);
add(P3x3);
add(P3x4);
add(P3x5);
add(P4x1);
add(P4x2);
add(P4x3);
add(P4x4);
add(P4x5);
add(P5x1);
add(P5x2);
add(P5x3);
add(P5x4);
add(P5x5);
}
}
Bin für jeden Tip und jede Meinung offen!
Mit freundlichen Grüßen
najjannaj