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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
| package windows;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import button.ButtonClientEditor;
import button.ButtonClientRenderer;
import database.Connexion;
@SuppressWarnings("serial")
public class MainMenu extends JFrame
{
private JMenuBar menuBar = new JMenuBar();
private JMenu general = new JMenu("Général");
private JMenuItem pref = new JMenuItem("Préférence");
private JMenuItem crclient = new JMenuItem("Créer Client");
private JMenuItem editclient = new JMenuItem("Editer Client");
private JMenuItem fermer = new JMenuItem("Fermer");
private JSplitPane split;
private JTable tableau;
JPanel clientlistside = new JPanel();
JPanel fact = new JPanel();
Connexion connexion;
MainMenu menu = this;
Object [][] clientlist = new Object [999][1];
String [] nomcolonne = {"Clients"};
public MainMenu(Connexion connect)
{
connexion = connect;
createMenu();
createSplit();
}
private void createMenu()
{
this.setTitle("logiciel facturation");
Dimension dimension = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
int height = (int)dimension.getHeight();
int width = (int)dimension.getWidth();
this.setSize(width, height);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.general.add(pref);
this.general.add(crclient);
this.general.add(editclient);
this.general.addSeparator();
pref.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
new Preferences(null, "Préférences", true);
}
}
);
fermer.addActionListener(new ActionListener()
{
@SuppressWarnings("static-access")
public void actionPerformed(ActionEvent arg0)
{
JOptionPane jop = new JOptionPane();
int option = jop.showConfirmDialog(null, "Êtes-vous sur de vouloir quitter?", "Fermeture", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if(option == JOptionPane.OK_OPTION){
System.exit(0);
}
}
}
);
crclient.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
new CreateClient(null, "Création d'un client", true, connexion, menu );
}
}
);
editclient.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
new EditClient(null, "Edition d'un client", true, connexion, menu, "test");
}
}
);
this.general.add(fermer);
this.menuBar.add(general);
this.setJMenuBar(menuBar);
}
private void createSplit()
{
ResultSet resultSet = connexion.query("SELECT * FROM CLIENT");
try {
for (int i=0;resultSet.next();i++)
{
clientlist[i][0]= new String (resultSet.getString("nomcli"));
}
}
catch (SQLException e)
{
e.printStackTrace();
}
this.tableau = new JTable(clientlist, nomcolonne);
tableau.getColumn("Clients").setCellRenderer(new ButtonClientRenderer());
tableau.getColumn("Clients").setCellEditor(new ButtonClientEditor(new JCheckBox()));
tableau.setSelectionBackground(Color.cyan);
fact.setBackground(Color.red);
JScrollPane scrollbar = new JScrollPane(tableau);
clientlistside.add(scrollbar);
split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, clientlistside, fact);
split.setDividerLocation(150);
this.getContentPane().add(split, BorderLayout.CENTER);
this.setVisible(true);
}
public void refreshClientList(String newclient)
{
ResultSet resultSet = connexion.query("SELECT * FROM CLIENT");
int i = -1;
try {
while (resultSet.next())
{
i++;
}
}
catch (SQLException e)
{
e.printStackTrace();
}
clientlist [i][0] = newclient;
this.getContentPane().remove(split);
split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, tableau, fact);
split.setDividerLocation(150);
this.getContentPane().add(split, BorderLayout.CENTER);
this.setVisible(true);
}
} |
Partager