Browse Source

finished the master gui

yigit
Yiğit Çolakoğlu 6 years ago
parent
commit
215ea2a923
3 changed files with 125 additions and 46 deletions
  1. +1
    -7
      traffic_analyzer/master_app/src/main/java/me/yigitcolakoglu/master_app/Main.java
  2. +19
    -11
      traffic_analyzer/master_app/src/main/java/me/yigitcolakoglu/master_app/cameraForm.form
  3. +105
    -28
      traffic_analyzer/master_app/src/main/java/me/yigitcolakoglu/master_app/cameraForm.java

+ 1
- 7
traffic_analyzer/master_app/src/main/java/me/yigitcolakoglu/master_app/Main.java View File

@ -18,13 +18,7 @@ public class Main {
// TODO code application logic here
cameraForm form = new cameraForm();
form.setVisible(true);
try{
while(true){
form.onCreate();
}
}catch(Exception e){
System.out.println(e.toString());
}
}
}

+ 19
- 11
traffic_analyzer/master_app/src/main/java/me/yigitcolakoglu/master_app/cameraForm.form View File

@ -48,9 +48,9 @@
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="33" max="-2" attributes="0"/>
<Component id="jButton1" min="-2" pref="247" max="-2" attributes="0"/>
<Component id="ambulance_button" min="-2" pref="247" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="217" max="-2" attributes="0"/>
<Component id="jButton2" min="-2" pref="248" max="-2" attributes="0"/>
<Component id="intersection_button" min="-2" pref="248" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace type="separate" max="-2" attributes="0"/>
@ -85,7 +85,7 @@
</Group>
</Group>
</Group>
<Component id="jButton3" alignment="0" min="-2" pref="251" max="-2" attributes="0"/>
<Component id="bus_button" alignment="0" min="-2" pref="251" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
@ -131,10 +131,12 @@
<Component id="camera_full_label" min="-2" pref="720" max="-2" attributes="0"/>
</Group>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jButton1" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jButton2" alignment="0" min="-2" pref="31" max="-2" attributes="0"/>
<Component id="jButton3" alignment="3" min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="intersection_button" alignment="0" min="-2" pref="31" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="ambulance_button" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="bus_button" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace pref="18" max="32767" attributes="0"/>
</Group>
@ -228,23 +230,29 @@
<Property name="text" type="java.lang.String" value="2500 RPM"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="jButton1">
<Component class="javax.swing.JButton" name="ambulance_button">
<Properties>
<Property name="text" type="java.lang.String" value="Ambulance"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="ambulance_buttonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="jButton2">
<Component class="javax.swing.JButton" name="intersection_button">
<Properties>
<Property name="text" type="java.lang.String" value="Intersection"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton2ActionPerformed"/>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="intersection_buttonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="jButton3">
<Component class="javax.swing.JButton" name="bus_button">
<Properties>
<Property name="text" type="java.lang.String" value="Bus"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="bus_buttonActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>

+ 105
- 28
traffic_analyzer/master_app/src/main/java/me/yigitcolakoglu/master_app/cameraForm.java View File

