CONTOH LOGIKA FUZZY JAVA 2

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package sisteminformasi;

/**
*
* @author Abbi
*/
import java.awt.*;
import java.applet.*;

public class Fuzzy extends Applet {

FuzzyNumber fuzz;

public void init() {

fuzz = new FuzzyNumber(0);

super.init();

//{{INIT_CONTROLS
setLayout(null);
resize(229,180);
label1=new Label(“Enter your age”);
add(label1);
label1.reshape(16,19,101,15);
editFuzzy=new TextField(9);
editFuzzy.setFont(new Font(“Courier”,Font.PLAIN,10));
add(editFuzzy);
editFuzzy.reshape(126,143,79,22);
label2=new Label(“Your fuzzy age is”);
add(label2);
label2.reshape(16,150,101,15);
editReal=new TextField(9);
editReal.setFont(new Font(“Courier”,Font.PLAIN,10));
add(editReal);
editReal.reshape(126,13,79,23);
label3=new Label(“0”);
label3.setFont(new Font(“Courier”,Font.PLAIN,10));
add(label3);
label3.reshape(9,113,23,20);
label4=new Label(“20”);
label4.setFont(new Font(“Courier”,Font.PLAIN,10));
add(label4);
label4.reshape(44,114,31,19);
label5=new Label(“50”);
label5.setFont(new Font(“Courier”,Font.PLAIN,10));
add(label5);
label5.reshape(100,114,30,19);
label6=new Label(“75”);
label6.setFont(new Font(“Courier”,Font.PLAIN,10));
add(label6);
label6.reshape(154,114,33,19);
//}}
}

/**
* Draw stuff
**/
public void paint( Graphics g )
{
fuzz.displayGraph(g);

}

public boolean handleEvent(Event event) {
if (event.id == Event.MOUSE_DRAG && event.target == this) {
mouseDownThis(event);
return true;
}
else
if (event.id == Event.KEY_RELEASE && event.target == editReal) {

keyReleaseReal(event);
return true;
}

return super.handleEvent(event);
}

//{{DECLARE_CONTROLS
Label label1;
TextField editFuzzy;
Label label2;
TextField editReal;
Label label3;
Label label4;
Label label5;
Label label6;
//}}

public void keyReleaseReal(Event ev) {

if (editReal.getText().length() != 0) {
Integer iField = new Integer( editReal.getText() );
int iValue = iField.intValue();

fuzz.setReal( iValue );

double dValue = fuzz.getFuzzyNum();
Double foo = new Double(dValue);
editFuzzy.setText( foo.toString() );

}

repaint();

}

/**
* Perhaps change the values of the grid thingies
**/
public void mouseDownThis(Event ev) {

// Make sure the click was in the b
if ( ev.y > 50 && ev.y < 100 ) {

// Setting the max right index
if (ev.y < 75 )
fuzz.setRightOne( (ev.x-20) / 2 );
else
fuzz.setLeftZero( (ev.x-20) / 2 );

// Calc the stuff (pass bogus event)
keyReleaseReal( new Event(new Object(), 5, new Object() ) );

// Show it
// repaint();
}
}
}

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s