Witam, znalazłem taki kod programu, który wylicza wyznacznik macierzy, lecz gdy chcę go uruchomić to wyskakuje mi że nie może znaleźć klasy Main, mógłby mi ktoś powiedzieć gdzie i jak mam ją dodać?
Z góry wielkie dzięki za pomoc ;)
package wyznacznik;
/*
* Wyznacznik macierzy
*
* autor: Bartosz Lewandowski
*
* Instrukcja:
* Po podaniu rozmiaru macierzy nalezy przycisk Generuj aby utworzyc
* grida do wprowadzania wartosci elementow macierzy.
* Wartosci bledne lub puste beda zinterpretowane jako 0.
*
* Po wybraniu opcji Licz zostanie wyswietlony wyznacznik macierzy.
*/
import java.applet.Applet;
import java.awt.Color;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
public class Det extends Applet implements ActionListener{
private static final long serialVersionUID = 1L;
JTable table;
JButton btnGen = new JButton("Generuj");
JButton btnLicz = new JButton("Licz");
JTextField txt = new JTextField(5);
float matrix[][];
public void init()
{
this.setSize(460,300);
this.setLayout(null);
JLabel l = new JLabel("Iloć wierszy");
this.add(l);
txt.setText("5");
this.add(txt);
this.add(btnGen);
this.add(btnLicz);
//podlaczenie listeneera do buttonow
btnGen.addActionListener(this);
btnLicz.addActionListener(this);
l.setBounds(10, 20, 400, 24);
btnGen.setBounds(100,50,95,18);
btnLicz.setBounds(200,50,95,18);
txt.setBounds(20,50,80,18);
}
public void initMatrix()
{
int rowsColsCount;
//gdy ilosc kolumn nie jest liczba to zakladamy 5
try {
rowsColsCount = Integer.valueOf(txt.getText());
} catch (Exception e) {
rowsColsCount = 5;
}
matrix = new float[rowsColsCount][rowsColsCount];
if (table!=null) this.remove(table);
DefaultTableModel model = new DefaultTableModel(rowsColsCount,rowsColsCount);
table = new JTable(model);
table.setShowGrid(true);
table.setBorder(BorderFactory.createLineBorder(Color.black));
table.setBounds(new Rectangle(40,80,rowsColsCount*25,rowsColsCount*25));
table.setRowHeight(25);
TableColumn column;
for (int a=0;a<table.getColumnCount();a++)
{
column = table.getColumnModel().getColumn(a);
column.setWidth(25);
}
this.add(table);
this.repaint();
}
//obliczenie wyznacznika macierzy
public float det(float[][] matrix, int dim) {
float buffer[][];
float result = 0;
if (dim == 1)
{
return matrix[0][0];
}
else
{
buffer = new float[dim - 1][dim - 1];
for (int a = 0; a < dim; a++)
{
for (int b = 0; b < dim - 1; b++)
{
for (int k = 0; k < dim - 1; k++)
{
if (k<a)
{
buffer[b][k] = matrix[b + 1][k];
}
else
{
buffer[b][k] = matrix[b + 1][k+1];
}
}
}
if (a % 2 == 0) //minory (znak) i obliczenie kolejnej macierzy
{
result += matrix[0][a] * det(buffer, dim - 1);
}
else
{
result -= matrix[0][a] * det(buffer, dim - 1);
}
}
return result;
}
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource()==btnGen)
{
this.initMatrix();
}
if (e.getSource()==btnLicz)
{
for (int a=0;a<matrix.length;a++)
{
for (int b=0;b<matrix.length;b++)
{
//wartosci domyslne (gdy nie ma liczby to zero)
float value =0;
try {
value = Float.valueOf(table.getValueAt(a, b).toString());
} catch (Exception ex) {
value = 0;
table.setValueAt("0", a,b);
}
matrix[a][b] = value;
}
}
try {
JOptionPane.showMessageDialog(this,"Wyznacznik macierzy wynosi: "+det(matrix,matrix.length),"Info",1);
} catch (Exception e2)
{
JOptionPane.showMessageDialog(this,"Nie można obliczyć wyznacznika.","Błšd",1);
}
}
}
}