cours0708/P51/PopupConnectionBD.java

142 lines
4.8 KiB
Java

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class PopupConnectionBD extends JDialog {
JPanel mainPanel;
JPanel labelPanel;
JPanel fieldPanel;
JPanel buttonPanel;
JPanel textPanel;
JButton buttonOK;
JButton buttonCancel;
JPasswordField passwordField;
JTextField nameField;
JLabel nameLabel;
JLabel passwordLabel;
JLabel baseLabel;
JTextField baseField;
JLabel hostLabel;
JLabel portLabel;
JTextField hostField;
JTextField portField;
private String name;
private String password;
private String base;
private String host;
private String port;
public JFrame parentFrame;
public String getHost() {
return host ;
}
public String getPort() {
return port ;
}
public String getUserName() {
return name ;
}
public String getUserPassword() {
return password;
}
public String getDataBase() {
return base;
}
public PopupConnectionBD( JFrame frame, String popupName ) {
super( (Frame)frame, popupName, true );
parentFrame = frame;
name = new String( "" );
password = new String( "" );
base = new String( "" );
host = new String( "" );
port = new String( "" );
fieldPanel = new JPanel();
fieldPanel.setLayout( new GridLayout( 5, 1 ) );
labelPanel = new JPanel();
labelPanel.setLayout( new GridLayout( 5, 1 ) );
hostField = new JTextField( "grive", 12 );
hostLabel = new JLabel( "Serveur : " );
labelPanel.add( hostLabel );
fieldPanel.add( hostField );
portField = new JTextField( "1521", 12 );
portLabel = new JLabel( "Port : " );
labelPanel.add( portLabel );
fieldPanel.add( portField );
baseField = new JTextField( "v816", 12 );
baseLabel = new JLabel( "Base : " );
labelPanel.add( baseLabel );
fieldPanel.add( baseField );
nameField = new JTextField( 12 );
nameLabel = new JLabel( "Nom : " );
labelPanel.add( nameLabel );
fieldPanel.add( nameField );
passwordLabel = new JLabel( "Mot de passe : " );
passwordField = new JPasswordField( 12 );
labelPanel.add( passwordLabel );
fieldPanel.add( passwordField );
textPanel = new JPanel();
textPanel.setLayout( new FlowLayout() );
textPanel.add( labelPanel );
textPanel.add( fieldPanel );
buttonPanel = new JPanel();
buttonPanel.setLayout( new GridLayout( 1, 2 ) );
buttonOK = new JButton( "OK" );
buttonOK.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent ev ) {
base = baseField.getText();
password = new String( passwordField.getPassword() );
name = nameField.getText();
passwordField.setText( "" );
nameField.setText( "" );
setVisible( false );
parentFrame.pack();
}
}
);
buttonCancel = new JButton( "Annuler" );
buttonCancel.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent ev ) {
name = "";
password = "";
base = "";
passwordField.setText( "" );
nameField.setText( "" );
setVisible( false );
parentFrame.pack();
}
}
);
buttonPanel.add( buttonOK );
buttonPanel.add( buttonCancel );
mainPanel = new JPanel();
mainPanel.setLayout( new BorderLayout() );
mainPanel.add( textPanel, BorderLayout.CENTER );
mainPanel.add( buttonPanel, BorderLayout.SOUTH );
getContentPane().add( mainPanel );
//setSize( 250, 130 );
setVisible( false );
pack();
setResizable( false );
}
}