// Copyright 哲猫. /* 行列式*/ /* */ import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Ex061021b extends JApplet implements ActionListener{ JTextField tf1[][] = new JTextField[3][3]; JButton bt; JLabel lb,lba; /* nMatrix インスタンスをinit()内で宣言しても、各要素は広域変数とはならない。 */ nMatrix m1 = new nMatrix(3,3); public void init(){ Container cp = getContentPane(); JPanel pl = new JPanel(); pl.setLayout(null); pl.setBackground(Color.white); lba = new JLabel("A="); lba.setBounds(5,5,25,20); pl.add(lba); for(int i=0;i<3;i++) for(int j=0;j<3;j++){ tf1[i][j] = new JTextField(10); tf1[i][j].setText("0.0"); tf1[i][j].setBounds(25+60*j,5+30*i,50,20); pl.add(tf1[i][j]); } bt = new JButton("det(A)"); bt.setBounds(30,100,120,20); bt.addActionListener(this); pl.add(bt); lb = new JLabel(""); lb.setBounds(20,120,200,30); pl.add(lb); cp.add(pl); } public void actionPerformed(ActionEvent event){ String s=new String(); double val=0.0; String str = new String(); if(event.getSource()==bt){ for(int i=0;i<3;i++) for(int j=0;j<3;j++){ s=tf1[i][j].getText(); val=Double.valueOf(s).doubleValue(); m1.set(i,j,val); } lb.setText("= "+nMatrix.det(m1)); } } }