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