بدي مستعمل يدخل معلومات و بعدين برنامج يضرب قيمة منتج في عدد منتج ثم يضعها في motantبعدين يجمع motant و يضعا في total
package hada;
import javax.swing.*;
import javax.swing.table.TableColumnModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
public class Test extends JFrame {
JLabel l,l1;JTable t,t1;Panel Tpanel;JButton b;
Test(){
l=new JLabel("Entreprise National des piéces/ 15 zone Rouiba/ Algérie",JLabel.LEFT);
l1=new JLabel("Facture",JLabel.RIGHT);
l.setFont(new Font("Ahmed",Font.PLAIN,20));
l1.setFont(new Font("Ahmed",Font.BOLD,30));
l.setVerticalAlignment(JLabel.TOP);
l1.setVerticalAlignment(JLabel.CENTER);
String titles[]= {"Référence","Produit","Quantité","Prix","Montant"};
String titles1[]= {"",""};
Object[][] data,data1;
data = new Object[3][5];
data1 = new Object[4][2];
Date d=new Date();
data1[0][0]="Némuro";data1[1][0]="Date";data1[2][0]="Nom Client";data1[1][1]=d;data1[3][0]="Prénom Client";
data[2][1]="Total";
t= new JTable(data,titles);
t1= new JTable(data1,titles1);
JScrollPane sp=new JScrollPane(t);
sp.getViewport().setViewPosition(new Point(0,0));
t.setRowHeight(25);
TableColumnModel columnModel = t1.getColumnModel();
columnModel.getColumn(1).setPreferredWidth(200);
columnModel.getColumn(1).setMaxWidth(200);
columnModel.getColumn(0).setPreferredWidth(120);
columnModel.getColumn(0).setMaxWidth(120);
JScrollPane sp1=new JScrollPane(t1);
sp1.getViewport().setViewPosition(new Point(0,0));
b=new JButton("save");
b.addActionListener((ActionListener) new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
FileWriter fileWriter = null;
try {
fileWriter = new FileWriter("ContactList.txt", true);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
PrintWriter outputFile = new PrintWriter(fileWriter);
outputFile.println(Tpanel);
outputFile.close();
}
});
Tpanel = new Panel();
Tpanel.add(l);
Tpanel.add(l1);
Tpanel.add(sp1);
Tpanel.add(sp);
Tpanel.add(b);
Tpanel.setLayout(new BoxLayout(Tpanel, BoxLayout.PAGE_AXIS));
add(Tpanel);
setTitle("Facture_ta3_jami3a");
setSize(700,700);
setVisible(true);
}
public static void main(String[] args) {
new Test();
} }