IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

AWT/Swing Java Discussion :

paginnation suivant / precedent


Sujet :

AWT/Swing Java

  1. #1
    Membre à l'essai
    Inscrit en
    Mars 2010
    Messages
    20
    Détails du profil
    Informations forums :
    Inscription : Mars 2010
    Messages : 20
    Points : 21
    Points
    21
    Par défaut paginnation suivant / precedent
    bonjour j ai besoin d afficher des items de ma table oracle 15 par fenetre mais j ai des difficulte au niveau de l affichage
    voila le code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
     
    package search;
     
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.Insets;
    import java.awt.LayoutManager;
    import java.awt.Point;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.ArrayList;
     
    import javax.swing.AbstractButton;
    import javax.swing.BorderFactory;
    import javax.swing.ButtonGroup;
    import javax.swing.DefaultListModel;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JPasswordField;
    import javax.swing.JRadioButton;
    import javax.swing.JSplitPane;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    import javax.swing.ToolTipManager;
    import javax.swing.border.Border;
     
    public class Paginnation extends JFrame {
    	/**
             * 
             */
    	private static final long serialVersionUID = 1L;
    	private JTextField text;
    	private JLabel label;
    	private JTextField nb;
    	private Connection connection;
    	private Statement statement;
    	private ResultSet resultSet;
    	private DefaultListModel model;
    	private JPanel panel;
    	JButton bouton;
    	JTextArea text1;
    	JRadioButton rbouton1;
    	JRadioButton rbouton2;
    	public int monNombre;
     
    	public Paginnation() {
    		setSize(new Dimension(500, 500));
    		label = new JLabel("Filter", 10);
    		text = new JTextField(10);
    		nb = new JTextField(10);
    		panel = new JPanel();
    		bouton = new JButton("chercher");
    		JLabel label = new JLabel("User");
     
    		final JTextField jtext = new JTextField("OPS$BRU");
    		jtext.setPreferredSize(new Dimension(100, 30));
     
    		JLabel label1 = new JLabel("Password");
     
    		final JPasswordField jtext1 = new JPasswordField("KALIMA");
    		jtext1.setPreferredSize(new Dimension(100, 30));
     
    		JTextField filterEdit = new JTextField(10);
     
    		text.setPreferredSize(new Dimension(700, 100));
     
    		bouton.addActionListener(new ActionListener() {
     
    			@Override
    			public void actionPerformed(ActionEvent arg0) {
     
    				try {
     
    					/****** Connection ******/
    					Class.forName("oracle.jdbc.driver.OracleDriver");
    					System.out.println("Connecting to the database..."); 
     
    					connection = DriverManager.getConnection(
    							"jdbc:oracle:thin:@10.215.:1521:UBLF",
    							jtext.getText(), jtext1.getText());
    					statement = connection.createStatement();
     
    					JButton button = new JButton("Filter");
    					JFrame base = new JFrame();
    					base.setSize(new Dimension(800, 800));
    					JSplitPane sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    					sp.setPreferredSize(new Dimension(800, 800));
     
    					final JPanel panel1 = new JPanel();
    					panel1.setPreferredSize(new Dimension(800, 50));
    					final JPanel panel2 = new JPanel();
    					panel2.setPreferredSize(new Dimension(800, 500));
     
    					panel1.setLayout(null);
     
    					panel2.setLayout(new CircleLayout2());
     
    					text.setBounds(10, 0, 70, 30);
    					panel1.add(text);
    					nb.setBounds(100, 0, 70, 30);
    					button.setBounds(200, 0, 70, 30);
    					panel1.add(nb);
    					sp.add(panel1);
    					sp.add(panel2);
    					rbouton1 = new JRadioButton("Anglais");
    					rbouton2 = new JRadioButton("Français");
    					rbouton1.setBounds(280, 0, 50, 30);
    					rbouton2.setBounds(350, 0, 50, 30);
    					final ButtonGroup group = new ButtonGroup();
    					group.add((AbstractButton) rbouton1);
    					group.add((AbstractButton) rbouton2);
    					button.addActionListener(new ActionListener() {
    						public void actionPerformed(ActionEvent e) {
     
    							String s = " ";
     
    							s = String.format(text.getText(), s);
    							System.out.println(s);
     
    							System.out.println(nb.getText());
     
    							monNombre = srtToInt(nb.getText());
     
    							try {
    								resultSet = statement
    										.executeQuery("select DISTINCT coobj from DICDOC WHERE   coobj  like '"
    												+ s
    												+ "%"
    												+ "'  AND COCOL IS NULL");
     
    								/* ******** Remplissage de Jlist********** */
    								model = new DefaultListModel();
     
    								while (resultSet.next()) {
     
    									model.addElement(resultSet.getString(1));
     
    								}
     
    								Border border = BorderFactory
    										.createLineBorder(Color.BLACK);
    								// if(monNombre<20)
    								panel2.removeAll();
    								panel2.repaint();
    								if (monNombre <= 15)
    									afficher(monNombre, panel2);
    								else if (monNombre > 15) {
    									afficher(15, panel2);
    									JButton b = new JButton("suivant");
    									panel2.add(b, BorderLayout.SOUTH);
    									b.addActionListener(new ActionListener() {
     
    										@Override
    										public void actionPerformed(
    												ActionEvent arg0) {
    											// TODO Auto-generated method stub
    											// JFrame f= new JFrame();
    											// JPanel p=new JPanel(new
    											// CircleLayout2());
    											panel2.removeAll();
    											afficher(monNombre - 15, panel2);
    											// f.getContentPane().add(p);
    											// f.setVisible(true);
    										}
    									});
    								}
     
    							} catch (SQLException e1) {
    								// TODO Auto-generated catch
    								// block
    								e1.printStackTrace();
    							}
    						}
     
    						private void afficher(int monNombre, JPanel panel2) {
    							// TODO Auto-generated method stub
    							text1 = new JTextArea(100, 30);
     
    							try {
    								String t = (String) model.getElementAt(0);
    								text1.append(t + "1");
    								text1.setBounds(panel2.getWidth() / 2,
    										panel2.getHeight() / 2, 100, 40);
    							} catch (Exception e1) {
    								// TODO: handle exception
    								text1.append(" ");
    							}
    							panel2.add(text1);
     
    							for (int i1 = 1; i1 < monNombre; i1++) {
     
    								text1 = new JTextArea();
    								text1.setName("Text" + i1);
    								try {
    									String t = (String) model.getElementAt(i1);
    									text1.append(t);
    								} catch (Exception e1) {
    									// TODO: handle exception
    									text1.append(" ");
    								}
     
    								ToolTipManager.sharedInstance()
    										.registerComponent(text1);
     
    								text1.addMouseListener(new MouseListener() {
     
    									public void mouseReleased(MouseEvent arg0) {
    										// TODO Auto-generated method stub
     
    									}
     
    									public void mousePressed(MouseEvent arg0) {
    										// TODO Auto-generated method stub
     
    									}
     
    									public void mouseExited(MouseEvent arg0) {
    										// TODO Auto-generated method stub
     
    									}
     
    									public void mouseEntered(MouseEvent arg0) {
    										// TODO Auto-generated method stub
     
    									}
     
    									public void mouseClicked(MouseEvent me) {
    										// TODO Auto-generated method stub
     
    										try {
    											Connection connection1 = DriverManager
    													.getConnection(
    															"jdbc:oracle:thin:@1:1521:UWLF",
    															"OPS$", "LIMA");
     
    											Statement statement1 = connection1
    													.createStatement();
     
    											ToolTipManager.sharedInstance()
    													.setInitialDelay(1);
     
    											JTextArea theText = (JTextArea) me
    													.getSource();
     
    											Point index = theText
    													.getLocation(me.getPoint());
    											System.out.println(index);
    											if (index.x > -1 && index.y > -1) {
    												theText.setToolTipText(null);
    												String text = (String) text1
    														.getSelectedText();
     
    												System.out
    														.println("the selected text is :"
    																+ text);
     
    												char a = ' ';
    												if (((AbstractButton) rbouton1)
    														.isSelected())
     
    													a = 'A';
    												else if (((AbstractButton) rbouton2)
    														.isSelected())
    													a = 'F';
     
    												boolean selected1 = group
    														.isSelected(null);
     
    												ResultSet resutset11 = statement1
    														.executeQuery("select libel from Dicdoc where coobj='"
    																+ text
    																+ "' and colan='"
    																+ "A" + "'");
    												resutset11.next();
    												try {
    													String s = resutset11
    															.getString("libel")
    															+ "\n";
    													System.out.println(s);
    													theText.setToolTipText(s);
    												} catch (Exception e) {
    													// TODO: handle
    													// exception
    													theText.setToolTipText("pas d'explication");
    													// }
     
    												}
     
    											}
     
    											statement1.close();
    											connection1.close();
     
    										} catch (SQLException e) {
    											// TODO Auto-generated catch
    											// block
    											e.printStackTrace();
    										}
     
    									}
    								});
     
    								panel2.add(text1);
     
    								text1.append(" ");
     
    							}
     
    						}
    					});
     
    					panel1.add(button);
    					panel1.add(rbouton1);
    					panel1.add(rbouton2);
     
    					base.getContentPane().add(sp);
     
    					base.setVisible(true);
     
    				} catch (Exception e) {
    					System.out.println("The exception raised is:" + e);
    				}
    			}
     
    			private int srtToInt(String text) {
    				// TODO Auto-generated method stub
    				return Integer.valueOf(text);
     
    			}
    		});
     
    		panel.add(label);
    		panel.add(jtext);
    		panel.add(label1);
    		panel.add(jtext1);
    		panel.add(bouton);
    		addWindowListener(new WindowAdapter() {
    			public void windowClosing(WindowEvent e) {
    				System.exit(0);
    			}
    		});
    		getContentPane().add(panel);
    		setVisible(true);
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
    	}
     
    	public static void main(String[] args) {
     
    		new Paginnation();
    	}
     
    }
     
    class CircleLayout2 implements LayoutManager {
     
    	ArrayList<?> components;
     
    	ArrayList<?> names;
     
    	private boolean isCircle;
     
    	/**
             * Creates a new CircleLayout that lays out components in a perfect circle
             */
     
    	public CircleLayout2() {
     
    		this(true);
    	}
     
    	/**
             * Creates a new CircleLayout that lays out components in either an Ellipse
             * or a Circle. Ellipse Layout is not yet implemented.
             * 
             * @param circle
             *            Indicated the shape to use. It's true for circle or false for
             *            ellipse.
             */
    	public CircleLayout2(boolean circle) {
    		isCircle = circle;
    	}
     
    	/**
             * For compatibility with LayoutManager interface
             */
    	public void addLayoutComponent(String name, Component comp) {
    	}
     
    	/**
             * Arranges the parent's Component objects in either an Ellipse or a Circle.
             * Ellipse is not yet implemented.
             */
    	public void layoutContainer(Container parent) {
    		int x, y, w, h, s, c;
    		int n = parent.getComponentCount();
    		double parentWidth = parent.getSize().width;
    		double parentHeight = parent.getSize().height;
    		Insets insets = parent.getInsets();
    		int centerX = (int) (parentWidth - (insets.left + insets.right)) / 2;
    		int centerY = (int) (parentHeight - (insets.top + insets.bottom)) / 2;
     
    		Component comp = null;
    		Dimension compPS = null;
    		if (n == 1) {
    			comp = parent.getComponent(0);
    			x = centerX;
    			y = centerY;
    			compPS = comp.getPreferredSize();
    			w = compPS.width;
    			h = compPS.height;
    			comp.setBounds(x, y, w, h);
    		} else {
    			double r = (Math.min(parentWidth - (insets.left + insets.right),
    					parentHeight - (insets.top + insets.bottom))) / 2;
    			r *= 0.75; // Multiply by .75 to account for extreme right and
    						// bottom
    						// Components
    			for (int i = 1; i < n; i++) {
    				comp = parent.getComponent(i);
    				compPS = comp.getPreferredSize();
    				if (isCircle) {
    					c = (int) (r * Math.cos(2 * i * Math.PI / n));
    					s = (int) (r * Math.sin(2 * i * Math.PI / n));
    				} else {
    					c = (int) ((centerX * 0.75) * Math.cos(2 * i * Math.PI / n));
    					s = (int) ((centerY * 0.75) * Math.sin(2 * i * Math.PI / n));
    				}
    				x = c + centerX;
    				y = s + centerY;
     
    				w = compPS.width;
    				h = compPS.height;
     
    				comp.setBounds(x, y, 100, 30);
    			}
    		}
     
    	}
     
    	/**
             * Returns this CircleLayout's preferred size based on its Container
             * 
             * @param target
             *            This CircleLayout's target container
             * @return The preferred size
             */
     
    	public Dimension preferredLayoutSize(Container target) {
    		return target.getSize();
    	}
     
    	/**
             * Returns this CircleLayout's minimum size based on its Container
             * 
             * @param target
             *            This CircleLayout's target container
             * @return The minimum size
             */
    	public Dimension minimumLayoutSize(Container target) {
    		return target.getSize();
    	}
     
    	/**
             * For compatibility with LayoutManager interface
             */
    	public void removeLayoutComponent(Component comp) {
    	}
     
    	/**
             * Returns a String representation of this CircleLayout.
             * 
             * @return A String that represents this CircleLayout
             */
    	public String toString() {
    		return this.getClass().getName();
    	}
     
    }

  2. #2
    Modérateur
    Avatar de dinobogan
    Homme Profil pro
    ingénieur
    Inscrit en
    Juin 2007
    Messages
    4 073
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France

    Informations professionnelles :
    Activité : ingénieur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2007
    Messages : 4 073
    Points : 7 163
    Points
    7 163
    Par défaut
    (envie de répondre : ça, c'est pas de chance...)

    Quel est le problème ? Quel est le comportement rencontré ? Quel est le comportement attendue ?
    Il faut aussi ajouter quelques phrases décrivant brièvement le code.
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java
    Que la force de la puissance soit avec le courage de ta sagesse.

Discussions similaires

  1. [Formulaire] bouton suivant precedent
    Par luz_negra dans le forum IHM
    Réponses: 5
    Dernier message: 05/12/2007, 09h44
  2. [Javascript] popup : Suivant-Precedent des images
    Par kagura dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 16/02/2007, 16h07
  3. recherche code pour limiter une lister et utiliser les bouton suivant precedent
    Par carmen256 dans le forum PHP & Base de données
    Réponses: 3
    Dernier message: 29/09/2006, 17h43
  4. [FLASH 8] BP suivant precedant
    Par steeves5 dans le forum Flash
    Réponses: 5
    Dernier message: 02/03/2006, 16h55
  5. [FLASH 8] Création de BP suivant precedant
    Par steeves5 dans le forum Flash
    Réponses: 6
    Dernier message: 25/02/2006, 21h43

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo