-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMotorPanel.java
More file actions
110 lines (100 loc) · 3.03 KB
/
MotorPanel.java
File metadata and controls
110 lines (100 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.Scanner;
public class MotorPanel extends JPanel{
private JButton forward, backward, up, down; // locking buttons
private JLabel m1, m2, m3, m4, m5, m6; // motors and their percent efficiencies
Timer t;
public MotorPanel(){
// what is the specific API we will use to gather data from the joystick and arduino and output it to the api? //
//for now, one possibility is using a real time update for a file. In this case, all that must be done is that is that the arduino and the
// joystick inputs into one file, while the java program reads it
// i have demonstrated this method for the efficiencies for the of the motor
Scanner infile = null;
try{
infile = new Scanner(new File("e"));
}catch(FileNotFoundException e){
System.err.println("File not found!");
System.exit(0);
}
String[] e = new String[6];
for(int i = 0; i < e.length; i++){
e[i] = infile.next();
}
Font f = new Font("Calibri", Font.ITALIC, 12);
m1 = new JLabel(e[0]+"%");
m2 = new JLabel(e[1]+"%");
m3 = new JLabel(e[2]+"%");
m4 = new JLabel(e[3]+"%");
m5 = new JLabel(e[4]+"%");
m6 = new JLabel(e[5]+"%");
m1.setFont(f);
m2.setFont(f);
m3.setFont(f);
m4.setFont(f);
m5.setFont(f);
m6.setFont(f);
forward = new JButton("Lock Forward");
backward = new JButton("Lock Backward");
up = new JButton("Lock Up");
down = new JButton("Lock Down");
setLayout(new FlowLayout());
JPanel subpanel = new JPanel();
subpanel.setLayout(new GridLayout(2,1));
JPanel eff = new JPanel();
eff.setLayout(new GridLayout(2,6));
JPanel locks = new JPanel();
locks.setLayout(new GridLayout(1,4));
JLabel m = new JLabel("Motors: ");
m.setFont((new Font("Calibri", Font.BOLD, 18)));
m.setForeground(Color.RED);
add(m);
add(subpanel);
subpanel.add(eff);
subpanel.add(locks);
for(int i =1; i <= 6; i++){
eff.add(new JLabel("Motor "+i));
}
eff.add(m1);
eff.add(m2);
eff.add(m3);
eff.add(m4);
eff.add(m5);
eff.add(m6);
locks.add(forward);
locks.add(backward);
locks.add(up);
locks.add(down);
setForeground(Color.GRAY);
t = new Timer(3,new Listener());
t.start();
}
public class Listener implements ActionListener {
@Override
public void actionPerformed(ActionEvent arg0) {
Scanner update = null;
try{
update = new Scanner(new File("e"));
}catch(FileNotFoundException e){
System.err.println("File not found!");
System.exit(0);
}
String[] e = new String[6];
for(int i = 0; i < e.length; i++){
e[i] = update.next();
}
Font f = new Font("Calibri", Font.ITALIC, 12);
m1.setText(e[0]+"%");
m2.setText(e[1]+"%");
m3.setText(e[2]+"%");
m4.setText(e[3]+"%");
m5.setText(e[4]+"%");
m6.setText(e[5]+"%");
for(int z = 0; z < 6; z++){
if(e[z])
}
}
}
}