Hallo Leute,
da ich ein blutiger Anfänger bin habe ich folgendes Problem, und zwar will ich in meinem Programm mit 5 verschiedenen Buttons 5 verschiedene Bilder aufrufen. Das heißt wenn ich Button1 anklicke soll Bild1 neben dem Button geladen werden, beim anklicken von Button2 soll statt Bild1 das Bild2 geladen werden. Die Position des Bildes ist -"komp.png"-, welche ich zum testen reingemacht habe.
Bitte helft mir, bin schon langsam am verzweifeln.
hier ist das Programm:
da ich ein blutiger Anfänger bin habe ich folgendes Problem, und zwar will ich in meinem Programm mit 5 verschiedenen Buttons 5 verschiedene Bilder aufrufen. Das heißt wenn ich Button1 anklicke soll Bild1 neben dem Button geladen werden, beim anklicken von Button2 soll statt Bild1 das Bild2 geladen werden. Die Position des Bildes ist -"komp.png"-, welche ich zum testen reingemacht habe.
Bitte helft mir, bin schon langsam am verzweifeln.
hier ist das Programm:
Code:
import java.awt.*;
import java.applet.*;
public class Operationsverstärker extends Applet
{
/*****************ATTRIBUTE**************/
/* Erzeugen des Objektes fuer Ue1 und Ue2 */
TextField Textfeld_Ue1 = new TextField("0");
TextField Textfeld_Ue2 = new TextField("0");
/* Funktionsgenerator */
Label Funktion1 = new Label();
Label Funktion2 = new Label();
Label Funktion3 = new Label();
Label Funktion4 = new Label();
Label Funktion5 = new Label();
Label Funktion6 = new Label();
Label Funktion7 = new Label();
/* OP-Schaltungsarten */
Label Schalt1 = new Label();
Button Bkomp = new Button ("Komparator");
Button Biverstaerker = new Button ("IVerstaerker");
Button Bniverstaerker = new Button ("NIVerstaerker");
Button Baddierer = new Button ("Addierer");
Button Bsubtrahierer = new Button ("Subtrahierer");
/* Bilder */
Image komp;
Image iverstaerker;
Image niverstaerker;
Image addierer;
Image subtrahierer;
Image osi;
/**************METHODEN******************/
/**Methode init()**/
public void init()
{
/*Definieren der Applet Grundfläche*/
setLayout(null);
setBackground(new Color(220,220,220));
setSize(600,600);
/* Textfeld_Ue1 */
Textfeld_Ue1.setFont(new Font("Dialog", Font.PLAIN, 12));
Textfeld_Ue1.setBounds(55,120,40,20);
add(Textfeld_Ue1);
/* Textfeld_Ue2 */
Textfeld_Ue2.setFont(new Font("Dialog", Font.PLAIN, 12));
Textfeld_Ue2.setBounds(225,120,40,20);
add(Textfeld_Ue2);
/* OP-Schaltungsarten*/
Bkomp.setFont(new Font("Dialog", Font.PLAIN, 12));
Bkomp.setBounds(100,350,80,20);
add(Bkomp);
Biverstaerker.setFont(new Font("Dialog", Font.PLAIN, 12));
Biverstaerker.setBounds(100,390,80,20);
add(Biverstaerker);
Bniverstaerker.setFont(new Font("Dialog", Font.PLAIN, 12));
Bniverstaerker.setBounds(100,430,80,20);
add(Bniverstaerker);
Baddierer.setFont(new Font("Dialog", Font.PLAIN, 12));
Baddierer.setBounds(100,470,80,20);
add(Baddierer);
Bsubtrahierer.setFont(new Font("Dialog", Font.PLAIN, 12));
Bsubtrahierer.setBounds(100,510,80,20);
add(Bsubtrahierer);
}
/** Grafische Elemente der Benutzeroberflaeche */
public void paint(Graphics g)
{
/* Abgrenzung der Bereiche */
g.setColor(Color.blue);
g.fillRect(10,300,580,1);
g.fillRect(300,10,1,580);
/* Funktionsgenerator */
Funktion1.setText("Funktionsgenerator");
Funktion1.setAlignment(Label.CENTER);
Funktion1.setForeground(Color.red);
Funktion1.setFont(new Font("Dialog", Font.BOLD, 15));
Funktion1.setBounds(65,10,150,16);
add(Funktion1);
Funktion2.setText("Ue1");
Funktion2.setAlignment(Label.LEFT);
Funktion2.setForeground(Color.black);
Funktion2.setFont(new Font("Dialog", Font.BOLD, 15));
Funktion2.setBounds(50,80,30,16);
add(Funktion2);
Funktion3.setText("Ue2");
Funktion3.setAlignment(Label.LEFT);
Funktion3.setForeground(Color.black);
Funktion3.setFont(new Font("Dialog", Font.BOLD, 15));
Funktion3.setBounds(220,80,30,16);
add(Funktion3);
Funktion4.setText("Wert:");
Funktion4.setAlignment(Label.LEFT);
Funktion4.setForeground(Color.black);
Funktion4.setFont(new Font("Dialog", Font.BOLD, 12));
Funktion4.setBounds(10,120,60,13);
add(Funktion4);
Funktion5.setText("Wert:");
Funktion5.setAlignment(Label.LEFT);
Funktion5.setForeground(Color.black);
Funktion5.setFont(new Font("Dialog", Font.BOLD, 12));
Funktion5.setBounds(180,120,60,13);
add(Funktion5);
Funktion6.setText("Gleichspannung");
Funktion6.setAlignment(Label.LEFT);
Funktion6.setForeground(Color.black);
Funktion6.setFont(new Font("Dialog", Font.BOLD, 11));
Funktion6.setBounds(10,180,100,12);
add(Funktion6);
Funktion7.setText("Wechselspannung");
Funktion7.setAlignment(Label.LEFT);
Funktion7.setForeground(Color.black);
Funktion7.setFont(new Font("Dialog", Font.BOLD, 11));
Funktion7.setBounds(10,210,110,12);
add(Funktion7);
/* OP-Schaltungsarten*/
Schalt1.setText("OP-Schaltungsarten");
Schalt1.setAlignment(Label.CENTER);
Schalt1.setForeground(Color.red);
Schalt1.setFont(new Font("Dialog", Font.BOLD, 15));
Schalt1.setBounds(65,310,150,16);
add(Schalt1);
/* Einfügen der Bilder */
komp = getImage(getCodeBase(),"komp.png");
g.drawImage(komp,310,10,this);
komp = getImage(getCodeBase(),"osi.gif");
g.drawImage(komp,310,310,this);
}
}