import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.ButtonGroup;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class Hauptprogramm {
JFrame hauptfenster;
JButton rechne;
JRadioButton reihe, parallel;
ButtonGroup grp;
JComboBox[] widerstand1;
JComboBox[] widerstand2;
JLabel ausgabe1;
JLabel ausgabe2;
JLabel ausgabe3;
JLabel ring1, ring2, ring3, ring4, ring5, ring6;
JLabel hintergrund;
public Hauptprogramm() {
String[][] dd = {{ "braun", "rot", "orange", "gelb", "grün", "blau",
"violet", "grau", "weiss" }, { "schwarz", "braun", "rot", "orange", "gelb", "grün",
"blau", "violet", "grau", "weiss" }, { "silber", "gold", "schwarz", "braun", "rot", "orange",
"gelb", "grün", "blau", "violet", "grau", "weiss" }};
hauptfenster = new JFrame();
hauptfenster.setSize(1024, 768);
hauptfenster.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
hauptfenster.setResizable(false);
hauptfenster.setLayout(null);
widerstand1 = new JComboBox[3];
for (int i = 0; i < 3; i++) {
widerstand1[i] = new JComboBox(dd[i]);
widerstand1[i].setSize(110,30);
widerstand1[i].setLocation(350 + 120 * i, 290);
hauptfenster.add(widerstand1[i]);
}
widerstand2 = new JComboBox[3];
for (int i = 0; i < 3; i++) {
widerstand2[i] = new JComboBox(dd[i]);
widerstand2[i].setSize(110,30);
widerstand2[i].setLocation(350 + 120 * i, 510);
hauptfenster.add(widerstand2[i]);
}
rechne = new JButton("Rechne");
rechne.setSize(100, 60);
rechne.setLocation(600, 600);
rechne.addActionListener( new ActionListener(){
@Override
public void actionPerformed(ActionEvent arg0) {
berechne();
}
});
ausgabe1 = new JLabel();
ausgabe1.setSize(180, 40);
ausgabe1.setForeground(Color.BLACK);
ausgabe1.setLocation(250, 390);
ausgabe2 = new JLabel();
ausgabe2.setSize(180, 40);
ausgabe2.setForeground(Color.BLACK);
ausgabe2.setLocation(250, 430);
ausgabe3 = new JLabel();
ausgabe3.setSize(180, 40);
ausgabe3.setForeground(Color.BLACK);
ausgabe3.setLocation(250, 470);
Farbwahl a = new Farbwahl();
Farbwahl b = new Farbwahl();
Farbwahl c = new Farbwahl();
Farbwahl d = new Farbwahl();
Farbwahl e = new Farbwahl();
Farbwahl f = new Farbwahl();
ring1 = new JLabel();
ring1.setSize(55, 110);
ring1.setIcon((Icon) a.Ausgabe((String)widerstand1[0].getSelectedItem()));
ring1.setLocation(425, 159);
ring2 = new JLabel();
ring2.setSize(55, 110);
ring2.setIcon((Icon) b.Ausgabe((String)widerstand1[1].getSelectedItem()));
ring2.setLocation(480, 159);
ring3 = new JLabel();
ring3.setSize(55, 110);
ring3.setIcon((Icon) c.Ausgabe((String)widerstand1[2].getSelectedItem()));
ring3.setLocation(535, 159);
ring4 = new JLabel();
ring4.setSize(55, 110);
ring4.setIcon((Icon) d.Ausgabe((String)widerstand2[0].getSelectedItem()));
ring4.setLocation(425, 383);
ring5 = new JLabel();
ring5.setSize(55, 110);
ring5.setIcon((Icon) e.Ausgabe((String)widerstand2[1].getSelectedItem()));
ring5.setLocation(480, 383);
ring6 = new JLabel();
ring6.setSize(55, 110);
ring6.setIcon((Icon) f.Ausgabe((String)widerstand2[2].getSelectedItem()));
ring6.setLocation(535, 383);
hauptfenster.add(rechne);
hauptfenster.add(ausgabe1);
hauptfenster.add(ausgabe2);
hauptfenster.add(ausgabe3);
hintergrund = new JLabel();
hintergrund.setSize(1024,768);
hintergrund.setIcon(new ImageIcon("background.jpg"));
hauptfenster.add(ring1);
hauptfenster.add(ring2);
hauptfenster.add(ring3);
hauptfenster.add(ring4);
hauptfenster.add(ring5);
hauptfenster.add(ring6);
hauptfenster.add(hintergrund);
hauptfenster.setVisible(true);
}
public void berechne(){
Widerstand y = new Widerstand();
Widerstand x = new Widerstand();
double d = x.Rechnung((String)widerstand1[0].getSelectedItem(), (String)widerstand1[1].getSelectedItem(), (String)widerstand1[2].getSelectedItem());
double e = y.Rechnung((String)widerstand1[0].getSelectedItem(), (String)widerstand1[1].getSelectedItem(), (String)widerstand1[2].getSelectedItem());
double f = d+e;
ausgabe2.setText("" + d);
ausgabe3.setText("" + e);
ausgabe1.setText("" + f);
}
public static void main(String[] args) {
Hauptprogramm hf = new Hauptprogramm();
}
}