jTables i wczytywanie macierzy

0

pisze program do mnozenia macierzy.
sa 3 okienka jTextArea (1-pierwsza macierz, 2-druga, 3 - wynik)
macierze wczytuje z 2 plikow.
wszystko pieknie dziala, ale chce zrobic aby te macierze wpisywaly sie w jTable...

chce zrobic do tego ProgressBar'a i tez nie wiem jak go powiazac

prosze o pomoc

pisze w Eclipsie

tu czesc kodu z jednym jTextArea i otworz

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class ramka extends JFrame {

    private JPanel jContentPane = null;

    private JButton jButton1 = null;

    private JScrollPane jScrollPane = null;

    private JTextArea jTextArea3 = null;

    double tab1[][];

    double tab2[][];

    /**
     * This method initializes jButton1
     * 
     * @return javax.swing.JButton
     */
    private JButton getJButton1() {
        if (jButton1 == null) {
            jButton1 = new JButton();
            jButton1.setBounds(new java.awt.Rectangle(30, 27, 78, 17));
            jButton1.setText("Otworz");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent e) {

                    int lw1 = 0;
                    int lk1 = 0;

                    JFileChooser jf = new JFileChooser();

                    if (jf.showOpenDialog(ramka.this) != jf.APPROVE_OPTION) {
                        return;
                    } else {
                        try {
                            File file = jf.getSelectedFile();
                            FileReader fr;

                            fr = new FileReader(file);

                            BufferedReader br = new BufferedReader(fr);

                            String wyn = new String("");
                            String s = null;

                            lw1 = 0;
                            while ((s = br.readLine()) != null) {

                                wyn += s + "\n";
                                lw1++;
                            }
                            System.out.println(lw1);

                            jTextArea3.setText(wyn);

                            br.close();
                            fr.close();
                        } catch (FileNotFoundException e1) {
                            // TODO Auto-generated catch block
                            e1.printStackTrace();
                        } catch (IOException e1) {
                            // TODO Auto-generated catch block
                            e1.printStackTrace();
                        }
                    }
                    File file_1 = jf.getSelectedFile();
                    FileReader fr;

                    try {
                        fr = new FileReader(file_1);
                        BufferedReader br = new BufferedReader(fr);

                        String s = br.readLine();
                        StringTokenizer st = new StringTokenizer(s);
                        lk1 = 0;

                        try {
                            while (st.nextToken() != null) {
                                lk1++;
                            }
                        } catch (Exception ee) {
                        ;
                        }
                        System.out.println("liczba kolumn: " + lk1);
                        br.close();
                        fr.close();
                    } catch (IOException eee) {
                        eee.printStackTrace();
                    }
                    tab1 = funkcja(file_1, lw1, lk1);
                    for (int i = 0; i < tab1.length; i++) {
                        for (int j = 0; j < tab1[0].length; j++) {
                            System.out.print(tab1[i][j] + "\t");
                        }
                        System.out.println();
                    }

                }
            });
        }
        return jButton1;
    }

    double[][] funkcja(File file, int lw, int lk) {
        double[][] wynik = new double[lw][lk];

        try {
            FileReader fr = new FileReader(file);
            BufferedReader br = new BufferedReader(fr);

            for (int i = 0; i < lw; i++) {
                String linia = br.readLine();
                StringTokenizer st = new StringTokenizer(linia);
                for (int j = 0; j < lk; j++) {
                    String s = st.nextToken();
                    System.out.print("element [" + i + "][" + j + "]=" + s
                            + "\t");
                    wynik[i][j] = Double.parseDouble(s);

                }
                System.out.println();
            }

            br.close();
            fr.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return wynik;
    }

    /**
     * This method initializes jScrollPane
     * 
     * @return javax.swing.JScrollPane
     */
    private JScrollPane getJScrollPane() {
        if (jScrollPane == null) {
            jScrollPane = new JScrollPane();
            jScrollPane.setBounds(new java.awt.Rectangle(26, 97, 103, 109));
            jScrollPane.setViewportView(getJTextArea3());
        }
        return jScrollPane;
    }

    /**
     * This method initializes jTextArea
     * 
     * @return javax.swing.JTextArea
     */

    private JTextArea getJTextArea3() {
        if (jTextArea3 == null) {
            jTextArea3 = new JTextArea();
        }
        return jTextArea3;
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        ramka r = new ramka();
        r.setLocation(50, 50);
        r.setVisible(true);

    }

    /**
     * This is the default constructor
     */
    public ramka() {
        super();
        initialize();
    }

    /**
     * This method initializes this
     * 
     * @return void
     */
    private void initialize() {
        this.setSize(316, 294);
        this.setTitle("JFrame");
        this.setContentPane(getJContentPane());
    }

    /**
     * This method initializes jContentPane
     * 
     * @return javax.swing.JPanel
     */
    private JPanel getJContentPane() {
        if (jContentPane == null) {
            jContentPane = new JPanel();
            jContentPane.setLayout(null);
            jContentPane.setBackground(new java.awt.Color(196, 210, 135));
            jContentPane.add(getJButton1(), null);
            jContentPane.add(getJScrollPane(), null);
        }
        return jContentPane;
    }

} // @jve:decl-index=0:visual-constraint="10,10"
0

nikt nie pomoze :|

0

Aby wyświetlić zapisaną w tablicy macierz tworząc JTable wywołujesz konstruktor JTable(Object[][] rowData, Object[] columnNames), czyli 2 wymiarowa tablica danych i 1 wymierowa tablica na nazwy kolumn. Jeśli chcesz mieć więcej możliwości powinieneś utworzyć model dla tabeli. Np tak jak tutaj: http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JTable.html ew tu http://javaalmanac.com - wiele przykładów do wszystkiego ;)

Do czego chcesz użyć progressBar'a i dlaczego uważasz, że nie wiesz jak to zrobic? Przecież wystarczy użyć odpowiedniej metody ;).

0

progressbara chce uzyc tylko i wylaczenie dla samego efektu ;)
mnozenie trwa na tyle krotko ze nie musialbym go uzywac, ale chce ;-P
po kliknieciu START mialby 'ruszyc'

1 użytkowników online, w tym zalogowanych: 0, gości: 1