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