📄 comptewindow.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
class CompteWindow extends JDialog
{
JPanel contentPane, commandPanel = new JPanel();
JButton clearButton = new JButton(),
cancelButton = new JButton(),
okButton = new JButton();
JLabel labelNumero = new JLabel(" Numero : "),
labelType = new JLabel(" Type : "),
labelSoldeinitial = new JLabel(" Solde initial : "),
labelNumeross = new JLabel(" Numero SS : ");
JTextField textNumero = new JTextField(),
textSoldeinitial = new JTextField(),
textNumeross = new JTextField(),
textNumero1 = new JTextField(),
textNumeross1 = new JTextField(),
textType1 = new JTextField();
JComboBox
jcType = new JComboBox();
public CompteWindow(int i)
{
super();
init(i);
}
public void init(int i)
{
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(new BorderLayout());
this.setSize(new Dimension(450,200));
if(i==0)
this.setTitle("Creation d'un nouveau compte");
else
this.setTitle("Modifier le compte");
this.setResizable(false);
textNumero.setFont(new java.awt.Font("Arial", 1, 18));
jcType.setFont(new java.awt.Font("Arial", 1, 18));
textSoldeinitial.setFont(new java.awt.Font("Arial", 1, 18));
textNumeross.setFont(new java.awt.Font("Arial", 1, 18));
textNumero1.setFont(new java.awt.Font("Arial", 1, 18));
textNumero1.setEditable(false);
textType1.setFont(new java.awt.Font("Arial", 1, 18));
textType1.setEditable(false);
textNumeross1.setFont(new java.awt.Font("Arial", 1, 18));
textNumeross1.setEditable(false);
clearButton.setText("Clear");
clearButton.setFont(new java.awt.Font("SansSerif", 0, 14));
clearButton.addActionListener(new java.awt.event.ActionListener(){
public void actionPerformed(ActionEvent e){clear();}
});
cancelButton.setText("Annuler");
cancelButton.addActionListener(new java.awt.event.ActionListener(){
public void actionPerformed(ActionEvent e){dispose();}
});
okButton.setText("OK");
JPanel centerPanel = new JPanel();
centerPanel.setLayout(new GridLayout(4,2));
centerPanel.setBorder(BorderFactory.createEtchedBorder());
centerPanel.add(labelNumero);
if(i==0)
centerPanel.add(textNumero);
else
centerPanel.add(textNumero1);
centerPanel.add(labelType);
if(i==0)
centerPanel.add(jcType);
else
centerPanel.add(textType1);
centerPanel.add(labelSoldeinitial);
centerPanel.add(textSoldeinitial);
centerPanel.add(labelNumeross);
if(i==0)
centerPanel.add(textNumeross);
else
centerPanel.add(textNumeross1);
jcType.addItem("choisez SVP");
jcType.addItem("a");
jcType.addItem("b");
jcType.addItem("c");
jcType.addItem("d");
if(i==0)
okButton.addActionListener(new java.awt.event.ActionListener(){
public void actionPerformed(ActionEvent e){ creerNouveauCompte(); }
});
else
{
okButton.addActionListener(new java.awt.event.ActionListener(){
public void actionPerformed(ActionEvent e){ ModifierCompte(); }
});
textNumero1.setText(graphicApp.getcompte().getnumero());
textType1.setText(Character.toString(graphicApp.getcompte().gettype()));
textSoldeinitial.setText(Integer.toString(graphicApp.getcompte().getinitSolde()));
textNumeross1.setText(graphicApp.getcompte().proprietaire().getnumeross());
}
contentPane.add(new JLabel(" "), BorderLayout.NORTH);
contentPane.add(centerPanel, BorderLayout.CENTER);
commandPanel.setBackground(Color.lightGray);
commandPanel.setBorder(BorderFactory.createRaisedBevelBorder());
commandPanel.add(clearButton, null);
commandPanel.add(cancelButton, null);
commandPanel.add(okButton, null);
contentPane.add(commandPanel, BorderLayout.SOUTH);
}
//End de init()
void clear()
{
textNumero.setText("");
jcType.setSelectedIndex(0);
textSoldeinitial.setText("");
textNumeross.setText("");
}
void creerNouveauCompte()
{
boolean error = false;
String numero = textNumero.getText().trim(),
type = (String)jcType.getItemAt(jcType.getSelectedIndex()),
soldeinitial = textSoldeinitial.getText().trim(),
numeross = textNumeross.getText().trim();
textNumero.setText(numero);
textSoldeinitial.setText(soldeinitial);
textNumeross.setText(numeross);
if(numero.equals(new String("")))
{
JOptionPane.showMessageDialog(this,
"Vous devez saisir le numero du compte","Information",JOptionPane.INFORMATION_MESSAGE);
return;
}
if (run.verifiercompte(numero)==-1)
{
JOptionPane.showMessageDialog(this,
"le numero du compte a deja existe","Information",JOptionPane.INFORMATION_MESSAGE);
return;
}
if(type.equals(new String("choisez SVP")))
{
JOptionPane.showMessageDialog(this,
"Vous devez select le type du compte","Information",JOptionPane.INFORMATION_MESSAGE);
return;
}
if(soldeinitial.equals(new String("")))
{
JOptionPane.showMessageDialog(this,
"Vous devez saisir le solde initial du compte","Information",JOptionPane.INFORMATION_MESSAGE);
return;
}
else
{
try
{
Integer.parseInt(textSoldeinitial.getText().trim());
}
catch(NumberFormatException e)
{
JOptionPane.showMessageDialog(this,
"le solde initial doit etre chiffre","Information",JOptionPane.INFORMATION_MESSAGE);
return;
}
}
if(numeross.equals(new String("")))
{
JOptionPane.showMessageDialog(this,
"Vous devez saisir le Numero SS du proprietaire","Information",JOptionPane.INFORMATION_MESSAGE);
return;
}
Personne p=run.rechercherclient(numeross);
if(p==null)
{
JOptionPane.showMessageDialog(this,
"il n'y a pas cette client,retaper SVP","Information",JOptionPane.INFORMATION_MESSAGE);
return;
}
run.creernouveaucompte(numero,type.charAt(0),Integer.parseInt(soldeinitial),p);
FilesUtils.enregistrerLesCompte();
dispose();
}
void ModifierCompte()
{
boolean error = false;
String soldeinitial = textSoldeinitial.getText().trim();
textSoldeinitial.setText(soldeinitial);
if(soldeinitial.equals(new String("")))
{
JOptionPane.showMessageDialog(this,
"Vous devez saisir le solde initial du compte","Information",JOptionPane.INFORMATION_MESSAGE);
return;
}
else
{
try
{
Integer.parseInt(textSoldeinitial.getText().trim());
}
catch(NumberFormatException e)
{
JOptionPane.showMessageDialog(this,
"le solde initial doit etre chiffre","Information",JOptionPane.INFORMATION_MESSAGE);
return;
}
}
graphicApp.modifiercompte(Integer.parseInt(soldeinitial));
FilesUtils.enregistrerLesCompte();
dispose();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -