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"