Interface toujours pas ouf

This commit is contained in:
Theau Giraud 2020-12-15 16:34:18 +01:00
parent fc16e1a74e
commit 92893d2a03

View file

@ -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 = ""; private JLabel Pseudolabel;
final JLabel Pseudolabel = new JLabel("Pseudo: " + Pseudolabeltext); private JTextField PseudotextField;
private JTextField PseudotextField;
private JButton convertPseudo;
//Specifies the look and feel to use. Valid values: private JLabel Messagelabel;
//null (use the default), "Metal", "System", "Motif", "GTK+" private JTextField MessagetextField;
final static String LOOKANDFEEL = null;
public Component createComponents() { private JButton RemoteUserButton;
PseudotextField = new JTextField(); private JLabel RemoteUserlabel;
PseudotextField.setColumns(10);
PseudotextField.setText("Enter pseudo");
convertPseudo = new JButton("Convert Pseudo"); //Specifies the look and feel to use. Valid values:
convertPseudo.addActionListener(this); //null (use the default), "Metal", "System", "Motif", "GTK+"
final static String LOOKANDFEEL = "System";
Pseudolabel.setLabelFor(PseudotextField); public Component createComponents() {
PseudotextField = new JTextField(); //Pseudo setup
PseudotextField.setColumns(10);
PseudotextField.addActionListener(this);
Pseudolabel = new JLabel("Enter username: ");
Pseudolabel.setLabelFor(PseudotextField);
/* MessagetextField = new JTextField(); //Messages setup
* An easy way to put space between a top-level container MessagetextField.setColumns(10);
* and its contents is to put the contents in a JPanel MessagetextField.addActionListener(this);
* that has an "empty" border. Messagelabel = new JLabel("Message field: ");
*/ Messagelabel.setLabelFor(MessagetextField);
JPanel pane = new JPanel(new GridLayout(0, 1)); MessagetextField.setVisible(false);
pane.add(PseudotextField); Messagelabel.setVisible(false);
pane.add(Pseudolabel);
pane.add(convertPseudo);
pane.setBorder(BorderFactory.createEmptyBorder(
30, //top
30, //left
10, //bottom
30) //right
);
return pane; 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);
// Modify the event handler code depending on which button is pressed. /*
// If the 1st button is pressed, increase the numClicks value by 1, else * An easy way to put space between a top-level container
// increase the value by 1000. * and its contents is to put the contents in a JPanel
public void actionPerformed(ActionEvent e) { * that has an "empty" border.
String texteUtilisateur = PseudotextField.getText(); */
Pseudolabel.setText("Pseudo: " + texteUtilisateur); 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
);
private static void initLookAndFeel() { return pane;
}
// Swing allows you to specify which look and feel your program uses- public void actionPerformed(ActionEvent e) {
// -Java, if(e.getSource() == PseudotextField) { //Changing pseudo
// GTK+, Windows, and so on as shown below. String Textinput = PseudotextField.getText();
String lookAndFeel = null; 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();
}
}
if (LOOKANDFEEL != null) { public void showRemoteUserList() {
if (LOOKANDFEEL.equals("Metal")) { RemoteUserlabel.setVisible(true);
lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName(); RemoteUserlabel.setText("Remote users");
} 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 static void initLookAndFeel() {
} catch (ClassNotFoundException e) { // Swing allows you to specify which look and feel your program uses-
System.err.println("Couldn't find class for specified look and feel:" + lookAndFeel); // -Java,
System.err.println("Did you include the L&F library in the class path?"); // GTK+, Windows, and so on as shown below.
System.err.println("Using the default look and feel."); String lookAndFeel = null;
} 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();
}
}
}
/** if (LOOKANDFEEL != null) {
* Create the GUI and show it. For thread safety, if (LOOKANDFEEL.equals("Metal")) {
* this method should be invoked from the lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
* event-dispatching thread. } else if (LOOKANDFEEL.equals("System")) {
*/ lookAndFeel = UIManager.getSystemLookAndFeelClassName();
private static void createAndShowGUI() { } else if (LOOKANDFEEL.equals("Motif")) {
//Set the look and feel. lookAndFeel = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
initLookAndFeel(); } 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();
}
}
}
//Make sure we have nice window decorations. /**
JFrame.setDefaultLookAndFeelDecorated(true); * 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();
//Create and set up the window. //Make sure we have nice window decorations.
JFrame frame = new JFrame("SwingApplication"); JFrame.setDefaultLookAndFeelDecorated(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Interface app = new Interface(); //Create and set up the window.
Component contents = app.createComponents(); JFrame frame = new JFrame("SwingApplication");
frame.getContentPane().add(contents, BorderLayout.CENTER); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Display the window. Interface app = new Interface();
frame.pack(); Component contents = app.createComponents();
frame.setVisible(true); frame.getContentPane().add(contents, BorderLayout.CENTER);
}
/* //Display the window.
public static void main(String[] args) { frame.pack();
//Schedule a job for the event-dispatching thread: frame.setVisible(true);
//creating and showing this applications GUI. }
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() { public static void main(String[] args) throws IOException {
createAndShowGUI(); //Schedule a job for the event-dispatching thread:
} //creating and showing this applications GUI.
}); javax.swing.SwingUtilities.invokeLater(new Runnable() {
}*/ public void run() {
createAndShowGUI();
}
});
}
} }