Codigo Netbeans Led
Codigo Netbeans Led
JDialog {
int R=0;
PanamaHitek_Arduino arduino=new PanamaHitek_Arduino();
String OutputR;
if (R < 10) {
OutputR = OutputR + "00" + R;
} else if (R < 100) {
OutputR = OutputR + "0" + R;
} else {
OutputR = OutputR + R;
}
super(parent, modal);
initComponents();
this.setTitle ("Encender o Apagar Led");
this.setLocationRelativeTo(JDialogEncenderled.this);
this.setResizable(false);
Image led
=Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("img/led.png"))
;
this.setIconImage(led);
this.jSliderled.setEnabled(false);
((JPanel)getContentPane()).setOpaque(false);
ImageIcon uno=new
ImageIcon(this.getClass().getResource("/img/startt.png"));
JLabel fondo= new JLabel();
fondo.setIcon(uno);
getLayeredPane().add(fondo,JLayeredPane.FRAME_CONTENT_LAYER);
fondo.setBounds(0,0,uno.getIconWidth(),uno.getIconHeight());
ImageIcon imagenled=new
ImageIcon(getClass().getResource("/img/led_off.png"));
Icon iconoled= new
ImageIcon(imagenled.getImage().getScaledInstance(labelfondo.getWidth(),labelfondo.g
etHeight(),Image.SCALE_DEFAULT));
labelfondo.setIcon(iconoled);
this.repaint();
try {
arduino.arduinoTX("COM3", 9600);
} catch (ArduinoException ex) {
Logger.getLogger(JDialogEncenderled.class.getName()).log(Level.SEVERE,
null, ex);
}
/**
* 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
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
pack();
}// </editor-fold>
if (Botonled.isSelected())
{ this.BotonRled.setEnabled(false);
this.BotonPled.setEnabled(false);
try {
Botonled.setText("Apagar Led");
ImageIcon imagenled=new
ImageIcon(getClass().getResource("/img/led_on.png"));
Icon iconoled= new
ImageIcon(imagenled.getImage().getScaledInstance(labelfondo.getWidth(),labelfondo.g
etHeight(),Image.SCALE_DEFAULT));
labelfondo.setIcon(iconoled);
this.repaint();
arduino.sendData("a");
} catch (ArduinoException | SerialPortException ex) {
if (BotonPled.isSelected())
{
this.Botonled.setEnabled(false);
this.BotonRled.setEnabled(false);
try {
BotonPled.setText("Detener");
ImageIcon imagenled=new
ImageIcon(getClass().getResource("/img/led_on.png"));
Icon iconoled= new
ImageIcon(imagenled.getImage().getScaledInstance(labelfondo.getWidth(),labelfondo.g
etHeight(),Image.SCALE_DEFAULT));
labelfondo.setIcon(iconoled);
this.repaint();
arduino.sendData("b");
} catch (ArduinoException | SerialPortException ex) {
}
}
private void BotonRledActionPerformed(java.awt.event.ActionEvent evt) {
if (BotonRled.isSelected())
{
this.jSliderled.setEnabled(true);
this.Botonled.setEnabled(false);
this.BotonPled.setEnabled(false);
this.jmostrar.setVisible(true);
try {
BotonRled.setText("Detener");
ImageIcon imagenled=new
ImageIcon(getClass().getResource("/img/led_on.png"));
Icon iconoled= new
ImageIcon(imagenled.getImage().getScaledInstance(labelfondo.getWidth(),labelfondo.g
etHeight(),Image.SCALE_DEFAULT));
labelfondo.setIcon(iconoled);
this.repaint();
arduino.sendData("c");
}
}
jmostrar.setText("Nivel es "+jSliderled.getValue());
Led();
SetData();
try {
arduino.sendData(OutputR);
} catch (ArduinoException | SerialPortException ex) {
Logger.getLogger(JDialogEncenderled.class.getName()).log(Level.SEVERE,
null, ex);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code
(optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the
default look and feel.
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(JDialogEncenderled.class.getName()).log(java.uti
l.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(JDialogEncenderled.class.getName()).log(java.uti
l.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(JDialogEncenderled.class.getName()).log(java.uti
l.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(JDialogEncenderled.class.getName()).log(java.uti
l.logging.Level.SEVERE, null, ex);
}
//</editor-fold>