MainFrame.java
Go to the documentation of this file.
1 package p2pgui;
2 
3 import java.awt.Frame;
4 import javax.swing.JOptionPane;
5 
11 public class MainFrame extends javax.swing.JFrame {
12 
16  public MainFrame() {
18  }
19 
20 
25  @SuppressWarnings("unchecked")
26  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
27  private void initComponents() {
28 
29  jButton3 = new javax.swing.JButton();
30  jButton4 = new javax.swing.JButton();
31  jButton1 = new javax.swing.JButton();
32  jMenuBar1 = new javax.swing.JMenuBar();
33  jMenu1 = new javax.swing.JMenu();
34  jMenuItem1 = new javax.swing.JMenuItem();
35  jMenu2 = new javax.swing.JMenu();
36  jMenuItem2 = new javax.swing.JMenuItem();
37  jMenuItem3 = new javax.swing.JMenuItem();
38  jMenu3 = new javax.swing.JMenu();
39  jMenuItem4 = new javax.swing.JMenuItem();
40 
41  setTitle("P2PFileSystem - Start");
42  setName("MainFrame"); // NOI18N
43  addWindowListener(new java.awt.event.WindowAdapter() {
44  public void windowClosing(java.awt.event.WindowEvent evt) {
45  formWindowClosing(evt);
46  }
47  });
48 
49  jButton3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
50  jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Server.png"))); // NOI18N
51  jButton3.setText("<html><br><br><br><br><br><br><br><br><br><br><br>Start SERVER </html>");
52  jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
53  jButton3.addActionListener(new java.awt.event.ActionListener() {
54  public void actionPerformed(java.awt.event.ActionEvent evt) {
56  }
57  });
58 
59  jButton4.setFont(new java.awt.Font("Tahoma", 1, 14));
60  jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Client.png"))); // NOI18N
61  jButton4.setText("<html><br><br><br><br><br><br><br><br><br><br><br>Start CLIENT</html>");
62  jButton4.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
63  jButton4.addActionListener(new java.awt.event.ActionListener() {
64  public void actionPerformed(java.awt.event.ActionEvent evt) {
66  }
67  });
68 
69  jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Exit.png"))); // NOI18N
70  jButton1.setText("Exit");
71  jButton1.addActionListener(new java.awt.event.ActionListener() {
72  public void actionPerformed(java.awt.event.ActionEvent evt) {
74  }
75  });
76 
77  jMenu1.setText("File");
78 
79  jMenuItem1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Exit.png"))); // NOI18N
80  jMenuItem1.setText("Exit");
81  jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
82  public void actionPerformed(java.awt.event.ActionEvent evt) {
84  }
85  });
86  jMenu1.add(jMenuItem1);
87 
88  jMenuBar1.add(jMenu1);
89 
90  jMenu2.setText("Action");
91 
92  jMenuItem2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Server_ico.png"))); // NOI18N
93  jMenuItem2.setText("Start Server");
94  jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
95  public void actionPerformed(java.awt.event.ActionEvent evt) {
97  }
98  });
99  jMenu2.add(jMenuItem2);
100 
101  jMenuItem3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Client_ico.png"))); // NOI18N
102  jMenuItem3.setText("Start Client");
103  jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
104  public void actionPerformed(java.awt.event.ActionEvent evt) {
106  }
107  });
108  jMenu2.add(jMenuItem3);
109 
110  jMenuBar1.add(jMenu2);
111 
112  jMenu3.setText("Help");
113 
114  jMenuItem4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Help_ico.png"))); // NOI18N
115  jMenuItem4.setText("About");
116  jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
117  public void actionPerformed(java.awt.event.ActionEvent evt) {
119  }
120  });
121  jMenu3.add(jMenuItem4);
122 
123  jMenuBar1.add(jMenu3);
124 
125  setJMenuBar(jMenuBar1);
126 
127  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
128  getContentPane().setLayout(layout);
129  layout.setHorizontalGroup(
130  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
131  .addGroup(layout.createSequentialGroup()
132  .addGap(49, 49, 49)
133  .addComponent(jButton3)
134  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 79, Short.MAX_VALUE)
135  .addComponent(jButton4)
136  .addGap(60, 60, 60))
137  .addGroup(layout.createSequentialGroup()
138  .addGap(194, 194, 194)
139  .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
140  .addContainerGap(210, Short.MAX_VALUE))
141  );
142  layout.setVerticalGroup(
143  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
144  .addGroup(layout.createSequentialGroup()
145  .addGap(25, 25, 25)
146  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
147  .addComponent(jButton3)
148  .addComponent(jButton4))
149  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 29, Short.MAX_VALUE)
150  .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
151  .addContainerGap())
152  );
153 
154  pack();
155  }// </editor-fold>//GEN-END:initComponents
162  private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
163  ExitFrame dialog = new ExitFrame(new javax.swing.JFrame(), true);
164  dialog.setLocationRelativeTo(null);
165  dialog.setVisible(true);
166  }//GEN-LAST:event_jMenuItem1ActionPerformed
167 
172  private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
173  System.exit(0);
174  }//GEN-LAST:event_formWindowClosing
175 
182  private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
184  JOptionPane.showMessageDialog(null, "Server is already running", "Information", 1);
185  p2putility.Util.logGeneric("Server is already running");
186  }
187  else{
188  ServerFrame x = new ServerFrame();
189  x.setLocationRelativeTo(null);
190  x.setVisible(true);
192  }
194  Frame[] f = Frame.getFrames();
195  for(int i =0; i< f.length; i++)
196  if((f[i].getName()).equals("MainFrame")&&f[i].isVisible())
197  f[i].dispose();
198  }
199  }//GEN-LAST:event_jButton3ActionPerformed
200 
207  private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
208  AboutFrame a = new AboutFrame(new javax.swing.JFrame(), true);
209  a.setLocationRelativeTo(null);
210  a.setVisible(true);
211  }//GEN-LAST:event_jMenuItem4ActionPerformed
212 
219  private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
221  JOptionPane.showMessageDialog(null, "Server is already running", "Information", 1);
222  p2putility.Util.logGeneric("Server is already running");
223  }
224  else{
225  ServerFrame s = new ServerFrame();
226  s.setLocationRelativeTo(null);
227  s.setVisible(true);
229  }
231  Frame[] f = Frame.getFrames();
232  for(int i =0; i< f.length; i++)
233  if((f[i].getName()).equals("MainFrame")&&f[i].isVisible())
234  f[i].dispose();
235  }
236  }//GEN-LAST:event_jMenuItem2ActionPerformed
237 
244  private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
246  JOptionPane.showMessageDialog(null, "Client is already running", "Information", 1);
247  p2putility.Util.logGeneric("Client is already running");
248  }
249  else{
250  ClientFrame c = new ClientFrame();
251  c.setLocationRelativeTo(null);
252  c.setVisible(true);
254  }
256  Frame[] f = Frame.getFrames();
257  for(int i =0; i< f.length; i++)
258  if((f[i].getName()).equals("MainFrame")&&f[i].isVisible())
259  f[i].dispose();
260  }
261  }//GEN-LAST:event_jButton4ActionPerformed
262 
269  private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
271  JOptionPane.showMessageDialog(null, "Client is already running", "Information", 1);
272  p2putility.Util.logGeneric("Client is already running");
273  }
274  else{
275  ClientFrame c = new ClientFrame();
276  c.setLocationRelativeTo(null);
277  c.setVisible(true);
279  }
281  Frame[] f = Frame.getFrames();
282  for(int i =0; i< f.length; i++)
283  if((f[i].getName()).equals("MainFrame")&&f[i].isVisible())
284  f[i].dispose();
285  }
286  }//GEN-LAST:event_jMenuItem3ActionPerformed
287 
294  private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
295  ExitFrame dialog = new ExitFrame(new javax.swing.JFrame(), true);
296  dialog.setLocationRelativeTo(null);
297  dialog.setVisible(true);
298  }//GEN-LAST:event_jButton1ActionPerformed
299 
300 
301  // Variables declaration - do not modify//GEN-BEGIN:variables
302  private javax.swing.JButton jButton1;
303  private javax.swing.JButton jButton3;
304  private javax.swing.JButton jButton4;
305  private javax.swing.JMenu jMenu1;
306  private javax.swing.JMenu jMenu2;
307  private javax.swing.JMenu jMenu3;
308  private javax.swing.JMenuBar jMenuBar1;
309  private javax.swing.JMenuItem jMenuItem1;
310  private javax.swing.JMenuItem jMenuItem2;
311  private javax.swing.JMenuItem jMenuItem3;
312  private javax.swing.JMenuItem jMenuItem4;
313  // End of variables declaration//GEN-END:variables
314 
315 }
static void w_serverOpen(boolean value)
Permette la scrittura della varibile relativa in modo sicuro.
Definition: Config.java:405
javax.swing.JMenu jMenu2
Definition: MainFrame.java:306
Classe che permette la configurazione di tutto il programma in base alle specifiche esigenze dell&#39;ute...
Definition: Config.java:14
Classe che genera graficamente la finestra di "About", con informazioni sul software, la version e gli autori.
Definition: AboutFrame.java:8
javax.swing.JMenuItem jMenuItem2
Definition: MainFrame.java:310
javax.swing.JMenuItem jMenuItem4
Definition: MainFrame.java:312
Classe che implementa metodi vari di utilita&#39; generale.
Definition: Util.java:14
javax.swing.JMenuItem jMenuItem1
Definition: MainFrame.java:309
Classe che genera graficamente la finestra di "Exit".
Definition: ExitFrame.java:7
Classe che implementa il servizio Client.
Classe che implementa il servizio Server.
javax.swing.JButton jButton4
Definition: MainFrame.java:304
javax.swing.JButton jButton1
Definition: MainFrame.java:302
MainFrame()
Costruttore che crea un nuovo MainFrame.
Definition: MainFrame.java:16
void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt)
Azione da effettuare se viene premuto il bottone Exit dal JMenu, istanziando un nuovo ExitFrame...
Definition: MainFrame.java:162
void jButton3ActionPerformed(java.awt.event.ActionEvent evt)
Azioni da effettuare alla pressione del bottone server: controlla se c&#39;e&#39; gia&#39; un server attivo...
Definition: MainFrame.java:182
Classe che genera graficamente la finestra di MainFrame da cui e&#39; possibile istanziare un client e/o ...
Definition: MainFrame.java:11
static void logGeneric(String data)
Scrive i dati in input sul file di log Generico (se questo esiste valido)
Definition: Util.java:132
javax.swing.JMenu jMenu1
Definition: MainFrame.java:305
void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt)
Azioni da effettuare alla pressione del bottone client dal JMenu: controlla se c&#39;e&#39; gia&#39; un client at...
Definition: MainFrame.java:269
void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt)
Azione da effettuare se viene premuto il bottone About, creando un nuovo AboutFrame.
Definition: MainFrame.java:207
javax.swing.JMenuItem jMenuItem3
Definition: MainFrame.java:311
void initComponents()
Metodo chiamato dal costruttore per inizializzare la form WARNING: Do NOT modify this code...
Definition: MainFrame.java:27
static boolean r_serverOpen()
Permette la lettura della varibile relativa in modo sicuro.
Definition: Config.java:400
javax.swing.JButton jButton3
Definition: MainFrame.java:303
void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt)
Azioni da effettuare alla pressione del bottone server dal JMenu: controlla se c&#39;e&#39; gia&#39; un server at...
Definition: MainFrame.java:219
void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
Azione da effettuare se viene premuto il bottone About, creando un nuovo ExitFrame.
Definition: MainFrame.java:294
static boolean r_clientOpen()
Permette la lettura della varibile relativa in modo sicuro.
Definition: Config.java:410
static void w_clientOpen(boolean value)
Permette la scrittura della varibile relativa in modo sicuro.
Definition: Config.java:415
javax.swing.JMenuBar jMenuBar1
Definition: MainFrame.java:308
javax.swing.JMenu jMenu3
Definition: MainFrame.java:307
void jButton4ActionPerformed(java.awt.event.ActionEvent evt)
Azioni da effettuare alla pressione del bottone client: controlla se c&#39;e&#39; gia&#39; un client attivo...
Definition: MainFrame.java:244
void formWindowClosing(java.awt.event.WindowEvent evt)
Azione da effettuare se alla chiusura della finestra.
Definition: MainFrame.java:172