Matris işlemleri yapan applet
Aşağıdaki gibi bir matematiksel işlemi yapabilen Appleti gerçekleştiriniz.
Main.java
package matrix;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class Main extends Applet implements ActionListener {
Label l1 = new Label("1/1");
TextField m11 = new TextField(2);
Label l2 = new Label("1/2");
TextField m12 = new TextField(2);
Label l3 = new Label("1/3");
TextField m13 = new TextField(2);
Label l4 = new Label("1/4");
TextField m14 = new TextField(2);
//------------------------------------
TextField islem = new TextField(1);
//------------------------------------
Label l5 = new Label("1/1");
TextField m21 = new TextField(2);
Label l6 = new Label("1/2");
TextField m22 = new TextField(2);
Label l7 = new Label("1/3");
TextField m23 = new TextField(2);
Label l8 = new Label("1/4");
TextField m24 = new TextField(2);
//-------------------------------
Label l9 = new Label("1/1");
TextField s1 = new TextField(2);
Label l10 = new Label("1/2");
TextField s2 = new TextField(2);
Label l11 = new Label("1/3");
TextField s3 = new TextField(2);
Label l12 = new Label("1/4");
TextField s4 = new TextField(2);
Button hesapla = new Button("Hesapla");
public void init() {
add(l1);
add(m11);
add(l2);
add(m12);
add(l3);
add(m13);
add(l4);
add(m14);
add(islem);
add(l5);
add(m21);
add(l6);
add(m22);
add(l7);
add(m23);
add(l8);
add(m24);
add(hesapla);
hesapla.addActionListener(this);
add(l9);
add(s1);
add(l10);
add(s2);
add(l11);
add(s3);
add(l12);
add(s4);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == hesapla) {
if (islem.getText().equals("+")) {
s1.setText(Integer.toString(Integer.parseInt(m11.getText()) + Integer.parseInt(m21.getText())));
s2.setText(Integer.toString(Integer.parseInt(m12.getText()) + Integer.parseInt(m22.getText())));
s3.setText(Integer.toString(Integer.parseInt(m13.getText()) + Integer.parseInt(m23.getText())));
s4.setText(Integer.toString(Integer.parseInt(m14.getText()) + Integer.parseInt(m24.getText())));
} else if (islem.getText().equals("-")) {
s1.setText(Integer.toString(Integer.parseInt(m11.getText()) - Integer.parseInt(m21.getText())));
s2.setText(Integer.toString(Integer.parseInt(m12.getText()) - Integer.parseInt(m22.getText())));
s3.setText(Integer.toString(Integer.parseInt(m13.getText()) - Integer.parseInt(m23.getText())));
s4.setText(Integer.toString(Integer.parseInt(m14.getText()) - Integer.parseInt(m24.getText())));
} else if (islem.getText().equals("*")) {
s1.setText(Integer.toString(Integer.parseInt(m11.getText()) * Integer.parseInt(m21.getText())));
s2.setText(Integer.toString(Integer.parseInt(m12.getText()) * Integer.parseInt(m22.getText())));
s3.setText(Integer.toString(Integer.parseInt(m13.getText()) * Integer.parseInt(m23.getText())));
s4.setText(Integer.toString(Integer.parseInt(m14.getText()) * Integer.parseInt(m24.getText())));
} else if (islem.getText().equals("/")) {
s1.setText(Integer.toString(Integer.parseInt(m11.getText()) / Integer.parseInt(m21.getText())));
s2.setText(Integer.toString(Integer.parseInt(m12.getText()) / Integer.parseInt(m22.getText())));
s3.setText(Integer.toString(Integer.parseInt(m13.getText()) / Integer.parseInt(m23.getText())));
s4.setText(Integer.toString(Integer.parseInt(m14.getText()) / Integer.parseInt(m24.getText())));
}
}
}
}
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class Main extends Applet implements ActionListener {
Label l1 = new Label("1/1");
TextField m11 = new TextField(2);
Label l2 = new Label("1/2");
TextField m12 = new TextField(2);
Label l3 = new Label("1/3");
TextField m13 = new TextField(2);
Label l4 = new Label("1/4");
TextField m14 = new TextField(2);
//------------------------------------
TextField islem = new TextField(1);
//------------------------------------
Label l5 = new Label("1/1");
TextField m21 = new TextField(2);
Label l6 = new Label("1/2");
TextField m22 = new TextField(2);
Label l7 = new Label("1/3");
TextField m23 = new TextField(2);
Label l8 = new Label("1/4");
TextField m24 = new TextField(2);
//-------------------------------
Label l9 = new Label("1/1");
TextField s1 = new TextField(2);
Label l10 = new Label("1/2");
TextField s2 = new TextField(2);
Label l11 = new Label("1/3");
TextField s3 = new TextField(2);
Label l12 = new Label("1/4");
TextField s4 = new TextField(2);
Button hesapla = new Button("Hesapla");
public void init() {
add(l1);
add(m11);
add(l2);
add(m12);
add(l3);
add(m13);
add(l4);
add(m14);
add(islem);
add(l5);
add(m21);
add(l6);
add(m22);
add(l7);
add(m23);
add(l8);
add(m24);
add(hesapla);
hesapla.addActionListener(this);
add(l9);
add(s1);
add(l10);
add(s2);
add(l11);
add(s3);
add(l12);
add(s4);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == hesapla) {
if (islem.getText().equals("+")) {
s1.setText(Integer.toString(Integer.parseInt(m11.getText()) + Integer.parseInt(m21.getText())));
s2.setText(Integer.toString(Integer.parseInt(m12.getText()) + Integer.parseInt(m22.getText())));
s3.setText(Integer.toString(Integer.parseInt(m13.getText()) + Integer.parseInt(m23.getText())));
s4.setText(Integer.toString(Integer.parseInt(m14.getText()) + Integer.parseInt(m24.getText())));
} else if (islem.getText().equals("-")) {
s1.setText(Integer.toString(Integer.parseInt(m11.getText()) - Integer.parseInt(m21.getText())));
s2.setText(Integer.toString(Integer.parseInt(m12.getText()) - Integer.parseInt(m22.getText())));
s3.setText(Integer.toString(Integer.parseInt(m13.getText()) - Integer.parseInt(m23.getText())));
s4.setText(Integer.toString(Integer.parseInt(m14.getText()) - Integer.parseInt(m24.getText())));
} else if (islem.getText().equals("*")) {
s1.setText(Integer.toString(Integer.parseInt(m11.getText()) * Integer.parseInt(m21.getText())));
s2.setText(Integer.toString(Integer.parseInt(m12.getText()) * Integer.parseInt(m22.getText())));
s3.setText(Integer.toString(Integer.parseInt(m13.getText()) * Integer.parseInt(m23.getText())));
s4.setText(Integer.toString(Integer.parseInt(m14.getText()) * Integer.parseInt(m24.getText())));
} else if (islem.getText().equals("/")) {
s1.setText(Integer.toString(Integer.parseInt(m11.getText()) / Integer.parseInt(m21.getText())));
s2.setText(Integer.toString(Integer.parseInt(m12.getText()) / Integer.parseInt(m22.getText())));
s3.setText(Integer.toString(Integer.parseInt(m13.getText()) / Integer.parseInt(m23.getText())));
s4.setText(Integer.toString(Integer.parseInt(m14.getText()) / Integer.parseInt(m24.getText())));
}
}
}
}
Yorumunuzu Ekleyin