Post on 01-Feb-2016
Prg2-2015B-Prueba4nov2015-PogoFernando
package Prueba4noviembre2015;
import java.awt.BorderLayout;import java.awt.Color;import java.awt.Container;import java.awt.FlowLayout;import java.awt.GridLayout;
import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JTextArea;import javax.swing.JTextField;
import java.awt.*;import java.awt.event.*;
public class A_Prueba4noviembre2015 extends JFrame implements ActionListener {private Container cntPrincipal;private JLabel lblMatriz1, lblMatriz2;private JButton btnGenerarM, btnSalir;private JTextField txtValor1, txtValor2;
private JTextArea txtSalida = new JTextArea("");private JPanel panelDatos = new JPanel(new GridLayout(2,5));private JPanel panelSalida = new JPanel(new GridLayout());private JPanel panelBotones = new JPanel(new GridLayout());
String strMatriz1, strMatriz2, strError, acumular="";int arregloMatriz1[][], arregloMatriz2[][];int i,j;boolean indBien;
public A_Prueba4noviembre2015() {super( "Prueba" );setSize(400, 300);setLocationByPlatform(true);
cntPrincipal = getContentPane();
cntPrincipal.setLayout(new BorderLayout());
cntPrincipal.add(panelDatos, BorderLayout.NORTH);cntPrincipal.add(panelSalida, BorderLayout.CENTER);cntPrincipal.add(panelBotones, BorderLayout.SOUTH);
panelSalida.add(txtSalida);
lblMatriz1 = new JLabel("Primera Matriz");lblMatriz1.setToolTipText("Ingrese el orden (n) de la matriz n*n" );panelDatos.add(lblMatriz1);
txtValor1 = new JTextField( 3 );panelDatos.add(txtValor1);
lblMatriz2 = new JLabel("Segunda Matriz");lblMatriz2.setToolTipText("Ingrese el orden (n) de la matriz n*n" );panelDatos.add(lblMatriz2);
txtValor2 = new JTextField( 3 );panelDatos.add(txtValor2);
btnGenerarM= new JButton();btnGenerarM.setText("Generar Matrices");panelBotones.add(btnGenerarM);btnGenerarM.setActionCommand("generar");btnGenerarM.addActionListener(this);
btnSalir= new JButton();btnSalir.setText("Salir");panelBotones.add(btnSalir);btnSalir.setActionCommand("salir");btnSalir.addActionListener(this);
setVisible(true);}
public void Validar(){indBien=true;boolean indVer=true;if(strMatriz1.length()!=1 || strMatriz2.length()!=1){
strError+="||Solo puede ingresar un digito\n";indBien=false;indVer=false;
}if(indVer==true){
if(strMatriz1.codePointAt(0)!=53 || strMatriz1.codePointAt(0)!=55 || strMatriz1.codePointAt(0)!=57)
{strError+="||Solo puede ingresar numeros impares entre el 5 y
el nueve para la matriz 1\n";indBien=false;
}if(strMatriz2.codePointAt(0)!=53 || strMatriz2.codePointAt(0)!=55 ||
strMatriz2.codePointAt(0)!=57){
strError+="||Solo puede ingresar numeros impares entre el 5 y el nueve para la matriz 2\n";
indBien=false;}
}}
public void Generar(){if(indBien==true){
i=Integer.parseInt(strMatriz1);arregloMatriz1 = new int[i][i];j=Integer.parseInt(strMatriz2);arregloMatriz2 = new int[j][j];
}}
public void Crear(){
int m=0;for ( int k = 0; k < i; k++ ){
for(int l = 0; l < i; l++){
arregloMatriz1[k][l]=200-m;m=m+2;
}}m=0;for ( int k = 0; k < i; k++ ){
for(int l = 0; l < i-m; l++){
}for(int n=0; n<i-m;n++){
}for(int o=0;o<i-m;o++){
}m++;for(int p=0;p<i-m;p++){
}}
}
public void Imprimir(){acumular+="\n";String numero;
for ( int k = 0; k < i; k++ ){
for(int l = 0; l < i; l++){
numero=Integer.toString(arregloMatriz1[k][l]);acumular+=numero; acumular+=" ";
}acumular+="\n";
}int m=0;for ( int k = 0; k < i; k++ ){
for(int l = 0; l < i-m; l++){
}for(int n=0; n<i-m;n++){
}for(int o=0;o<i-m;o++){
}m++;for(int p=0;p<i-m;p++){
}}
}
public static void main(String[] args) {
A_Prueba4noviembre2015 ventana = new A_Prueba4noviembre2015();ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubacumular="";String a = e.getActionCommand();strMatriz1=txtValor1.getText();strMatriz2=txtValor2.getText();acumular+="Fernando Pogo Prueba 4 Noviembre 2015\n";if(a.equals("generar")){
Validar();Generar();Crear();Imprimir();
}txtSalida.append(acumular);if(a.equals("salir")){
System.exit(0);}
}}