Merge branch 'master' of https://git.etud.insa-toulouse.fr/gallois/Clavardage
This commit is contained in:
commit
986ad70f27
1 changed files with 144 additions and 113 deletions
|
@ -3,37 +3,56 @@ package view;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class Interface implements ActionListener {
|
public class Interface implements ActionListener {
|
||||||
|
|
||||||
private String Pseudolabeltext = "";
|
private JLabel Pseudolabel;
|
||||||
final JLabel Pseudolabel = new JLabel("Pseudo: " + Pseudolabeltext);
|
|
||||||
private JTextField PseudotextField;
|
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:
|
//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+"
|
||||||
final static String LOOKANDFEEL = null;
|
final static String LOOKANDFEEL = "System";
|
||||||
|
|
||||||
public Component createComponents() {
|
public Component createComponents() {
|
||||||
PseudotextField = new JTextField();
|
PseudotextField = new JTextField(); //Pseudo setup
|
||||||
PseudotextField.setColumns(10);
|
PseudotextField.setColumns(10);
|
||||||
PseudotextField.setText("Enter pseudo");
|
PseudotextField.addActionListener(this);
|
||||||
|
Pseudolabel = new JLabel("Enter username: ");
|
||||||
convertPseudo = new JButton("Convert Pseudo");
|
|
||||||
convertPseudo.addActionListener(this);
|
|
||||||
|
|
||||||
Pseudolabel.setLabelFor(PseudotextField);
|
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
|
* 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
|
||||||
* that has an "empty" border.
|
* that has an "empty" border.
|
||||||
*/
|
*/
|
||||||
JPanel pane = new JPanel(new GridLayout(0, 1));
|
JPanel pane = new JPanel(new GridLayout(0, 2));
|
||||||
pane.add(PseudotextField);
|
|
||||||
pane.add(Pseudolabel);
|
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(
|
pane.setBorder(BorderFactory.createEmptyBorder(
|
||||||
30, //top
|
30, //top
|
||||||
30, //left
|
30, //left
|
||||||
|
@ -44,16 +63,29 @@ public class Interface implements ActionListener {
|
||||||
return pane;
|
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) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
String texteUtilisateur = PseudotextField.getText();
|
if(e.getSource() == PseudotextField) { //Changing pseudo
|
||||||
Pseudolabel.setText("Pseudo: " + texteUtilisateur);
|
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() {
|
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,
|
||||||
// GTK+, Windows, and so on as shown below.
|
// 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);
|
System.err.println("Unexpected value of LOOKANDFEEL specified: " + LOOKANDFEEL);
|
||||||
lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
|
lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {UIManager.setLookAndFeel(lookAndFeel);
|
try {UIManager.setLookAndFeel(lookAndFeel);
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
System.err.println("Couldn't find class for specified look and feel:" + lookAndFeel);
|
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.pack();
|
||||||
frame.setVisible(true);
|
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:
|
//Schedule a job for the event-dispatching thread:
|
||||||
//creating and showing this application’s GUI.
|
//creating and showing this application’s GUI.
|
||||||
javax.swing.SwingUtilities.invokeLater(new Runnable() {
|
javax.swing.SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
@ -122,6 +153,6 @@ public class Interface implements ActionListener {
|
||||||
createAndShowGUI();
|
createAndShowGUI();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue