This commit is contained in:
LMAGallois 2020-12-15 17:42:15 +01:00
commit 986ad70f27

View file

@ -3,37 +3,56 @@ package view;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
public class Interface implements ActionListener {
private String Pseudolabeltext = "";
final JLabel Pseudolabel = new JLabel("Pseudo: " + Pseudolabeltext);
private JLabel Pseudolabel;
private JTextField PseudotextField;
private JButton convertPseudo;
private JLabel Messagelabel;
private JTextField MessagetextField;
private JButton RemoteUserButton;
private JLabel RemoteUserlabel;
//Specifies the look and feel to use. Valid values:
//null (use the default), "Metal", "System", "Motif", "GTK+"
final static String LOOKANDFEEL = null;
final static String LOOKANDFEEL = "System";
public Component createComponents() {
PseudotextField = new JTextField();
PseudotextField = new JTextField(); //Pseudo setup
PseudotextField.setColumns(10);
PseudotextField.setText("Enter pseudo");
convertPseudo = new JButton("Convert Pseudo");
convertPseudo.addActionListener(this);
PseudotextField.addActionListener(this);
Pseudolabel = new JLabel("Enter username: ");
Pseudolabel.setLabelFor(PseudotextField);
MessagetextField = new JTextField(); //Messages setup
MessagetextField.setColumns(10);
MessagetextField.addActionListener(this);
Messagelabel = new JLabel("Message field: ");
Messagelabel.setLabelFor(MessagetextField);
MessagetextField.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
* and its contents is to put the contents in a JPanel
* that has an "empty" border.
*/
JPanel pane = new JPanel(new GridLayout(0, 1));
pane.add(PseudotextField);
JPanel pane = new JPanel(new GridLayout(0, 2));
pane.add(Pseudolabel);
pane.add(convertPseudo);
pane.add(PseudotextField);
pane.add(Messagelabel);
pane.add(MessagetextField);
pane.add(RemoteUserButton);
pane.add(RemoteUserlabel);
pane.setBorder(BorderFactory.createEmptyBorder(
30, //top
30, //left
@ -44,16 +63,29 @@ public class Interface implements ActionListener {
return pane;
}
// Modify the event handler code depending on which button is pressed.
// If the 1st button is pressed, increase the numClicks value by 1, else
// increase the value by 1000.
public void actionPerformed(ActionEvent e) {
String texteUtilisateur = PseudotextField.getText();
Pseudolabel.setText("Pseudo: " + texteUtilisateur);
if(e.getSource() == PseudotextField) { //Changing pseudo
String Textinput = PseudotextField.getText();
Pseudolabel.setText("Your current username is: " + Textinput);
MessagetextField.setVisible(true);
Messagelabel.setVisible(true);
//TODO Appeler setPseudo(TextInput) à chaque fois
}else if(e.getSource() == MessagetextField){ //Messages
String Textinput = MessagetextField.getText();
Messagelabel.setText("Message: " + Textinput);
//TODO mettre Textinput dans la database
MessagetextField.setText("");
}else if(e.getSource() == RemoteUserButton) { //Shows remote user list
showRemoteUserList();
}
}
public void showRemoteUserList() {
RemoteUserlabel.setVisible(true);
RemoteUserlabel.setText("Remote users");
}
private static void initLookAndFeel() {
// Swing allows you to specify which look and feel your program uses-
// -Java,
// GTK+, Windows, and so on as shown below.
@ -72,7 +104,6 @@ public class Interface implements ActionListener {
System.err.println("Unexpected value of LOOKANDFEEL specified: " + LOOKANDFEEL);
lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
}
try {UIManager.setLookAndFeel(lookAndFeel);
} catch (ClassNotFoundException e) {
System.err.println("Couldn't find class for specified look and feel:" + lookAndFeel);
@ -113,8 +144,8 @@ public class Interface implements ActionListener {
frame.pack();
frame.setVisible(true);
}
/*
public static void main(String[] args) {
public static void main(String[] args) throws IOException {
//Schedule a job for the event-dispatching thread:
//creating and showing this applications GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
@ -122,6 +153,6 @@ public class Interface implements ActionListener {
createAndShowGUI();
}
});
}*/
}
}