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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
|
public class Fenetre extends JFrame {
protected JScrollPane scroll; // mais c ce scrollPane qu'il faut afficher et non la jtable, puisqu'il la contient(la JTable), je l'ai déjà fait dans menuPrinc
private Connection con;
public Fenetre() {
super();
scroll = new JScrollPane();
try
{
con = DriverManager.getConnection(
"jdbc:oracle:thin:@134.214.112.67:1521:orcl","p1603697","267785");
}catch(SQLException e){}
build();
}
public void build()
{
setTitle("Scoring League Of Legend");
setContentPane(content());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
pack();
setVisible(true);
}
public JTabbedPane content()
{
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.setBackground(Color.LIGHT_GRAY);
tabbedPane.setPreferredSize(new Dimension(1000, 700));
tabbedPane.addTab("Menu principal", MenuPrinc());
tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);
tabbedPane.addTab("Ajouter joueur",ajouter());
tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);
tabbedPane.addTab("Lancer partie",lancerPartie());
tabbedPane.setMnemonicAt(2, KeyEvent.VK_3);
tabbedPane.addTab("Statistiques", stat());
tabbedPane.setMnemonicAt(3, KeyEvent.VK_4);
//The following line enables to use scrolling tabs.
tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
return tabbedPane;
}
public JPanel MenuPrinc(){ // ne plus toucher
JPanel panel = new JPanel();
panel.setBackground(Color.LIGHT_GRAY);
JPanel panelbouton = new JPanel();
panelbouton.setBackground(Color.LIGHT_GRAY);
scroll.setPreferredSize(new Dimension(550,600));
JButton mmr = new JButton("Afficher joueurs triés par MMR");
JButton role = new JButton("Afficher joueurs triés par rôle");
JButton afficher = new JButton("Afficher champions");
panelbouton.setLayout(new GridLayout(3,1,20,20));
panel.setLayout(new FlowLayout(5,30,30)/*new BorderLayout(10,10)*/);
panelbouton.add(mmr);
panelbouton.add(role);
panelbouton.add(afficher);
//paneltable.setBorder(BorderFactory.createLineBorder(Color.BLACK));
panel.add(scroll);
panel.add(panelbouton);
mmr.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e)
{
String requete = "select * from Joueur order by mmr desc";
JTable table = new JTable(requete(con,requete));
scroll = new JScrollPane(table);
build();
};
});
return panel;
}
public JPanel ajouter()
{
JPanel label = new JPanel();
JLabel Pseudo = new JLabel("Pseudo");
JLabel Mmr = new JLabel("MMR");
JLabel Main = new JLabel("Rank");
label.add(Pseudo);
label.add(Mmr);
label.add(Main);
//label.setLayout(new FlowLayout());
JPanel tf = new JPanel();
JTextField Pseudotf = new JTextField(" ");
JTextField Mmrtf = new JTextField(" ");
JTextField Maintf = new JTextField(" ");
tf.add(Pseudotf);
tf.add(Mmrtf);
tf.add(Maintf);
//tf.setLayout(new FlowLayout());
JPanel bt = new JPanel();
JButton ajouterjoueur = new JButton("Ajouter joueur");
bt.add(ajouterjoueur);
JPanel condense = new JPanel();
condense.add(label);
condense.add(tf);
condense.setLayout(new GridLayout(3, 2));
JPanel panel = new JPanel();
panel.add(condense);
panel.add(ajouterjoueur);
return panel;
}
public JPanel lancerPartie(){
JPanel panel = new JPanel();
JLabel info = new JLabel("Label");
panel.add(info);
setVisible(true);
return panel;
}
public JPanel stat()
{
JPanel label = new JPanel();
JLabel Main = new JLabel("Main : ");
JLabel Mainvalue = new JLabel("null");
JLabel nombre = new JLabel("Nombre de partie(s) jouées :");
JLabel nombrevalue = new JLabel("null");
JLabel pourcent = new JLabel("Pourcentage de victoire :");
JLabel pourcentvalue = new JLabel("null");
label.add(Main);
label.add(Mainvalue);
label.add(nombre);
label.add(nombrevalue);
label.add(pourcent);
label.add(pourcentvalue);
label.setLayout(new GridLayout(3, 2));
JPanel combo = new JPanel();
Object[] liste = new Object[]{"Sélectionner joueur","Mettre array list nom joueur"};
JComboBox selectjoueur = new JComboBox(liste);
combo.add(selectjoueur);
//combo.setLayout(new GridLayout(1,1));
//Avec grid layout le bouton est énorme
JPanel panel = new JPanel();
setBackground(Color.orange);
panel.add(combo);
panel.add(label);
panel.setLayout(new GridLayout(6,1));
setVisible(true);
return panel;
}
public ModeleDonnee requete(Connection con,String requête) // retourne une instance de ModeleDonnee
{
Statement stmt;
ResultSet rs;
ResultSetMetaData rsMeta;
String []nom = null ;
Object [][]colonnes = new Object[0][0];
ModeleDonnee mod;
try
{
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
rs = stmt.executeQuery(requête);
rsMeta = rs.getMetaData();
nom = new String[rsMeta.getColumnCount()];// On initialise notre tableau de nom de colonnes
for(int i = 1; i <= rsMeta.getColumnCount(); i++) // On recupère les nom des colonnes
{
nom[i-1] = rsMeta.getColumnName(i).toUpperCase();
//System.out.printf("%s ",nom[i-1]);
}
rs.last(); // on place le curseur à la fin
int nombreLignes = rs.getRow(); //on récupère le numéro de la ligne
rs.beforeFirst(); //on replace le curseur avant la première ligne
int nombreColonnes = rsMeta.getColumnCount();
//System.out.println("Nombre de ligne(s) : "+nombreLignes+"\n"+"Nombre de colonne(s) : "+rsMeta.getColumnCount());
colonnes = new Object[nombreLignes][nombreColonnes];
//colonnes = new String[nombreLignes-1][nombreColonnes-1];
while(rs.next())
{
Object obj[] = new Object[nombreColonnes];
for(int i = 0 ; i < nombreColonnes ; i++)
{
obj[i] = rs.getObject(i+1);
}
for(int el = 0 ; el < nombreColonnes ; el++)
{
colonnes [rs.getRow()-1][el] = obj[el];
}
}
stmt.close();
rs.close();
}catch(Exception e){}
mod = new ModeleDonnee(nom, colonnes);
if(mod == null)
return null;
else
return mod;
}
public static void main (String[]arg)
{
new Fenetre();
}
} |