@ -29,7 +29,9 @@ public class cameraForm extends javax.swing.JFrame {
public cameraForm() {
initComponents();
}
private ServerSocket server;
private Socket client;
private Thread running = null;
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
@ -56,9 +58,9 @@ public class cameraForm extends javax.swing.JFrame {
ram_temp = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
fan_rpm = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
ambulance_button = new javax.swing.JButton();
intersection_button = new javax.swing.JButton();
bus_button = new javax.swing.JButton();
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
@ -107,16 +109,26 @@ public class cameraForm extends javax.swing.JFrame {
fan_rpm.setFont(new java.awt.Font("Dialog", 1, 24)); // NOI18N
fan_rpm.setText("2500 RPM");
jButton1.setText("Ambulance");
ambulance_button.setText("Ambulance");
ambulance_button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ambulance_buttonActionPerformed(evt);
}
});
jButton2.setText("Intersection");
jButton2.addActionListener(new java.awt.event.ActionListener() {
intersection_button.setText("Intersection");
intersection_button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
intersection_buttonActionPerformed(evt);
}
});
jButton3.setText("Bus");
bus_button.setText("Bus");
bus_button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bus_buttonActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
@ -129,9 +141,9 @@ public class cameraForm extends javax.swing.JFrame {
.addComponent(camera_full_label, javax.swing.GroupLayout.PREFERRED_SIZE, 900, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(33, 33, 33)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 247, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(ambulance_button, javax.swing.GroupLayout.PREFERRED_SIZE, 247, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(217, 217, 217)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(intersection_button, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(camera_cut_label, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
@ -158,7 +170,7 @@ public class cameraForm extends javax.swing.JFrame {
.addComponent(cpu_temp)
.addComponent(gpu_temp)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(bus_button, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
@ -194,19 +206,84 @@ public class cameraForm extends javax.swing.JFrame {
.addComponent(fan_rpm, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(camera_full_label, javax.swing.GroupLayout.PREFERRED_SIZE, 720, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton3))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(intersection_button, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(ambulance_button)
.addComponent(bus_button)))
.addContainerGap(18, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jButton2ActionPerformed
private void intersection_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_intersection_buttonActionPerformed
if(running!=null){
try{
server.close();
client.close();
running.stop();
}catch(IOException e){
System.out.println("IO Exception occured");
}catch(Exception e){
System.out.println(e.toString());
}
}
running = new Thread(() -> {
try{
onCreate(8486,"Intersection");
}catch(Exception e){
System.out.println(e.toString());
}
});
running.start();
}//GEN-LAST:event_intersection_buttonActionPerformed
private void ambulance_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ambulance_buttonActionPerformed
if(running!=null){
try{
server.close();
client.close();
running.stop();
}catch(IOException e){
System.out.println("IO Exception occured");
}catch(Exception e){
System.out.println(e.toString());
}
}
running = new Thread(() -> {
try{
onCreate(8485,"Ambulance");
}catch(Exception e){
System.out.println(e.toString());
}
});
running.start();
}//GEN-LAST:event_ambulance_buttonActionPerformed
private void bus_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bus_buttonActionPerformed
if(running!=null){
try{
server.close();
client.close();
running.stop();
}catch(IOException e){
System.out.println("IO Exception occured");
}catch(Exception e){
System.out.println(e.toString());
}
}
running = new Thread(() -> {
try{
onCreate(8487,"Bus");
}catch(Exception e){
System.out.println(e.toString());
}
});
running.start(); }//GEN-LAST:event_bus_buttonActionPerformed
/**
* @param args the command line arguments
@ -244,18 +321,18 @@ public class cameraForm extends javax.swing.JFrame {
}});
}
public void onCreate() throws Exception{
public void onCreate(int port, String name) throws Exception{
this.camera_cut_label.setIcon(new ImageIcon());
this.camera_full_label.setIcon(new ImageIcon());
String fromClient = "";
String toClient;
ServerSocket server = new ServerSocket(8485);
System.out.println("wait for connection on port 8080");
server = new ServerSocket(port);
System.out.println("wait for connection on port " + port);
boolean run = true;
Socket client = server.accept();
System.out.println("got connection on port 8080");
client = server.accept();
System.out.println("got connection on port " + port);
BufferedImage image = null;
byte[] imageByte;
int null_reps = 0;
@ -306,7 +383,7 @@ public class cameraForm extends javax.swing.JFrame {
}
server.close();
client.close();
JOptionPane.showMessageDialog(this, "Ambulance socket server down!");
JOptionPane.showMessageDialog(this, name +" socket server down!");
}
@ -324,6 +401,8 @@ public class cameraForm extends javax.swing.JFrame {
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton ambulance_button;
private javax.swing.JButton bus_button;
private javax.swing.JLabel camera_cut_label;
private javax.swing.JLabel camera_full_label;
private javax.swing.JLabel cpu_temp;
@ -331,9 +410,7 @@ public class cameraForm extends javax.swing.JFrame {
private javax.swing.JLabel fan_rpm;
private javax.swing.JLabel gpu_temp;
private javax.swing.JLabel gpu_usage;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton intersection_button;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;


Loading…
Cancel
Save