Zkus tohle - je to naklikane behem 5ti minut, takze si s tim muzes vyhrat lepe. Hodnoty se zadavaji do JTable, po stisku tlacitka se obsah matice vypise na konzoli. Rozmery matice jsou v konstantach na zacatku. Pokud je tam chybny vstup, doplni se nula.

Kód:
/*
 * Qwert.java
 *
 * Created on 9. květen 2004, 10:24
 */

/**
 *
 * @author  user
 */
public class Qwert extends javax.swing.JDialog {
    private static final int COLS = 5;
    private static final int ROWS = 10;
    
    
    /** Creates new form Qwert */
    public Qwert(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        initComponents2();
    }
    
    private void initComponents2() {
        setupTable(ROWS,COLS);
    }
    
    protected int[][] createArray() {
        try {
            int rows = jTable1.getRowCount();
            int cols = jTable1.getColumnCount();
            
            int[][] ret = new int[rows][cols];
            for&#40;int i=0; i<rows; i++&#41;
                for&#40;int j=0; j<cols; j++&#41; &#123;
                    int value;
                    Object oValue = jTable1.getValueAt&#40;i,j&#41;;
                    try &#123;
                        value = &#40;oValue!=null&#41; ? Integer.parseInt&#40;jTable1.getValueAt&#40;i,j&#41;.toString&#40;&#41;&#41; &#58; 0;
                    &#125; catch &#40;NumberFormatException nfe&#41; &#123;
                        value = 0;
                    &#125;
                    ret&#91;i&#93;&#91;j&#93; = value;
                &#125;
            
            return ret;
        &#125; catch &#40;Exception e &#41; &#123;
            e.printStackTrace&#40;&#41;;
            return null;
        &#125;
    &#125;
    
    protected void test&#40;&#41; &#123;
        int&#91;&#93;&#91;&#93; matice = createArray&#40;&#41;;
        for&#40;int i=0; i<matice.length; i++&#41; &#123;
            int&#91;&#93; row = matice&#91;i&#93;;
            for&#40;int j=0; j<row.length; j++&#41; &#123;
                System.out.print&#40;row&#91;j&#93;+"|\t"&#41;;
            &#125;
            System.out.println&#40;""&#41;;
        &#125;
    &#125;
    
    protected void setupTable&#40;int _rows, int _cols&#41; &#123;
        Object&#91;&#93;&#91;&#93; aoData = new Object&#91;_rows&#93;&#91;_cols&#93;;
        String&#91;&#93; aCols = new String&#91;_cols&#93;;
        for&#40;int i=0; i<_cols; i++&#41; aCols&#91;i&#93; = Integer.toString&#40;i&#41;;
        jTable1.setModel&#40;new javax.swing.table.DefaultTableModel&#40;
        aoData,
        aCols
        &#41;&#41;;
    &#125;
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING&#58; Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents&#40;&#41; &#123;
        jPanel1 = new javax.swing.JPanel&#40;&#41;;
        jButton1 = new javax.swing.JButton&#40;&#41;;
        jScrollPane1 = new javax.swing.JScrollPane&#40;&#41;;
        jTable1 = new javax.swing.JTable&#40;&#41;;

        addWindowListener&#40;new java.awt.event.WindowAdapter&#40;&#41; &#123;
            public void windowClosing&#40;java.awt.event.WindowEvent evt&#41; &#123;
                closeDialog&#40;evt&#41;;
            &#125;
        &#125;&#41;;

        jPanel1.setLayout&#40;new java.awt.FlowLayout&#40;java.awt.FlowLayout.RIGHT&#41;&#41;;

        jButton1.setText&#40;"nacti"&#41;;
        jButton1.addActionListener&#40;new java.awt.event.ActionListener&#40;&#41; &#123;
            public void actionPerformed&#40;java.awt.event.ActionEvent evt&#41; &#123;
                jButton1ActionPerformed&#40;evt&#41;;
            &#125;
        &#125;&#41;;

        jPanel1.add&#40;jButton1&#41;;

        getContentPane&#40;&#41;.add&#40;jPanel1, java.awt.BorderLayout.NORTH&#41;;

        jScrollPane1.setViewportView&#40;jTable1&#41;;

        getContentPane&#40;&#41;.add&#40;jScrollPane1, java.awt.BorderLayout.CENTER&#41;;

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit&#40;&#41;.getScreenSize&#40;&#41;;
        setBounds&#40;&#40;screenSize.width-200&#41;/2, &#40;screenSize.height-250&#41;/2, 200, 250&#41;;
    &#125;
    
    private void jButton1ActionPerformed&#40;java.awt.event.ActionEvent evt&#41; &#123;
        // Add your handling code here&#58;
        test&#40;&#41;;
    &#125;
    
    /** Closes the dialog */
    private void closeDialog&#40;java.awt.event.WindowEvent evt&#41; &#123;
        //setVisible&#40;false&#41;;
        System.exit&#40;0&#41;;
    &#125;
    
    /**
     * @param args the command line arguments
     */
    public static void main&#40;String args&#91;&#93;&#41; &#123;
        new Qwert&#40;new javax.swing.JFrame&#40;&#41;, true&#41;.show&#40;&#41;;
    &#125;
    
    
    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration    
&#125;