Voltometro

 

 

Appartieno alla serie dei manometri che sto realizzando per utilizzarli con Arduino. Questo è stato il primo ed è un test dell'impiego delle mie slide personalizzate.

 

classe: VoltMetro

 1 package voltmetro;
 2 
 3 import imgctrl.*;
 4 import java.awt.Color;
 5 import java.awt.Dimension;
 6 import java.awt.Font;
 7 import javax.swing.JFrame;
 8 
 9 public class VoltMetro extends JFrame {
10 
11     private Volt01 v01;
12     private Slider sdr;
13     private Dimension icd;
14     private String vrea;
15     private double rea;
16       
17     public VoltMetro() {        
18         setTitle("MyVoltmetro");
19         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        
20         getContentPane().setBackground(Color.white);        
21         setLayout(null);
22         setSize(600, 600);
23         setLocationRelativeTo(null);
24         
25         v01=new Volt01();
26         v01.setBounds(100, 30, 400, 400);
27         add(v01);
28         sdr=new Slider("/image/bayer-pom30.png",
29                 "/image/bayer-grey30-dx.png",
30                 "/image/bayer-braun30-sx.png");
31         icd=sdr.getIcoSize();
32         sdr.setMaxDim(500);       
33         sdr.setOrienta(0);
34         sdr.setVal(0,5,2);
35         sdr.setEtic(new Font("Arial",1,24));
36         sdr.setTickParam(null, 5, 1);
37         sdr.setLocation(20, 440);
38         sdr.jd.addDragListener(new MyDragListener() {
39             @Override
40             public void valChanged(DragEvent ev) {                               
41                 vrea=ev.getRea();                
42                 rea= Double.parseDouble(vrea);               
43                 v01.setRot(rea);
44             }                                
45         });       
46         add(sdr);
47         
48         setVisible(true);     
49     }
50 
51     public static void main(String args[]) {
52         /* Create and display the form */
53         java.awt.EventQueue.invokeLater(new Runnable() {
54             public void run() {
55                 new VoltMetro();
56             }
57         });
58     }    
59 }