domingo, 24 de febrero de 2013

JtoggleButton Programador Java Interfaz Gráfico GUI AWT Swing 1 Swing 2

Java
JtoggleButton Programador Java Interfaz Gráfico GUI AWT Swing 1 Swing 2


 java.awt.*;
 java.awt.event.*;
 javax.swing.*;
javax.swing.event.*;


public class jToggle extends JFrame {

  private JLabel jLabel1 = new JLabel();
  private JLabel jLabel2 = new JLabel();
  private JLabel jLabel3 = new JLabel();
  private JLabel jLabel4 = new JLabel();
  private JLabel jLabel5 = new JLabel();
  private JLabel jLabel6 = new JLabel();
  private JTextField jTextField1 = new JTextField();
  private JToggleButton jToggleButton1 = new JToggleButton();
  private JToggleButton jToggleButton2 = new JToggleButton();
  private JToggleButton jToggleButton3 = new JToggleButton();
  private JButton jButton1 = new JButton();

  public jToggle(String title) {
 
    super(title);
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    int frameWidth = 412;
    int frameHeight = 335;
    setSize(frameWidth, frameHeight);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (d.width - getSize().width) / 2;
    int y = (d.height - getSize().height) / 2;
    setLocation(x, y);
    setResizable(false);
    Container cp = getContentPane();
    cp.setLayout(null);
 
    jLabel1.setBounds(360, 120, 59, 25);
    jLabel1.setText("50");
    cp.add(jLabel1);
    jLabel2.setBounds(360, 160, 51, 25);
    jLabel2.setText("20");
    cp.add(jLabel2);
    jLabel3.setBounds(360, 200, 59, 25);
    jLabel3.setText("20");
    cp.add(jLabel3);
    jLabel4.setBounds(224, 256, 123, 33);
    jLabel4.setText("");
    cp.add(jLabel4);
    jLabel5.setBounds(72, 16, 251, 49);
    jLabel5.setText("JToggleButton");
    jLabel5.setFont(new Font("Gunplay 3D", Font.BOLD, 36));
    jLabel5.setForeground(Color.BLUE);
    cp.add(jLabel5);
    jLabel6.setBounds(40, 96, 139, 33);
    jLabel6.setText("Precio del Servicio");
    cp.add(jLabel6);
    jTextField1.setBounds(32, 136, 129, 25);
    cp.add(jTextField1);
    cp.setBackground(new Color(0x49B68A));
    jToggleButton1.setBounds(216, 112, 129, 33);
    jToggleButton1.setText("Cargar Gasolina");
    jToggleButton1.setMargin(new Insets(2, 2, 2, 2));
    jToggleButton1.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
        jToggleButton1_ActionPerformed(evt);
      }
    });
    cp.add(jToggleButton1);
    jToggleButton2.setBounds(216, 160, 129, 33);
    jToggleButton2.setText("Servicio mecánico");
    jToggleButton2.setMargin(new Insets(2, 2, 2, 2));
    jToggleButton2.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
        jToggleButton2_ActionPerformed(evt);
      }
    });
    cp.add(jToggleButton2);
    jToggleButton3.setBounds(216, 200, 129, 33);
    jToggleButton3.setText("Aceitear");
    jToggleButton3.setMargin(new Insets(2, 2, 2, 2));
    jToggleButton3.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
        jToggleButton3_ActionPerformed(evt);
      }
    });
    cp.add(jToggleButton3);
    jButton1.setBounds(32, 240, 145, 49);
    jButton1.setText("Calcular el Servicio");
    jButton1.setMargin(new Insets(2, 2, 2, 2));
    jButton1.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
        jButton1_ActionPerformed(evt);
      }
    });
    cp.add(jButton1);
 
   
    setVisible(true);
  }
 

  public void jToggleButton1_ActionPerformed(ActionEvent evt) {
 
  }
 
  public void jToggleButton2_ActionPerformed(ActionEvent evt) {
 
  }
 
  public void jToggleButton3_ActionPerformed(ActionEvent evt) {
   
  }
 
  public void jButton1_ActionPerformed(ActionEvent evt) {
    double precio_base;
    double precio_instal;
    double precio_for;
    double precio_ali;
   
 
   
    precio_base = Double.parseDouble(jTextField1.getText());
    precio_instal = Double.parseDouble(jLabel1.getText());
    precio_for = Double.parseDouble(jLabel2.getText());
    precio_ali = Double.parseDouble(jLabel3.getText());
   
   
    double precio_total;
   
    precio_total = precio_base;
   
    if (jToggleButton1.isSelected()) {
      precio_total = precio_total+precio_instal;
    }
   
    if (jToggleButton2.isSelected()) {
      precio_total = precio_total+precio_for;          
    }
   
    if (jToggleButton3.isSelected()) {
      precio_total = precio_total+precio_ali;
    }
   
   
   
    jLabel4.setText(precio_total+" $us");
   
  }

 
  public static void main(String[] args) {
    new jToggle("jToggle");
  }
 
}

No hay comentarios:

Publicar un comentario