Datos
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class pregunta12 extends JApplet implements ActionListener {
//declaracion de variables globales
JButton btncalcular; //boton
JButton btnlimpiar; //boton
JTextArea txtS;
JLabel lblnumerotarjeta;
JLabel lblimportecompra;
JTextField txtnumerotarjeta;
JTextFieldtxtimportecompra;
JScrollPane scpScroll;
double importe_descuento,importe_compra,importe_pagar;
int numtarj;
public void init() {
getContentPane().setLayout(null);
lblnumerotarjeta= new JLabel("Nùmero de tarjeta");
lblnumerotarjeta.setBounds(15, 15, 420, 23);
getContentPane().add(lblnumerotarjeta);
txtnumerotarjeta = new JTextField();txtnumerotarjeta.setBounds(180, 15, 80, 23);
getContentPane().add(txtnumerotarjeta);
getContentPane().setLayout(null);
lblimportecompra= new JLabel("Importe de Compra");
lblimportecompra.setBounds(15, 45, 420, 23);
getContentPane().add(lblimportecompra);
txtimportecompra = new JTextField();
txtimportecompra.setBounds(180, 45,80, 23);
getContentPane().add(txtimportecompra);
getContentPane().setLayout(null);
btncalcular = new JButton("calcular");//crea el boton
btncalcular.setBounds(305, 20, 101, 23);//ubicacion y dimensiones(x,y,ancho, alto)
btncalcular.addActionListener(this);//para que funcione el boton
getContentPane().add(btncalcular); //coloca el boton en laaplicacion o ventana
btnlimpiar = new JButton("Limpiar");//crea el boton
btnlimpiar.setBounds(305, 50, 101, 23);//ubicacion y dimensiones(x,y,ancho, alto)
btnlimpiar.addActionListener(this);//para que funcione el boton
getContentPane().add(btnlimpiar); //coloca el boton en la aplicacion o ventana
txtS = new JTextArea();
txtS.setFont(newFont("monospaced", 0, 12));
scpScroll = new JScrollPane(txtS);
scpScroll.setBounds(15, 120, 300, 180);
getContentPane().add(scpScroll);
}
public void actionPerformed(ActionEvent e) {
numtarj = Integer.parseInt(txtnumerotarjeta.getText());
importe_compra=Double.parseDouble(txtimportecompra.getText());
if(numtarj%2==0 &&numtarj>=100){
importe_descuento=importe_compra*0.15;
}else{
importe_descuento=importe_compra*0.05;
}
importe_pagar=importe_compra-importe_descuento;
txtS.setText("Supermercado"+ "\n");
txtS.append("Importe Descuento :" + importe_descuento + "\n");
txtS.append("Importe Pagar :" + importe_pagar + "\n");
if (e.getSource() ==btnlimpiar) {
txtnumerotarjeta.setText("");
txtimportecompra.setText("");
txtnumerotarjeta.requestFocus();
}
}
}
Pregunta13
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class pregunta13 extends JApplet implements ActionListener {
//declaracion de variables globales
JButton btncalcular; //botonJButton btnlimpiar; //boton
JTextArea txtS;
JLabel lblcategoria;
JLabel lblmontototvendido;
JTextField txtmontototvendido;
JScrollPane scpScroll;
JComboBox cbocategoria;
double sueldo_basico, comision,sueldo_bruto,descuento,sueldo_neto,monto_tot_vendido;
public void init() {
getContentPane().setLayout(null);
lblcategoria= newJLabel("Categoria");
lblcategoria.setBounds(15, 15, 420, 23);
getContentPane().add(lblcategoria);
cbocategoria= new JComboBox();
cbocategoria.setBounds(105, 15, 120, 23);
cbocategoria.addItem("1");
cbocategoria.addItem("2");
cbocategoria.addItem("3");
getContentPane().add(cbocategoria);
lblmontototvendido= new JLabel("Monto...
Regístrate para leer el documento completo.