Menu déroulant external users dans Interface
This commit is contained in:
parent
233fcfd78c
commit
021ed7cec0
1 changed files with 25 additions and 16 deletions
|
@ -4,7 +4,10 @@ import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import controller.Controller;
|
import controller.Controller;
|
||||||
|
import model.RemoteUser;
|
||||||
|
|
||||||
public class Interface implements ActionListener {
|
public class Interface implements ActionListener {
|
||||||
|
|
||||||
|
@ -17,7 +20,7 @@ public class Interface implements ActionListener {
|
||||||
public JTextField MessagetextField;
|
public JTextField MessagetextField;
|
||||||
|
|
||||||
public JButton RemoteUserButton;
|
public JButton RemoteUserButton;
|
||||||
public JLabel RemoteUserlabel;
|
public JComboBox RemoteUserbox;
|
||||||
|
|
||||||
//Specifies the look and feel to use. Valid values:
|
//Specifies the look and feel to use. Valid values:
|
||||||
//null (use the default), "Metal", "System", "Motif", "GTK+"
|
//null (use the default), "Metal", "System", "Motif", "GTK+"
|
||||||
|
@ -34,6 +37,18 @@ public class Interface implements ActionListener {
|
||||||
Pseudolabel = new JLabel("Your current username is: " + hisController.getMyUser().getPseudo());
|
Pseudolabel = new JLabel("Your current username is: " + hisController.getMyUser().getPseudo());
|
||||||
Pseudolabel.setLabelFor(PseudotextField);
|
Pseudolabel.setLabelFor(PseudotextField);
|
||||||
|
|
||||||
|
RemoteUserButton = new JButton("Click here to get Remote User list"); //Remote user list setup
|
||||||
|
RemoteUserButton.addActionListener(this);
|
||||||
|
//Convert the Userlist to Pseudotab
|
||||||
|
String[] pseudotab = new String[hisController.getMyUser().getRemoteUsersList().size()];
|
||||||
|
for(int i=0; i < hisController.getMyUser().getRemoteUsersList().size(); i++) {
|
||||||
|
pseudotab[i] = "(" + Integer.toString(i) + "): " + hisController.getMyUser().getRemoteUsersList().get(i).getPseudo();
|
||||||
|
}
|
||||||
|
RemoteUserbox = new JComboBox(pseudotab);
|
||||||
|
RemoteUserbox.setEditable(true);
|
||||||
|
RemoteUserbox.addActionListener(this);
|
||||||
|
RemoteUserbox.setVisible(false);
|
||||||
|
|
||||||
MessagetextField = new JTextField(); //Messages setup
|
MessagetextField = new JTextField(); //Messages setup
|
||||||
MessagetextField.setColumns(10);
|
MessagetextField.setColumns(10);
|
||||||
MessagetextField.addActionListener(this);
|
MessagetextField.addActionListener(this);
|
||||||
|
@ -42,12 +57,6 @@ public class Interface implements ActionListener {
|
||||||
MessagetextField.setVisible(false);
|
MessagetextField.setVisible(false);
|
||||||
Messagelabel.setVisible(false);
|
Messagelabel.setVisible(false);
|
||||||
|
|
||||||
RemoteUserButton = new JButton("Click here to get Remote User list"); //Remote user list setup
|
|
||||||
RemoteUserButton.addActionListener(this);
|
|
||||||
RemoteUserlabel = new JLabel("Remote User List:");
|
|
||||||
RemoteUserlabel.setLabelFor(RemoteUserButton);
|
|
||||||
RemoteUserlabel.setVisible(false);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* An easy way to put space between a top-level container
|
* An easy way to put space between a top-level container
|
||||||
* and its contents is to put the contents in a JPanel
|
* and its contents is to put the contents in a JPanel
|
||||||
|
@ -56,10 +65,10 @@ public class Interface implements ActionListener {
|
||||||
JPanel pane = new JPanel(new GridLayout(0, 2));
|
JPanel pane = new JPanel(new GridLayout(0, 2));
|
||||||
pane.add(Pseudolabel);
|
pane.add(Pseudolabel);
|
||||||
pane.add(PseudotextField);
|
pane.add(PseudotextField);
|
||||||
|
pane.add(RemoteUserButton);
|
||||||
|
pane.add(RemoteUserbox);
|
||||||
pane.add(Messagelabel);
|
pane.add(Messagelabel);
|
||||||
pane.add(MessagetextField);
|
pane.add(MessagetextField);
|
||||||
pane.add(RemoteUserButton);
|
|
||||||
pane.add(RemoteUserlabel);
|
|
||||||
pane.setBorder(BorderFactory.createEmptyBorder(
|
pane.setBorder(BorderFactory.createEmptyBorder(
|
||||||
30, //top
|
30, //top
|
||||||
30, //left
|
30, //left
|
||||||
|
@ -79,7 +88,7 @@ public class Interface implements ActionListener {
|
||||||
try {
|
try {
|
||||||
hisController.changePseudo();
|
hisController.changePseudo();
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
// TODO Auto-generated catch block
|
System.out.println("Error in change pseudo\n");
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
}else if(e.getSource() == MessagetextField){ //Messages
|
}else if(e.getSource() == MessagetextField){ //Messages
|
||||||
|
@ -88,15 +97,15 @@ public class Interface implements ActionListener {
|
||||||
//TODO mettre Textinput dans la database
|
//TODO mettre Textinput dans la database
|
||||||
MessagetextField.setText("");
|
MessagetextField.setText("");
|
||||||
}else if(e.getSource() == RemoteUserButton) { //Shows remote user list
|
}else if(e.getSource() == RemoteUserButton) { //Shows remote user list
|
||||||
showRemoteUserList();
|
RemoteUserbox.setVisible(true);
|
||||||
|
}else {
|
||||||
|
JComboBox cb = (JComboBox)e.getSource(); //Casts obscurs pour récupérer le numéro du user dans la liste
|
||||||
|
int selectedUsernb = Integer.parseInt(String.valueOf(((String) cb.getSelectedItem()).charAt(1)));
|
||||||
|
System.out.println("selectedUsernb: " + selectedUsernb); //Test pour voir si ça marche
|
||||||
|
//TODO Utiliser ce selectedUsernb pour faire le lien avec openSession de Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showRemoteUserList() {
|
|
||||||
RemoteUserlabel.setVisible(true);
|
|
||||||
RemoteUserlabel.setText("Remote users");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void initLookAndFeel() {
|
private static void initLookAndFeel() {
|
||||||
// Swing allows you to specify which look and feel your program uses-
|
// Swing allows you to specify which look and feel your program uses-
|
||||||
// -Java,
|
// -Java,
|
||||||
|
|
Loading…
Reference in a new issue