minor improvements

This commit is contained in:
joxe 2009-04-25 10:21:51 +00:00
parent 19a30284e5
commit 889a2bb024

View file

@ -27,12 +27,14 @@ public class ViewRSSI extends JPanel {
public void paint(Graphics g) { public void paint(Graphics g) {
int h = getHeight(); int h = getHeight();
int w = getWidth(); int w = getWidth();
g.clearRect(0, 0, w, h);
double factor = (h - 20.0) / RSSI_MAX_VALUE; double factor = (h - 20.0) / RSSI_MAX_VALUE;
double sSpacing = (w - 15 ) / 80.0; double sSpacing = (w - 15 ) / 80.0;
int sWidth = (int) (sSpacing - 1); int sWidth = (int) (sSpacing - 1);
if (sWidth == 0) sWidth = 1; if (sWidth == 0) sWidth = 1;
g.setColor(Color.white);
g.fillRect(0, 0, w, h);
g.setColor(Color.gray); g.setColor(Color.gray);
double xpos = 10; double xpos = 10;
for (int i = 0, n = rssi.length; i < n; i++) { for (int i = 0, n = rssi.length; i < n; i++) {
@ -59,8 +61,8 @@ public class ViewRSSI extends JPanel {
String line = reader.readLine(); String line = reader.readLine();
if (line.startsWith("RSSI:")) { if (line.startsWith("RSSI:")) {
try { try {
String[] parts = line.split(" "); String[] parts = line.substring(5).split(" ");
for (int i = 1, n = parts.length; i < n; i++) { for (int i = 0, n = parts.length; i < n; i++) {
rssi[i] = 3 * Integer.parseInt(parts[i]); rssi[i] = 3 * Integer.parseInt(parts[i]);
if (rssi[i] > rssiMax[i]) rssiMax[i] = rssi[i]; if (rssi[i] > rssiMax[i]) rssiMax[i] = rssi[i];
else if (rssiMax[i] > 0) rssiMax[i]--; else if (rssiMax[i] > 0) rssiMax[i]--;
@ -80,6 +82,7 @@ public class ViewRSSI extends JPanel {
win.setBounds(10, 10, 300, 300); win.setBounds(10, 10, 300, 300);
win.getContentPane().add(panel = new ViewRSSI()); win.getContentPane().add(panel = new ViewRSSI());
win.setVisible(true); win.setVisible(true);
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel.handleInput(); panel.handleInput();
} }