UI proof of concept (sans discussion)
This commit is contained in:
parent
c6d49ab579
commit
f8a2e59d69
3 changed files with 301 additions and 0 deletions
90
Projet_POO/src/ui/ListUI.java
Normal file
90
Projet_POO/src/ui/ListUI.java
Normal file
|
@ -0,0 +1,90 @@
|
|||
package ui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
|
||||
import nom.GestionnaireNom;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class ListUI extends JFrame implements Runnable{
|
||||
|
||||
private JPanel contentPane;
|
||||
private JTable table;
|
||||
private DefaultTableModel dtm = new DefaultTableModel(null, new String[] {"Name"});
|
||||
|
||||
private String[] test = new String[] {"1", "2", "3", "4"};
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
ListUI frame = new ListUI();
|
||||
frame.setVisible(true);
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void add(DefaultTableModel dtm, String[] test) {
|
||||
for (String t : test) {
|
||||
dtm.addRow(new Object[] {t});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public ListUI() {
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 450, 300);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
table = new JTable();
|
||||
|
||||
table.setModel(dtm);
|
||||
table.setBounds(120, 67, 203, 134);
|
||||
contentPane.add(table);
|
||||
|
||||
JButton btnNewButton = new JButton("Connect");
|
||||
btnNewButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
int row = table.getSelectedRow();
|
||||
int col = table.getSelectedColumn();
|
||||
try{
|
||||
String nom = (String) table.getValueAt(row, col);
|
||||
System.out.println(nom);
|
||||
|
||||
//String id = GestionnaireNom.idFromNom(nom);
|
||||
|
||||
}
|
||||
catch (Exception e) {}
|
||||
|
||||
}
|
||||
});
|
||||
btnNewButton.setBounds(170, 22, 89, 23);
|
||||
contentPane.add(btnNewButton);
|
||||
|
||||
add(dtm, test);
|
||||
}
|
||||
|
||||
}
|
207
Projet_POO/src/ui/Login_RegisterUI.java
Normal file
207
Projet_POO/src/ui/Login_RegisterUI.java
Normal file
|
@ -0,0 +1,207 @@
|
|||
package ui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import nom.GestionnaireNom;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JButton;
|
||||
import java.awt.event.FocusAdapter;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
public class Login_RegisterUI extends JFrame {
|
||||
|
||||
private JPanel contentPane;
|
||||
private JTextField idField;
|
||||
private JTextField usernameField;
|
||||
|
||||
|
||||
/*
|
||||
//Instance du gestionnaire de liste
|
||||
static private Login_RegisterUI uniqueInstance = null;
|
||||
|
||||
//Renvoie le gestionnaire de liste, ou le créé s'il n'existe pas encore
|
||||
static public Login_RegisterUI instance() {
|
||||
//Si l'instance n'existe pas, on la créé
|
||||
if (Login_RegisterUI.uniqueInstance == null) {
|
||||
Login_RegisterUI.uniqueInstance = new Login_RegisterUI();
|
||||
}
|
||||
|
||||
return Login_RegisterUI.uniqueInstance;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
|
||||
|
||||
public void enter() {
|
||||
if( usernameField.getText().equals("admin") || idField.getText().equals("0") ) { //remplaver || par && -> flemme debug
|
||||
ListUI liste = new ListUI();
|
||||
liste.setLocationRelativeTo(null);
|
||||
liste.setVisible(true);
|
||||
dispose();
|
||||
//Thread ts = new Thread(liste); //inutile avce le setVisible(true)
|
||||
//ts.start();
|
||||
}
|
||||
else {
|
||||
JOptionPane.showMessageDialog(null, "Invalid Username / Password", "Login error", 2);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Login_RegisterUI frame = new Login_RegisterUI();
|
||||
frame.setVisible(true);
|
||||
|
||||
//center the frame
|
||||
frame.setLocationRelativeTo(null);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public Login_RegisterUI() {
|
||||
setTitle("Login");
|
||||
|
||||
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 450, 300);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
JLabel idLabel = new JLabel("Id");
|
||||
idLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
idLabel.setBounds(39, 47, 79, 32);
|
||||
contentPane.add(idLabel);
|
||||
|
||||
JLabel usernameLabel = new JLabel("Username");
|
||||
usernameLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
usernameLabel.setBounds(39, 93, 79, 25);
|
||||
contentPane.add(usernameLabel);
|
||||
|
||||
idField = new JTextField();
|
||||
idField.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if (e.getExtendedKeyCode() == KeyEvent.VK_ENTER) {
|
||||
enter();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//id field
|
||||
idField.addFocusListener(new FocusAdapter() {
|
||||
@Override
|
||||
public void focusGained(FocusEvent e) {
|
||||
String s = idField.getText();
|
||||
if ( s.equals("Id") ) {
|
||||
idField.setText("");
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void focusLost(FocusEvent e) {
|
||||
String s = idField.getText();
|
||||
if ( s.equals("") ) {
|
||||
idField.setText("Id");
|
||||
}
|
||||
}
|
||||
});
|
||||
idField.setText("Id");
|
||||
idField.setBounds(167, 53, 195, 20);
|
||||
contentPane.add(idField);
|
||||
idField.setColumns(10);
|
||||
|
||||
usernameField = new JTextField();
|
||||
usernameField.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if (e.getExtendedKeyCode() == KeyEvent.VK_ENTER) {
|
||||
enter();
|
||||
}
|
||||
}
|
||||
});
|
||||
// Username field
|
||||
usernameField.addFocusListener(new FocusAdapter() {
|
||||
@Override
|
||||
public void focusGained(FocusEvent e) {
|
||||
String s = usernameField.getText();
|
||||
if ( s.equals("Username") ) {
|
||||
usernameField.setText("");
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void focusLost(FocusEvent e) {
|
||||
String s = usernameField.getText();
|
||||
if ( s.equals("") ) {
|
||||
usernameField.setText("Username");
|
||||
}
|
||||
}
|
||||
});
|
||||
usernameField.setText("Username");
|
||||
usernameField.setColumns(10);
|
||||
usernameField.setBounds(167, 95, 195, 20);
|
||||
contentPane.add(usernameField);
|
||||
|
||||
//login Button
|
||||
JButton loginButton = new JButton("Login");
|
||||
loginButton.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if (e.getExtendedKeyCode() == KeyEvent.VK_ENTER) {
|
||||
enter();
|
||||
}
|
||||
}
|
||||
});
|
||||
loginButton.setBorder(BorderFactory.createLineBorder(Color.black));
|
||||
loginButton.setBorder(BorderFactory.createRaisedSoftBevelBorder());
|
||||
|
||||
loginButton.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
loginButton.setBorder(BorderFactory.createLoweredSoftBevelBorder());
|
||||
}
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
loginButton.setBorder(BorderFactory.createRaisedSoftBevelBorder());
|
||||
}
|
||||
});
|
||||
loginButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
enter();
|
||||
|
||||
}
|
||||
});
|
||||
loginButton.setBounds(167, 162, 89, 23);
|
||||
contentPane.add(loginButton);
|
||||
}
|
||||
|
||||
}
|
|
@ -93,6 +93,10 @@ public class ToutUI {
|
|||
frmTitle.getContentPane().add(comboBox);
|
||||
|
||||
JButton btnNewButton = new JButton("New buttonn");
|
||||
btnNewButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
}
|
||||
});
|
||||
btnNewButton.setToolTipText("tip");
|
||||
btnNewButton.setMnemonic('e');
|
||||
btnNewButton.setBounds(372, 20, 154, 23);
|
||||
|
|
Loading…
Reference in a new issue