cs_saif87
Messages postés35Date d'inscriptiondimanche 7 décembre 2008StatutMembreDernière intervention16 juin 2010
-
18 déc. 2008 à 16:15
cs_saif87
Messages postés35Date d'inscriptiondimanche 7 décembre 2008StatutMembreDernière intervention16 juin 2010
-
19 déc. 2008 à 11:00
bonjour je suis débutant en graphique de java et je veut créer une application pour une gestion bancaire donc il y'a une interface graphique(frame)composer de 3 boutton
b1:creation du client
b2:cretaion du compte
b3:affichage des inforamtion
si l'utilisateur tape b1 une frame apparait composer d'une suite de zone de text
et ainsi de suite......
voici mon code mais l'orsque je tape le boutton 3 frame apparait
aidez moi svp
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class ButtonPanel extends JPanel
{
ButtonPanel()
{
JButton client=new JButton("cree un client");
JButton compte=new JButton("cree un compte");
JButton information=new JButton("afficher vos informations");
add(client,BorderLayout.WEST);
add(compte,BorderLayout.CENTER);
add(information,BorderLayout.EAST);
client.addActionListener(new ColorAction());
compte.addActionListener(new ColorAction());
information.addActionListener(new ColorAction());
}
class ColorAction implements ActionListener
{
ColorAction()
{
}
public void actionPerformed(ActionEvent event)
{
//setBackground(color);
Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();
int w=screenSize.width;
int h=screenSize.height;
uhrand
Messages postés491Date d'inscriptionsamedi 20 mai 2006StatutMembreDernière intervention15 juillet 20129 19 déc. 2008 à 04:56
Remarque: "show()" est déconseillé et remplacé par "setVisible(true)".
Une application n'a qu'un seul JFrame, les fenêtres auxiliaires étant réalisées par JDialog:
/*
* MainGraphique4.java
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class ButtonPanel extends JPanel implements ActionListener{
private JButton client, compte, information;
ButtonPanel() {
client = new JButton("cree un client");
compte = new JButton("cree un compte");
information = new JButton("afficher vos informations");
add(client, BorderLayout.WEST);
add(compte, BorderLayout.CENTER);
add(information, BorderLayout.EAST);
client.addActionListener(this);
compte.addActionListener(this);
information.addActionListener(this);
}
public void actionPerformed(ActionEvent event) {
Object source = event.getSource();
JDialog d = null;
JFrame parent = (JFrame)SwingUtilities.getRoot(ButtonPanel.this);
if (source == client) {
d = new JDialog(parent, "Nouveau Client", true);
} else if (source == compte) {
d = new JDialog(parent, "Nouveau Compte", true);
} else if (source == information) {
d = new JDialog(parent, "Informations", true);
}
if(d != null){
d.setSize(400, 300);
d.setLocationRelativeTo(parent);
d.setVisible(true);
}
}
}
public class MainGraphique4 {
public static void main(String[] args) {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int w = screenSize.width;
int h = screenSize.height;
JFrame frame = new MainFrame(w / 2, h / 2, 0, 0, "GESTION BANCAIRE");
frame.setVisible(true);
}
}
class MainFrame extends JFrame {
MainFrame(int w, int h, int x, int y, String ch) {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle(ch);
setSize(w, h);
setLocation(x, y);
getContentPane().add(new ButtonPanel());
}
}