Aufgabe1
Logische Verknuepfung
“EXOR”
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class exor extends
Applet
{
// private Klasse objekt;
private Und und1;
private Oder oder1;
private Oder oder2;
private Nicht nicht1;
private Nicht nicht2;
boolean a,b;
TextArea
textArea1 = new TextArea();
public
void init()
{ try
{jbInit();}
catch(Exception
e)
{e.printStackTrace();}
}
private
void jbInit() throws Exception
{
this.setLayout(null);
this.setBackground(Color.white);
textArea1.setBounds(new
Rectangle(274, 6, 179, 193));
textArea1.setFont(new
java.awt.Font("Dialog", 0, 14));
// objekt1 = new Klasse();
und1 = new
Und();
oder1 = new
Oder();
oder2 = new
Oder();
nicht1 = new
Nicht();
nicht2 = new
Nicht();
this.add(textArea1, null);
}
public void
paint(Graphics g)
{
// g.drawImage(getImage (getDocumentBase(),"Name
des Bildes"),x,y,Breite,Hoehe,this);
g.drawImage(getImage (getDocumentBase(),"gemSchalt1.jpg"),0,0,260,205,this);
verarbeiten();
}
private void
berechnen(){
// Anweisungen;
oder1.setE1(a);
oder1.setE2(b);
nicht1.setE1(a);
nicht2.setE1(b);
oder2.setE1(nicht1.getA());
oder2.setE2(nicht2.getA());
und1.setE1(oder1.getA());
und1.setE2(oder2.getA());
}
private void
verarbeiten(){
textArea1.setText(" Konjunktve Normalform
\n");
textArea1.append("
--------------------------- \n");
textArea1.append(" B
A Y \n");
a=false;
b=false;
berechnen();
textArea1.append("\n false false =
"+und1.getA());
a=true;
b=false;
berechnen();
textArea1.append("\n false true =
"+und1.getA());
a=false;
b=true;
berechnen();
textArea1.append("\n true false =
"+und1.getA());
a=true;
b=true;
berechnen();
textArea1.append("\n true true =
"+und1.getA());
}
}
-----------------------------------------------------------------------------------------------------------------
Klasse Nicht
public class Nicht
{
private
boolean e1,a;
public Nicht() {
e1 = a = false;
}
public
void setE1( boolean wert ) {
e1 = wert;
a =
!e1;
}
public boolean getA() {
return
a;
}
public boolean getE1() {
return e1;
}}
-----------------------------------------------------------------------------------------------------------------
Klasse Oder
public class Oder{
private
boolean e1,e2,a;
public
Oder() {
e1 = e2 = a = false;
}
public
void setE1( boolean wert ) {
e1 = wert;
a = e1 || e2;
}
public
void setE2( boolean wert ) {
e2 = wert;
a = e1 || e2;
}
public boolean getA() {
return
a;
}
public boolean getE1() {
return
e1;
}
public boolean getE2() {
return
e2;
}}
Klasse Und
public class Und{
private boolean e1,e2,a;
public
Und() {
e1 = e2 = a = false;
}
public
void setE1( boolean wert ) {
e1 = wert;
a = e1 && e2;
}
public
void setE2( boolean wert ) {
e2 = wert;
a = e1 && e2;
}
public boolean getA() {
return
a;
}
public boolean getE1() {
return
e1;
}
public boolean getE2() {
return
e2;
}}
Aufgabe2 Logische Verknuepfung
“EXOR”
(Klassen wie Aufgabe 1)
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class exor extends
Applet
{
// private Klasse objekt;
private Und und1;
private Oder oder1;
private Oder oder2;
private Nicht nicht1;
private Nicht nicht2;
boolean a=false,b=false;
TextArea
textArea1 = new TextArea();
Button aa
= new Button();
Button bb = new Button();
Label yy
= new Label();
public
void init()
{ try
{jbInit();}
catch(Exception
e)
{e.printStackTrace();}
}
private
void jbInit() throws Exception
{
this.setLayout(null);
this.setBackground(Color.white);
textArea1.setBounds(new
Rectangle(274, 6, 179, 193));
textArea1.setFont(new
java.awt.Font("Dialog", 0, 14));
// objekt1 = new Klasse();
und1 = new
Und();
oder1 = new
Oder();
oder2 = new
Oder();
nicht1 = new
Nicht();
nicht2 = new
Nicht();
aa.setBackground(Color.red);
aa.setLabel(" 0");
aa.setBounds(new
Rectangle(2, 156, 30, 27));
aa.addActionListener(new exor_aa_actionAdapter(this));
bb.setBackground(Color.red);
bb.setLabel(" 0");
bb.setBounds(new
Rectangle(46, 156, 31, 27));
bb.addActionListener(new exor_bb_actionAdapter(this));
yy.setBackground(Color.red);
yy.setText("0");
yy.setBounds(new
Rectangle(226, 64, 32, 27));
this.add(textArea1, null);
this.add(bb, null);
this.add(aa,
null);
this.add(yy,
null);
}
public
void paint(Graphics g)
{
// g.drawImage(getImage (getDocumentBase(),"Name
des Bildes"),x,y,Breite,Hoehe,this);
g.drawImage(getImage (getDocumentBase(),"gemSchalt1.jpg"),0,0,260,205,this);
// verarbeiten();
}
private void
berechnen(){
// Anweisungen;
oder1.setE1(a);
oder1.setE2(b);
nicht1.setE1(a);
nicht2.setE1(b);
oder2.setE1(nicht1.getA());
oder2.setE2(nicht2.getA());
und1.setE1(oder1.getA());
und1.setE2(oder2.getA());
}
private void
verarbeiten(){
textArea1.setText(" Konjunktve Normalform
\n");
textArea1.append("
--------------------------- \n");
textArea1.append(" B
A Y \n");
berechnen();
textArea1.append("\n "+b+" "+a+" =
"+und1.getA());
}
void aa_actionPerformed(ActionEvent e)
{
a=!a;
berechnen();
verarbeiten();
if(und1.getA()==true){
yy.setBackground(Color.green);
yy.setText(" 1");
}
else{
yy.setBackground(Color.red);
yy.setText(" 0");
}
if(a==true){
aa.setBackground(Color.green);
aa.setLabel(" 1");
}
else{
aa.setBackground(Color.red);
aa.setLabel(" 0");
}
}
void bb_actionPerformed(ActionEvent e)
{
b=!b;
berechnen();
verarbeiten();
if(und1.getA()==true){
yy.setBackground(Color.green);
yy.setText(" 1");
}
else{
yy.setBackground(Color.red);
yy.setText(" 0");
}
if(b==true){
bb.setBackground(Color.green);
bb.setLabel(" 1");
}
else{
bb.setBackground(Color.red);
bb.setLabel(" 0");
}
}
}
class exor_aa_actionAdapter
implements java.awt.event.ActionListener {
exor adaptee;
exor_aa_actionAdapter(exor adaptee) {
this.adaptee
= adaptee;
}
public
void actionPerformed(ActionEvent
e) {
adaptee.aa_actionPerformed(e);
}
}
class exor_bb_actionAdapter
implements java.awt.event.ActionListener {
exor adaptee;
exor_bb_actionAdapter(exor adaptee) {
this.adaptee
= adaptee;
}
public
void actionPerformed(ActionEvent
e) {
adaptee.bb_actionPerformed(e);
}
}