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

Interfaces Graphiques en Java Discussion :

Problème d'affichage de boutons dans une Frame ayant une image en background


Sujet :

Interfaces Graphiques en Java

  1. #1
    Candidat au Club
    Inscrit en
    Mars 2012
    Messages
    3
    Détails du profil
    Informations forums :
    Inscription : Mars 2012
    Messages : 3
    Points : 4
    Points
    4
    Par défaut Problème d'affichage de boutons dans une Frame ayant une image en background
    Bonjour,
    j'ai une Jframe nommée DatabaseView ayant une image en fond. Je lui ajoute un JPanel contenant des boutons. Lorsque j'exécute le code, les boutons n'apparaissent pas. Pour les voir, il faut passer la souris sur l'interface. Je pensais que c'étais un problème de validate() et non repaint() mais, aucunes des deux fonctions ne fonctionnent. Je suis confus. Pouvez-vous m'aider?

    La classe ci-dessous (DatabaseView) se trouve aussi en pièce jointe.


    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
    package view;
     
    import java.awt.BorderLayout;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.Toolkit;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.Observable;
    import java.util.Observer;
     
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.WindowConstants;
     
    import Controler.ControlerCreate_User;
    import Controler.ControlerCreate_Database;
    import Controler.ControlerDelete_Database;
    import Controler.ControlerRemove_User;
    import Controler.Controler_Connect_Local_User;
    import Controler.Controler_General_Display;
     
    import model.ShanghaiMetro_Database;
     
     
    /**
    * This code was edited or generated using CloudGarden's Jigloo
    * SWT/Swing GUI Builder, which is free for non-commercial
    * use. If Jigloo is being used commercially (ie, by a corporation,
    * company or business for any purpose whatever) then you
    * should purchase a license for each developer using Jigloo.
    * Please visit <a href="http://www.cloudgarden.com" target="_blank">www.cloudgarden.com</a> for details.
    * Use of Jigloo implies acceptance of these licensing terms.
    * A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
    * THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
    * LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
    */
    public class DatabaseView extends javax.swing.JFrame implements Observer{
     
    	private static final long serialVersionUID = 3477287769198950032L;
    	private JButton Create_Database;
    	private JButton Delete_Database;
    	private JButton Show_Users;
    	private JButton ShowAll_Database;
    	private JButton Disconnect_to_local_User;
    	private JButton ModifyDatabase;
    	private JButton Connect_to_local_user;
    	private JButton Remove_User;
    	private JButton Create_User;
    	private JPanel pan;
     
    	ShanghaiMetro_Database ShanghaiM;
     
    	// Controler for PAnelNorth
    	ControlerCreate_Database controlerCreate_Data;
    	ControlerDelete_Database controlDelete_data;
    	ControlerCreate_User controlCreate_User;
    	ControlerRemove_User controlRemove_User;
    	Controler_Connect_Local_User controlLocalServer_connection;
    	Controler_General_Display controlGeneralDisplay;
    	Image image;
     
    	public DatabaseView(ShanghaiMetro_Database SM) {
    		super();
    		image = Toolkit.getDefaultToolkit().createImage("images/Wallpaper.jpg");	
    		initGUI();
     
    		(SM.getCdata()).addObserver(this);
    		(SM.getcUser()).addObserver(this);
    		(SM.getdData()).addObserver(this);
    		(SM.getrUser()).addObserver(this);
    		(SM.getcLocalServer()).addObserver(this);	
    		(SM.getDisp()).addObserver(this);		
     
    		this.ShanghaiM = SM;
     
    		this.controlCreate_User = new ControlerCreate_User(SM.getcUser());
    		this.controlRemove_User = new ControlerRemove_User(SM.getrUser());
    		this.controlDelete_data = new ControlerDelete_Database(SM.getdData());
    		this.controlerCreate_Data = new ControlerCreate_Database(SM.getCdata());
    		this.controlGeneralDisplay = new Controler_General_Display(SM.getDisp());
    		this.controlLocalServer_connection = new Controler_Connect_Local_User(SM.getcLocalServer());
     
    	}
     
    	private void initGUI() {
    		try {
    			this.setTitle("Shanghai Subway System Database ");
    			this.setIconImage(new ImageIcon("images/Logo.jpg").getImage());
    			setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
     
     
    			{
    				pan = new JPanel();
    				this.getContentPane().add(pan);
    				pan.setLayout(null);
    				pan.setBackground(new java.awt.Color(255,255,255));
    				pan.setFocusable(false);
    				pan.setPreferredSize(new java.awt.Dimension(582, 372));
    				{
    					Create_Database = new JButton();
    					pan.add(Create_Database);
    					Create_Database.setText("Create DATABASE");
    					Create_Database.setBounds(77, 7, 154, 42);
    					Create_Database.addActionListener(new ActionListener() {
    						public void actionPerformed(ActionEvent evt) {
    							Create_DatabaseActionPerformed(evt);
    						}
    					});
    				}
    				{
    					Delete_Database = new JButton();
    					pan.add(Delete_Database);
    					Delete_Database.setText("Delete DATABASE");
    					Delete_Database.setBounds(370, 7, 154, 42);
    					Delete_Database.addActionListener(new ActionListener() {
    						public void actionPerformed(ActionEvent evt) {
    							Delete_DatabaseActionPerformed(evt);
    						}
    					});
    				}
    				{
    					Remove_User = new JButton();
    					pan.add(Remove_User);
    					Remove_User.setText("Remove USER");
    					Remove_User.setBounds(370, 60, 154, 42);
    					Remove_User.addActionListener(new ActionListener() {
    						public void actionPerformed(ActionEvent evt) {
    							Remove_UserActionPerformed(evt);
    						}
    					});
    				}
    				{
    					Create_User = new JButton();
    					pan.add(Create_User);
    					Create_User.setText("Create USER");
    					Create_User.setBounds(77, 60, 154, 42);
    					Create_User.addActionListener(new ActionListener() {
    						public void actionPerformed(ActionEvent evt) {
    							Create_UserActionPerformed(evt);
    						}
    					});
    				}
    				{
    					Connect_to_local_user = new JButton();
    					pan.add(Connect_to_local_user);
    					Connect_to_local_user.setText("Connect to the local USER");
    					Connect_to_local_user.setBounds(65, 112, 181, 42);
    					Connect_to_local_user.addActionListener(new ActionListener() {
    						public void actionPerformed(ActionEvent evt) {
    							Connect_to_local_userActionPerformed(evt);
    						}
    					});
    				}
    				{
    					ModifyDatabase = new JButton();
    					pan.add(ModifyDatabase);
    					ModifyDatabase.setText("Modify DATABASE");				
    					ModifyDatabase.setBounds(439, 360, 150, 23);
    					ModifyDatabase.addActionListener(new ActionListener() {
    						public void actionPerformed(ActionEvent evt) {
    							ModifyDatabaseActionPerformed(evt);
    						}
    					});
    				}
    				{
    					Disconnect_to_local_User = new JButton();
    					pan.add(Disconnect_to_local_User);
    					Disconnect_to_local_User.setText("Disconnect to the local User");
    					Disconnect_to_local_User.setBounds(358, 113, 181, 40);
    					Disconnect_to_local_User.addActionListener(new ActionListener() {
    						public void actionPerformed(ActionEvent evt) {
    							Disconnect_to_local_UserActionPerformed(evt);
    						}
    					});
    				}
    				{
    					ShowAll_Database = new JButton();
    					pan.add(ShowAll_Database);
    					ShowAll_Database.setText("Show All DAtabase on this server");
    					ShowAll_Database.setBounds(181, 360, 239, 23);
    					ShowAll_Database.addActionListener(new ActionListener() {
    						public void actionPerformed(ActionEvent evt) {
    							ShowAll_DatabaseActionPerformed(evt);
    						}
    					});
    					ShowAll_Database.setVisible(true);
    				}
    				{
    					Show_Users = new JButton();
    					pan.add(Show_Users, BorderLayout.CENTER);
    					Show_Users.setText("Show all USERS");
    					Show_Users.setBounds(12,360, 150, 23);
    					Show_Users.addActionListener(new ActionListener() {
    						public void actionPerformed(ActionEvent evt) {
    							Show_UsersActionPerformed(evt);
    						}
    					});
    				}
    				pan.validate();
    				pan.setVisible(true);
     
    			}
     
    			pack();
    			setSize(600, 410);
    			this.setResizable(false);
    			this.validate();
    			this.setVisible(true);
    			this.setLocationRelativeTo(null);
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
     
    	public void paint(Graphics g){
    		super.paint(g);
    		g.drawImage(image,0, 0,this.getWidth(), this.getHeight(), null);
    	}
     
    	private void Create_DatabaseActionPerformed(ActionEvent evt) {
    		controlerCreate_Data.control(JOptionPane.showInputDialog (this, "Enter the name of the database you want to create"));
    		JOptionPane.showMessageDialog(this, (this.ShanghaiM.getCdata()).getStr_cretaDabase()
    				  , "Result of Creation", JOptionPane.PLAIN_MESSAGE);
    	}
     
    	private void Create_UserActionPerformed(ActionEvent evt) {
    		this.controlCreate_User.control(JOptionPane.showInputDialog (this, "Enter the name of the database that you want to add an user"), 
    							JOptionPane.showInputDialog (this, "Enter the name of the user you want to create"), 
    							JOptionPane.showInputDialog (this, "Enter the password of the user you want to create"));
     
    		JOptionPane.showMessageDialog(this, (this.ShanghaiM.getcUser()).getStr_createUser()
    				  , "Result of Creation", JOptionPane.PLAIN_MESSAGE);
    	}
     
    	private void Delete_DatabaseActionPerformed(ActionEvent evt) {
     
    		JOptionPane.showMessageDialog(this, "DON'T DELETE THE DATABASES NAMES: \n" +
    											"								    information_schema\n" + 
    											"								    mysql\n" + 
    											"								    performance_schema\n" + 
    											"								    sakila\n" + 
    											"								    test\n" + 
    											"								    world\n"    
    				  , "BE CAREFUL", JOptionPane.PLAIN_MESSAGE);
     
    		this.controlDelete_data.control(JOptionPane.showInputDialog (this,
    				"Enter the name of the database you want to delete.\n" + 
    				"It should be different from the database name: \n" +
    				"								    information_schema\n" + 
    				"								    mysql\n" + 
    				"								    performance_schema\n" + 
    				"								    sakila\n" + 
    				"								    test\n" + 
    				"								    world\n" ));
    		JOptionPane.showMessageDialog(this, (this.ShanghaiM.getdData()).getStr_deleteDatabase()
    				  , "Result of Deletion", JOptionPane.PLAIN_MESSAGE);
    	}
     
    	private void Remove_UserActionPerformed(ActionEvent evt) {
    		this.controlRemove_User.control(JOptionPane.showInputDialog (this, "Enter the name of the user you want to remove"));
    		JOptionPane.showMessageDialog(this, (this.ShanghaiM.getrUser()).getStr_removeUser()
    				  , "Result of Deletion", JOptionPane.PLAIN_MESSAGE);	
    	}
     
    	private void Connect_to_local_userActionPerformed(ActionEvent evt) {
    		this.controlLocalServer_connection.control(
    				JOptionPane.showInputDialog (this, "Enter the name of the database that you want to be connected"), 
    				JOptionPane.showInputDialog (this, "Enter the name of the local user who have all privilege \n" +
    												   "to the database you want to be connected"), 
    				JOptionPane.showInputDialog (this, "Enter the password of the user this user"));
    		JOptionPane.showMessageDialog(this, (this.ShanghaiM.getcLocalServer()).getLocal_Server_str_Error()
    				  , "Result of connection", JOptionPane.PLAIN_MESSAGE);
    	}
     
    	private void ModifyDatabaseActionPerformed(ActionEvent evt) {
    		if ( (this.ShanghaiM.getcLocalServer()).getConnect() == null )
    			JOptionPane.showMessageDialog(this, " Make sure that you have being connected first.\n" + 
    				" To do that, click to the button \"Connect to the local USER\"" ,
    				"BE CAREFUL", JOptionPane.PLAIN_MESSAGE);
    		else
    			new Modify_Database(ShanghaiM);
    	}
     
    	private void Disconnect_to_local_UserActionPerformed(ActionEvent evt) {
    		this.controlLocalServer_connection.deconnection();
    		JOptionPane.showMessageDialog(this, (this.ShanghaiM.getcLocalServer()).getDeconnection()
    				  , "Result of deconnection", JOptionPane.PLAIN_MESSAGE);
    	}
     
    	private void ShowAll_DatabaseActionPerformed(ActionEvent evt) {
    		this.controlGeneralDisplay.control();
    		JOptionPane.showMessageDialog(this, (this.ShanghaiM.getDisp()).getDisplayDatabases()
    				  , "This is all existing databases on this server", JOptionPane.PLAIN_MESSAGE);
    	}
     
    	private void Show_UsersActionPerformed(ActionEvent evt) {
    		this.controlGeneralDisplay.display();
    		JOptionPane.showMessageDialog(this, (this.ShanghaiM.getDisp()).getShowUsers()
    				  , "This is all existing users on this server", JOptionPane.PLAIN_MESSAGE);
    	}
     
     
     
    	@Override
    	public void update(Observable arg0, Object arg) {}
     
    }
    Fichiers attachés Fichiers attachés

Discussions similaires

  1. Réponses: 1
    Dernier message: 13/04/2015, 11h17
  2. Problème d'intégration de boutons dans une Frame
    Par unic0 dans le forum Tkinter
    Réponses: 2
    Dernier message: 01/03/2015, 23h06
  3. [WD18] Metre une colonne d'une Table sur une ligne d'une autre Table
    Par Totophe2 dans le forum WinDev
    Réponses: 2
    Dernier message: 22/11/2013, 12h58
  4. [XL-2002] Macro de comparaison d'une cellule d'une feuille avec une cellule d'une autre feuille.
    Par steelydan dans le forum Macros et VBA Excel
    Réponses: 6
    Dernier message: 08/09/2010, 12h59
  5. Réponses: 1
    Dernier message: 04/05/2007, 12h40

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