Muchas gracias por la respuesta WHK, me quedó claro como funciona esto de los arrays en PHP.
Saludos.
Saludos.
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menú
// el subindice se crea automaticamente ¿?
$array = array(
'elemento',
'otro elemento',
$elemento_tres,
$elemento_cuatro
)
$array = array(
'elemento' => $elemento,
'elemento2' => $elemento2
)
public void actionPerformed(ActionEvent evt)
{
String[] nombres_columnas={"","","","","","".....};
Object [][] data = {
{tuDato,tuDato,tuDato,tuDato},
{tuDato,tuDato,tuDato,tuDato},
{tuDato,tuDato,tuDato,tuDato},
{tuDato,tuDato,tuDato,tuDato},
};
ventana2 = new JTable(data,nombres_columnas);
ventana2.setPreferredScrollableViewportSize(new Dimension (700,250));
ventana2.setFillsViewportHeight(true);
JScrollPane scrollPane=new JScrollPane(ventana2);
add(scrollPane);
} // fin actionPerformed
tuDato = el dato que deseas pasar. Recuerda que si es entero, se pasa de la siguiente manera:
new Integer(tuDatoEntero)
double:
new Double(tuDatoReal)
boolean:
new Boolean(tuDatoLogico)
String:
tuDato
public class TablaVentas extends JFrame {
public TablaVentas(Object[][] data, String[] columnas) {
super("Información de venta");
//Creacion de la tabla
final JTable table = new JTable(data, columnas);
table.setPreferredScrollableViewportSize(new Dimension(500, 80));
//Creamos un scrollpanel y se lo agregamos a la tabla
JScrollPane scrollpane = new JScrollPane(table);
//Agregamos el scrollpanel al contenedor
getContentPane().add(scrollpane, BorderLayout.CENTER);
} // fin constructor
} // fin clase
public void actionPerformed(ActionEvent evt)
{
String[] nombres_columnas={"","","","","","".....};
Object [][] data = {
{tuDato,tuDato,tuDato,tuDato},
{tuDato,tuDato,tuDato,tuDato},
{tuDato,tuDato,tuDato,tuDato},
{tuDato,tuDato,tuDato,tuDato},
// la informacion procesada se envia a la tabla
TablaVentas miTabla = new TablaVentas(datos,nombres_columnas);
miTabla.pack();
miTabla.setVisible(true);
} // fin metodo actionPerformed
hacer un for que recorra la lista 2
luego, dentro del for, colocamos una condicional:
Si se ha ingresado una respuesta {
Si lista[i] == respuestaCorrecta // o que compare con la otra lista
correctas++;
si no
incorrectas++:
}
si no omitidas++;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Color;
import java.text.DecimalFormat;
public class SistemaVentas extends JFrame
{
// componentes del Frame
// textos
JLabel textoProveedor, textoProducto, textoCantidad, textoPrecioU, textoSubTotal, textoDescuentoPOR, textoDescuentoDIN, textoImpuestoIVA, textoTotalPagar;
// campos de textos
JTextField campoTextoProveedor, campoTextoCantidad, campoTextoPrecioU, campoTextoSubTotal, campoTextoDescuentoPOR,
campoTextoDescuentoDIN, campoTextoIVA, campoTextoTotalPagar;
// menu combobox
JComboBox stockProductos;
// botones
JButton botonProcesar, botonBuscar, botonBorrar, botonModificar, botonPrimero, botonAnterior,
botonSiguiente, botonUltimo, botonSalir;
// variables nativas
String nombresProductos[] = {"Portátil Veltron","MacBook Pro","Led Full HD","Tablet Sony"};
DecimalFormat formatear = new DecimalFormat("0.00");
public SistemaVentas()
{
super("Programa de compras - Por Mitsu");
setLayout(null);
// cabecera superior
textoProveedor = new JLabel("Proveedor");
textoProveedor.setBounds(35,40,70,20);
add(textoProveedor);
campoTextoProveedor = new JTextField("",20);
campoTextoProveedor.setBounds(100,35,110,30);
add(campoTextoProveedor);
// Elementos de la cabecera
textoProducto = new JLabel("Producto");
textoProducto.setBounds(85,75,60,40);
add(textoProducto);
stockProductos = new JComboBox(nombresProductos);
stockProductos.setBounds(32,115,160,30);
add(stockProductos);
textoCantidad = new JLabel("Cantidad");
textoCantidad.setBounds(305,75,60,40);
add(textoCantidad);
campoTextoCantidad = new JTextField("",20);
campoTextoCantidad.setBounds(280,115,110,30);
add(campoTextoCantidad);
textoPrecioU = new JLabel("Precio Unitario");
textoPrecioU.setBounds(448,75,85,40);
add(textoPrecioU);
campoTextoPrecioU = new JTextField("",20);
campoTextoPrecioU.setBounds(430,116,110,30);
add(campoTextoPrecioU);
// cuerpo
textoSubTotal = new JLabel("Subtotal");
textoSubTotal.setBounds(305,185,60,40);
add(textoSubTotal);
campoTextoSubTotal = new JTextField("",20);
campoTextoSubTotal.setBounds(430,190,110,30);
add(campoTextoSubTotal);
textoDescuentoPOR = new JLabel("Descuento %");
textoDescuentoPOR.setBounds(305,225,80,40);
add(textoDescuentoPOR);
campoTextoDescuentoPOR = new JTextField("",20);
campoTextoDescuentoPOR.setBounds(430,230,110,30);
add(campoTextoDescuentoPOR);
textoDescuentoDIN = new JLabel("Descuento $");
textoDescuentoDIN.setBounds(305,265,80,40);
add(textoDescuentoDIN);
campoTextoDescuentoDIN = new JTextField("",20);
campoTextoDescuentoDIN.setBounds(430,270,110,30);
add(campoTextoDescuentoDIN);
textoImpuestoIVA = new JLabel("IGV/IVA");
textoImpuestoIVA.setBounds(305,305,60,40);
add(textoImpuestoIVA);
campoTextoIVA = new JTextField("",20);
campoTextoIVA.setBounds(430,310,110,30);
add(campoTextoIVA);
textoTotalPagar = new JLabel("TOTAL");
textoTotalPagar.setBounds(305,345,60,40);
add(textoTotalPagar);
campoTextoTotalPagar = new JTextField("",20);
campoTextoTotalPagar.setBounds(430,350,110,30);
add(campoTextoTotalPagar);
// botones
botonProcesar = new JButton("Procesar");
botonProcesar.setBackground(new Color(48,88,143) );
botonProcesar.setBounds(20,440,90,32);
add(botonProcesar);
botonProcesar.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent evento)
{
if(evento.getSource() == botonProcesar)
{
Compras objeto = new Compras();
String cantidadx = campoTextoCantidad.getText();
double cantidad = Double.parseDouble(cantidadx);
String precio = campoTextoPrecioU.getText();
double precioU = Double.parseDouble(precio);
objeto.setCalculos(cantidad,precioU);
double subtotal = objeto.getSubTotal();
subtotal = Math.round(subtotal*Math.pow(10,2))/Math.pow(10,2);
int descuentopor = (int) objeto.getDescuentoPOR();
double descuentodin = objeto.getDescuentoDIN();
descuentodin = Math.round(descuentodin*Math.pow(10,2))/Math.pow(10,2);
double iva = objeto.getIVA();
iva = Math.round(iva*Math.pow(10,2))/Math.pow(10,2);
double total = objeto.getTotal();
total = Math.round(total*Math.pow(10,2))/Math.pow(10,2);
String subtotalx = String.valueOf(subtotal);
String descuentoporx = String.valueOf(descuentopor);
String descuentodinx = String.valueOf(descuentodin);
String ivax = String.valueOf(iva);
String totalx = String.valueOf(total);
campoTextoSubTotal.setText(subtotalx);
campoTextoDescuentoPOR.setText(descuentoporx);
campoTextoDescuentoDIN.setText(descuentodinx);
campoTextoIVA.setText(ivax);
campoTextoTotalPagar.setText(totalx);
}
} // fin metodo actionPerformed
} ); // fin clase interna anonima
botonBuscar = new JButton("Buscar");
botonBuscar.setBackground(new Color(48,88,143) );
botonBuscar.setBounds(120,440,90,32);
add(botonBuscar);
botonBorrar = new JButton("Borrar");
botonBorrar.setBackground(new Color(48,88,143) );
botonBorrar.setBounds(220,440,90,32);
add(botonBorrar);
botonModificar = new JButton("Modificar");
botonModificar.setBackground(new Color(48,88,143) );
botonModificar.setBounds(320,440,90,32);
add(botonModificar);
botonBorrar.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evento)
{
if(evento.getSource() == botonBorrar)
{
campoTextoProveedor.setText("");
campoTextoCantidad.setText("");
campoTextoPrecioU.setText("");
campoTextoSubTotal.setText("");
campoTextoDescuentoPOR.setText("");
campoTextoDescuentoDIN.setText("");
campoTextoIVA.setText("");
campoTextoTotalPagar.setText("");
}
} // fin metodo
} ); // fin clase interna anonima
// fila de abajo
botonPrimero = new JButton("Primero");
botonPrimero.setBackground(new Color(48,88,143) );
botonPrimero.setBounds(20,480,90,32);
add(botonPrimero);
botonAnterior = new JButton("Anterior");
botonAnterior.setBackground(new Color(48,88,143) );
botonAnterior.setBounds(120,480,90,32);
add(botonAnterior);
botonSiguiente = new JButton("Siguiente");
botonSiguiente.setBackground(new Color(48,88,143) );
botonSiguiente.setBounds(220,480,90,32);
add(botonSiguiente);
botonUltimo = new JButton("Ultimo");
botonUltimo.setBackground(new Color(48,88,143) );
botonUltimo.setBounds(320,480,90,32);
add(botonUltimo);
botonSalir = new JButton("Salir");
botonSalir.setBackground(new Color(255,75,0) );
botonSalir.setBounds(440,480,90,32);
add(botonSalir);
botonSalir.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evento)
{
if(evento.getSource() == botonSalir)
{
System.exit(0);
}
} // fin metodo
} // fin clase interna anonima
); // fin clase interna anonima 2
}
}
import java.text.DecimalFormat;
public class Compras
{
private double cantidad,precioUnitario,subTotal,xIVA,totalPagar,descuentoPOR,descuentoDIN;
public static final double IVA = 0.16;
DecimalFormat formatear = new DecimalFormat("0.00");
public Compras()
{
cantidad = 0;
precioUnitario = 0;
subTotal = 0;
xIVA = 0;
totalPagar = 0;
descuentoPOR = 0;
descuentoDIN = 0;
}
public void setCalculos(double cantidadx, double precioUnidad)
{
cantidad = cantidadx;
precioUnitario = precioUnidad;
double descuento;
if(cantidad>=0 && cantidad<=4){
descuento = 0; }
else if(cantidad>=5 && cantidad<=10){
descuento = 0.20; }
else if(cantidad>=11 && cantidad<=15){
descuento = 0.45; }
else descuento = 0.6;
double totalTemp = cantidad * precioUnitario;
xIVA = totalTemp * IVA;
descuentoDIN = totalTemp * descuento;
descuentoPOR = descuento * 10;
subTotal = totalTemp - descuento;
totalPagar = subTotal + xIVA;
} // fin metodo
public double getSubTotal()
{
return subTotal;
}
public double getDescuentoPOR()
{
return descuentoPOR;
}
public double getDescuentoDIN()
{
return descuentoDIN;
}
public double getIVA()
{
return xIVA;
}
public double getTotal()
{
return totalPagar;
}
}
import javax.swing.JFrame;
public class Principal
{
public static void main(String[] args)
{
SistemaVentas prueba = new SistemaVentas();
prueba.setSize(600,560);
prueba.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
prueba.setResizable(false);
prueba.setVisible(true);
}
} // fin