1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
import org.w3c.dom.views.AbstractView;
public class main {
public static void main(String[] args) {
JFrame frame = new mainFrame();
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
class mainFrame extends JFrame {
public mainFrame() {
setSize(500, 500);
TableModel model = new Investissement(30, 5, 10);
JTable table = new JTable(model);
add(new JScrollPane(table), BorderLayout.CENTER);
JPanel pane = new JPanel();
add(pane, BorderLayout.SOUTH);
final JTextField textfield = new JTextField();
textfield.setColumns(15);
pane.add(textfield);
JButton bouton = new JButton("Valider");
pane.add(bouton);
bouton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event) {
String sBalance = textfield.toString();
double balance = Double.valueOf(sBalance);
/*
* Mettre a jour la table ....
*/
}
});
}
}
class Investissement extends AbstractTableModel {
Investissement(int y, int r1, int r2) {
annee = y;
min = r1;
max = r2;
balance = 1000;
}
public int getRowCount() {
return annee;
}
public int getColumnCount() {
return (max - min + 1);
}
public void setBalance(int b) {
balance = b;
}
public Object getValueAt(int r, int c) {
double rate = ( c + min ) / 100.0;
double futureBalance = balance * Math.pow( 1 + rate, r );
return String.format("%.2f", futureBalance);
}
public String getColumnName(int c) {
return (c + min) + "%";
}
private int annee;
private int min;
private int max;
private int balance ;
} |