Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package my.project;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.EditText;
- import android.widget.Button;
- import android.widget.TextView;
- import java.lang.String;
- import java.util.regex.*;
- public class ComplexConverter extends Activity {
- private ComplexA complexA;
- private ComplexE complexE;
- private Pattern p;
- private Matcher m;
- private double a;
- private boolean isAlg(String str) {
- p = Pattern.compile("(\\d+)[+-]i(\\d+)",
- Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE);
- m = p.matcher(str);
- a = Double.parseDouble(m.group(1));
- return m.matches();
- }
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- complexA = new ComplexA();
- complexE = new ComplexE();
- final EditText edit = (EditText) findViewById(R.id.edit);
- Button button = (Button) findViewById(R.id.button);
- final TextView text = (TextView) findViewById(R.id.text);
- button.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- if (isAlg(edit.getText().toString())) {
- text.setText(Double.toString(a));
- }
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement