Browse Source

Interface toujours pas ouf

Theau Giraud 3 years ago
parent
commit
92893d2a03
1 changed files with 141 additions and 110 deletions
  1. 141
    110
      Application/Clavardage/src/view/Interface.java

+ 141
- 110
Application/Clavardage/src/view/Interface.java View File

@@ -3,125 +3,156 @@ package view;
3 3
 import javax.swing.*;
4 4
 import java.awt.*;
5 5
 import java.awt.event.*;
6
+import java.io.IOException;
6 7
 
7 8
 public class Interface implements ActionListener {
9
+		
10
+	private JLabel Pseudolabel;
11
+	private JTextField PseudotextField;
8 12
 	
9
- private String Pseudolabeltext = "";
10
- final JLabel Pseudolabel = new JLabel("Pseudo: " + Pseudolabeltext);
11
- private JTextField PseudotextField;
12
- private JButton convertPseudo;
13
-
14
- //Specifies the look and feel to use. Valid values:
15
- //null (use the default), "Metal", "System", "Motif", "GTK+"
16
- final static String LOOKANDFEEL = null;
17
-
18
- public Component createComponents() {
19
-	 PseudotextField = new JTextField();
20
-	 PseudotextField.setColumns(10);
21
-	 PseudotextField.setText("Enter pseudo");
22
-	 
23
-	 convertPseudo = new JButton("Convert Pseudo");
24
-	 convertPseudo.addActionListener(this);
25
-	 
26
-	 Pseudolabel.setLabelFor(PseudotextField);
27
-	
28
-	 /*
29
-	 * An easy way to put space between a top-level container
30
-	 * and its contents is to put the contents in a JPanel
31
-	 * that has an "empty" border.
32
-	 */
33
-	 JPanel pane = new JPanel(new GridLayout(0, 1));
34
-	 pane.add(PseudotextField);
35
-	 pane.add(Pseudolabel);
36
-	 pane.add(convertPseudo);
37
-	 pane.setBorder(BorderFactory.createEmptyBorder(
38
-	 30, //top
39
-	 30, //left
40
-	 10, //bottom
41
-	 30) //right
42
-	 );
13
+	private JLabel Messagelabel;
14
+	private JTextField MessagetextField;
43 15
 	
44
-	 return pane;
45
- }
46
- 
47
- // Modify the event handler code depending on which button is pressed.
48
- // If the 1st button is pressed, increase the numClicks value by 1, else
49
- // increase the value by 1000.
50
- public void actionPerformed(ActionEvent e) {
51
-	    String texteUtilisateur = PseudotextField.getText();
52
-	    Pseudolabel.setText("Pseudo: " + texteUtilisateur);
53
- }
54
- 
55
- private static void initLookAndFeel() {
16
+	private JButton RemoteUserButton;
17
+	private JLabel RemoteUserlabel;
56 18
 	
57
-	 // Swing allows you to specify which look and feel your program uses-
58
-	 // -Java,
59
-	 // GTK+, Windows, and so on as shown below.
60
-	 String lookAndFeel = null;
19
+	//Specifies the look and feel to use. Valid values:
20
+	//null (use the default), "Metal", "System", "Motif", "GTK+"
21
+	final static String LOOKANDFEEL = "System";
61 22
 	
62
-	 if (LOOKANDFEEL != null) {
63
-		 if (LOOKANDFEEL.equals("Metal")) {
64
-			 lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
65
-		 } else if (LOOKANDFEEL.equals("System")) {
66
-			 lookAndFeel = UIManager.getSystemLookAndFeelClassName();
67
-		 } else if (LOOKANDFEEL.equals("Motif")) {
68
-			 lookAndFeel = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
69
-		 } else if (LOOKANDFEEL.equals("GTK+")) { //new in 1.4.2
70
-			 lookAndFeel = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
71
-		 } else {
72
-			 System.err.println("Unexpected value of LOOKANDFEEL specified: " + LOOKANDFEEL);
73
-			 lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
74
-		 }
23
+	public Component createComponents() {
24
+		PseudotextField = new JTextField();        //Pseudo setup
25
+		PseudotextField.setColumns(10);
26
+		PseudotextField.addActionListener(this);
27
+		Pseudolabel = new JLabel("Enter username: ");
28
+		Pseudolabel.setLabelFor(PseudotextField);
75 29
 		
76
-		 try {UIManager.setLookAndFeel(lookAndFeel);
77
-		 } catch (ClassNotFoundException e) {
78
-			 System.err.println("Couldn't find class for specified look and feel:" + lookAndFeel);
79
-			 System.err.println("Did you include the L&F library in the class path?");
80
-			 System.err.println("Using the default look and feel.");
81
-		 } catch (UnsupportedLookAndFeelException e) {
82
-			 System.err.println("Can't use the specified look and feel (" + lookAndFeel+ ") on this platform.");
83
-			 System.err.println("Using the default look and feel.");
84
-		 } catch (Exception e) {
85
-			 System.err.println("Couldn't get specified look and feel (" + lookAndFeel + "), for some reason.");
86
-			 System.err.println("Using the default look and feel.");
87
-			 e.printStackTrace();
88
-		 }
89
-	 }
90
- }
91
-
92
- /**
93
- * Create the GUI and show it. For thread safety,
94
- * this method should be invoked from the
95
- * event-dispatching thread.
96
- */
97
- private static void createAndShowGUI() {
98
-	 //Set the look and feel.
99
-	 initLookAndFeel();
100
-	
101
-	 //Make sure we have nice window decorations.
102
-	 JFrame.setDefaultLookAndFeelDecorated(true);
30
+		MessagetextField = new JTextField();       //Messages setup
31
+		MessagetextField.setColumns(10);
32
+		MessagetextField.addActionListener(this);
33
+		Messagelabel = new JLabel("Message field: ");
34
+		Messagelabel.setLabelFor(MessagetextField);
35
+		MessagetextField.setVisible(false);
36
+		Messagelabel.setVisible(false);
37
+		
38
+		RemoteUserButton = new JButton("Click here to get Remote User list");          //Remote user list setup
39
+		RemoteUserButton.addActionListener(this);
40
+		RemoteUserlabel = new JLabel("Remote User List:");
41
+		RemoteUserlabel.setLabelFor(RemoteUserButton);
42
+		RemoteUserlabel.setVisible(false);
43
+			
44
+		/*
45
+		* An easy way to put space between a top-level container
46
+		* and its contents is to put the contents in a JPanel
47
+		* that has an "empty" border.
48
+		*/
49
+		JPanel pane = new JPanel(new GridLayout(0, 2));
50
+		pane.add(Pseudolabel);
51
+		pane.add(PseudotextField);
52
+		pane.add(Messagelabel);
53
+		pane.add(MessagetextField);
54
+		pane.add(RemoteUserButton);
55
+		pane.add(RemoteUserlabel);
56
+		pane.setBorder(BorderFactory.createEmptyBorder(
57
+									30, //top
58
+									30, //left
59
+									10, //bottom
60
+									30) //right
61
+		);
62
+			
63
+		return pane;
64
+	}
103 65
 	
104
-	 //Create and set up the window.
105
-	 JFrame frame = new JFrame("SwingApplication");
106
-	 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
66
+	public void actionPerformed(ActionEvent e) {
67
+		if(e.getSource() == PseudotextField) {                //Changing pseudo
68
+			String Textinput = PseudotextField.getText();
69
+			Pseudolabel.setText("Your current username is: " + Textinput);
70
+			MessagetextField.setVisible(true);
71
+			Messagelabel.setVisible(true);
72
+			//TODO Appeler setPseudo(TextInput) à chaque fois
73
+		}else if(e.getSource() == MessagetextField){          //Messages
74
+			String Textinput = MessagetextField.getText();
75
+			Messagelabel.setText("Message: " + Textinput);
76
+			//TODO mettre Textinput dans la database
77
+			MessagetextField.setText("");
78
+		}else if(e.getSource() == RemoteUserButton) {         //Shows remote user list
79
+			showRemoteUserList();
80
+		}
81
+	}
107 82
 	
108
-	 Interface app = new Interface();
109
-	 Component contents = app.createComponents();
110
-	 frame.getContentPane().add(contents, BorderLayout.CENTER);
83
+	public void showRemoteUserList() {
84
+		RemoteUserlabel.setVisible(true);
85
+		RemoteUserlabel.setText("Remote users");
86
+	}
87
+	 
88
+	private static void initLookAndFeel() {
89
+		// Swing allows you to specify which look and feel your program uses-
90
+		// -Java,
91
+		// GTK+, Windows, and so on as shown below.
92
+		String lookAndFeel = null;
93
+			
94
+		if (LOOKANDFEEL != null) {
95
+			if (LOOKANDFEEL.equals("Metal")) {
96
+				lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
97
+			} else if (LOOKANDFEEL.equals("System")) {
98
+				lookAndFeel = UIManager.getSystemLookAndFeelClassName();
99
+			} else if (LOOKANDFEEL.equals("Motif")) {
100
+				lookAndFeel = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
101
+			} else if (LOOKANDFEEL.equals("GTK+")) { //new in 1.4.2
102
+				lookAndFeel = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
103
+			} else {
104
+				System.err.println("Unexpected value of LOOKANDFEEL specified: " + LOOKANDFEEL);
105
+				lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
106
+			}	
107
+			try {UIManager.setLookAndFeel(lookAndFeel);
108
+			} catch (ClassNotFoundException e) {
109
+				System.err.println("Couldn't find class for specified look and feel:" + lookAndFeel);
110
+				System.err.println("Did you include the L&F library in the class path?");
111
+				System.err.println("Using the default look and feel.");
112
+			} catch (UnsupportedLookAndFeelException e) {
113
+				System.err.println("Can't use the specified look and feel (" + lookAndFeel+ ") on this platform.");
114
+				System.err.println("Using the default look and feel.");
115
+			} catch (Exception e) {
116
+				System.err.println("Couldn't get specified look and feel (" + lookAndFeel + "), for some reason.");
117
+				System.err.println("Using the default look and feel.");
118
+				e.printStackTrace();
119
+			}
120
+		}
121
+	}
111 122
 	
112
-	 //Display the window.
113
-	 frame.pack();
114
-	 frame.setVisible(true);
115
-	 }
116
-	/*
117
-	 public static void main(String[] args) {
118
-	 //Schedule a job for the event-dispatching thread:
119
-	 //creating and showing this application’s GUI.
120
-	 javax.swing.SwingUtilities.invokeLater(new Runnable() {
121
-		 public void run() {
122
-			 createAndShowGUI();
123
-		 }
124
-	 	});
125
-	 }*/
123
+	/**
124
+	* Create the GUI and show it. For thread safety,
125
+	* this method should be invoked from the
126
+	* event-dispatching thread.
127
+	*/
128
+	private static void createAndShowGUI() {
129
+		//Set the look and feel.
130
+		initLookAndFeel();
131
+		
132
+		//Make sure we have nice window decorations.
133
+		JFrame.setDefaultLookAndFeelDecorated(true);
134
+			
135
+		//Create and set up the window.
136
+		JFrame frame = new JFrame("SwingApplication");
137
+		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
138
+		
139
+		Interface app = new Interface();
140
+		Component contents = app.createComponents();
141
+		frame.getContentPane().add(contents, BorderLayout.CENTER);
142
+			
143
+		//Display the window.
144
+		frame.pack();
145
+		frame.setVisible(true);
146
+	}
147
+		
148
+	public static void main(String[] args) throws IOException {
149
+		//Schedule a job for the event-dispatching thread:
150
+		//creating and showing this application’s GUI.
151
+		javax.swing.SwingUtilities.invokeLater(new Runnable() {
152
+			public void run() {
153
+				createAndShowGUI();
154
+			}
155
+		});
156
+	}
126 157
 }
127 158
 

Loading…
Cancel
Save