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,125 +3,156 @@ 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 = "";
|
|
||||||
final JLabel Pseudolabel = new JLabel("Pseudo: " + Pseudolabeltext);
|
|
||||||
private JTextField PseudotextField;
|
|
||||||
private JButton convertPseudo;
|
|
||||||
|
|
||||||
//Specifies the look and feel to use. Valid values:
|
|
||||||
//null (use the default), "Metal", "System", "Motif", "GTK+"
|
|
||||||
final static String LOOKANDFEEL = null;
|
|
||||||
|
|
||||||
public Component createComponents() {
|
|
||||||
PseudotextField = new JTextField();
|
|
||||||
PseudotextField.setColumns(10);
|
|
||||||
PseudotextField.setText("Enter pseudo");
|
|
||||||
|
|
||||||
convertPseudo = new JButton("Convert Pseudo");
|
|
||||||
convertPseudo.addActionListener(this);
|
|
||||||
|
|
||||||
Pseudolabel.setLabelFor(PseudotextField);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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);
|
|
||||||
pane.add(Pseudolabel);
|
|
||||||
pane.add(convertPseudo);
|
|
||||||
pane.setBorder(BorderFactory.createEmptyBorder(
|
|
||||||
30, //top
|
|
||||||
30, //left
|
|
||||||
10, //bottom
|
|
||||||
30) //right
|
|
||||||
);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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.
|
|
||||||
String lookAndFeel = null;
|
|
||||||
|
|
||||||
if (LOOKANDFEEL != null) {
|
|
||||||
if (LOOKANDFEEL.equals("Metal")) {
|
|
||||||
lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
|
|
||||||
} else if (LOOKANDFEEL.equals("System")) {
|
|
||||||
lookAndFeel = UIManager.getSystemLookAndFeelClassName();
|
|
||||||
} else if (LOOKANDFEEL.equals("Motif")) {
|
|
||||||
lookAndFeel = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
|
|
||||||
} else if (LOOKANDFEEL.equals("GTK+")) { //new in 1.4.2
|
|
||||||
lookAndFeel = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
|
|
||||||
} else {
|
|
||||||
System.err.println("Unexpected value of LOOKANDFEEL specified: " + LOOKANDFEEL);
|
|
||||||
lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {UIManager.setLookAndFeel(lookAndFeel);
|
private JLabel Pseudolabel;
|
||||||
} catch (ClassNotFoundException e) {
|
private JTextField PseudotextField;
|
||||||
System.err.println("Couldn't find class for specified look and feel:" + lookAndFeel);
|
|
||||||
System.err.println("Did you include the L&F library in the class path?");
|
|
||||||
System.err.println("Using the default look and feel.");
|
|
||||||
} catch (UnsupportedLookAndFeelException e) {
|
|
||||||
System.err.println("Can't use the specified look and feel (" + lookAndFeel+ ") on this platform.");
|
|
||||||
System.err.println("Using the default look and feel.");
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.err.println("Couldn't get specified look and feel (" + lookAndFeel + "), for some reason.");
|
|
||||||
System.err.println("Using the default look and feel.");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create the GUI and show it. For thread safety,
|
|
||||||
* this method should be invoked from the
|
|
||||||
* event-dispatching thread.
|
|
||||||
*/
|
|
||||||
private static void createAndShowGUI() {
|
|
||||||
//Set the look and feel.
|
|
||||||
initLookAndFeel();
|
|
||||||
|
|
||||||
//Make sure we have nice window decorations.
|
private JLabel Messagelabel;
|
||||||
JFrame.setDefaultLookAndFeelDecorated(true);
|
private JTextField MessagetextField;
|
||||||
|
|
||||||
//Create and set up the window.
|
private JButton RemoteUserButton;
|
||||||
JFrame frame = new JFrame("SwingApplication");
|
private JLabel RemoteUserlabel;
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
|
|
||||||
Interface app = new Interface();
|
//Specifies the look and feel to use. Valid values:
|
||||||
Component contents = app.createComponents();
|
//null (use the default), "Metal", "System", "Motif", "GTK+"
|
||||||
frame.getContentPane().add(contents, BorderLayout.CENTER);
|
final static String LOOKANDFEEL = "System";
|
||||||
|
|
||||||
//Display the window.
|
public Component createComponents() {
|
||||||
frame.pack();
|
PseudotextField = new JTextField(); //Pseudo setup
|
||||||
frame.setVisible(true);
|
PseudotextField.setColumns(10);
|
||||||
}
|
PseudotextField.addActionListener(this);
|
||||||
/*
|
Pseudolabel = new JLabel("Enter username: ");
|
||||||
public static void main(String[] args) {
|
Pseudolabel.setLabelFor(PseudotextField);
|
||||||
//Schedule a job for the event-dispatching thread:
|
|
||||||
//creating and showing this application’s GUI.
|
MessagetextField = new JTextField(); //Messages setup
|
||||||
javax.swing.SwingUtilities.invokeLater(new Runnable() {
|
MessagetextField.setColumns(10);
|
||||||
public void run() {
|
MessagetextField.addActionListener(this);
|
||||||
createAndShowGUI();
|
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, 2));
|
||||||
|
pane.add(Pseudolabel);
|
||||||
|
pane.add(PseudotextField);
|
||||||
|
pane.add(Messagelabel);
|
||||||
|
pane.add(MessagetextField);
|
||||||
|
pane.add(RemoteUserButton);
|
||||||
|
pane.add(RemoteUserlabel);
|
||||||
|
pane.setBorder(BorderFactory.createEmptyBorder(
|
||||||
|
30, //top
|
||||||
|
30, //left
|
||||||
|
10, //bottom
|
||||||
|
30) //right
|
||||||
|
);
|
||||||
|
|
||||||
|
return pane;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
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.
|
||||||
|
String lookAndFeel = null;
|
||||||
|
|
||||||
|
if (LOOKANDFEEL != null) {
|
||||||
|
if (LOOKANDFEEL.equals("Metal")) {
|
||||||
|
lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
|
||||||
|
} else if (LOOKANDFEEL.equals("System")) {
|
||||||
|
lookAndFeel = UIManager.getSystemLookAndFeelClassName();
|
||||||
|
} else if (LOOKANDFEEL.equals("Motif")) {
|
||||||
|
lookAndFeel = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
|
||||||
|
} else if (LOOKANDFEEL.equals("GTK+")) { //new in 1.4.2
|
||||||
|
lookAndFeel = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
|
||||||
|
} else {
|
||||||
|
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);
|
||||||
|
System.err.println("Did you include the L&F library in the class path?");
|
||||||
|
System.err.println("Using the default look and feel.");
|
||||||
|
} catch (UnsupportedLookAndFeelException e) {
|
||||||
|
System.err.println("Can't use the specified look and feel (" + lookAndFeel+ ") on this platform.");
|
||||||
|
System.err.println("Using the default look and feel.");
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("Couldn't get specified look and feel (" + lookAndFeel + "), for some reason.");
|
||||||
|
System.err.println("Using the default look and feel.");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the GUI and show it. For thread safety,
|
||||||
|
* this method should be invoked from the
|
||||||
|
* event-dispatching thread.
|
||||||
|
*/
|
||||||
|
private static void createAndShowGUI() {
|
||||||
|
//Set the look and feel.
|
||||||
|
initLookAndFeel();
|
||||||
|
|
||||||
|
//Make sure we have nice window decorations.
|
||||||
|
JFrame.setDefaultLookAndFeelDecorated(true);
|
||||||
|
|
||||||
|
//Create and set up the window.
|
||||||
|
JFrame frame = new JFrame("SwingApplication");
|
||||||
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
|
Interface app = new Interface();
|
||||||
|
Component contents = app.createComponents();
|
||||||
|
frame.getContentPane().add(contents, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
//Display the window.
|
||||||
|
frame.pack();
|
||||||
|
frame.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) throws IOException {
|
||||||
|
//Schedule a job for the event-dispatching thread:
|
||||||
|
//creating and showing this application’s GUI.
|
||||||
|
javax.swing.SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
createAndShowGUI();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue