Triqui
package paqTriqui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JOptionPane;
/**
*
* @author Administrador
*/
public class jTriqui extends javax.swing.JFrame {
JButton[][] botones=new JButton[3][3];
String letra="x";
Integer x=0, y=0;
/**
* Creates new form jTriqui
*/
public jTriqui() {
initComponents();
for (int i=0; i<3; i++ ){
for (int j=0; j<3; j++ ) {
botones [i][j]=new JButton("");
botones [i][j].setBounds((60*i)+10,(60*j)+10,50,50);
this.add(botones[i][j]);
botones[i][j].setVisible(true);
botones[i][j].addActionListener(es);
}
}
}
ActionListener es=new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
for(int i=0; i<3; i++) {
for(int j=0; j<3; j++) {
if (botones[i][j].getText().equals("")){
if(botones[i][j].equals(e.getSource())) {
botones[i][j].setText(letra);
x=i;
y=j;
}
}
}
}
if(letra.equals("x")){
letra="o";
}
else {
letra="x";
}
if((botones[x][y].getText().equals(botones[x+1][y+1].getText()))&&
(botones[x][y].getText().equals(botones[x+2][y+2].getText()))) {
JOptionPane.showConfirmDialog(null,"triqui");
}
}
};
miércoles, 28 de noviembre de 2012
Trabajo
package newpackage;
import javax.swing.JLabel;
/**
*
* @author w7
*/
public class NewJFrame extends javax.swing.JFrame {
private final int[][] numeros;
private int j;
private int i;
private int[][] numero;
/**
* Creates new form NewJFrame
*/
public NewJFrame() {
initComponents();
JLabel[][] campos=new JLabel[4][4];
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
campos[i][j]=new JLabel("");
campos[i][j].setBounds((80*i)+10,(40*j)+10,80,40);
this.add(campos[i][j]);
campos[i][j].setVisible(true);
}
}
Integer C=1;
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
if(i==0||i==2)
numeros[i][j]=1;
}
else{
numero[i][j]=0;
}
private void initComponents() {
}
}}
}
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
campos[i][j].setText(numeros[i][j].toString());
}}
}
Arreglo
public class Main {
/**
* @param args the command line arguments
*/
public static void funcion9 (){
Integer[] numeros=new Integer[10];
try {
numeros[0] = System.in.read();
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println( numeros[0]);
}
public static void funcion2 (){
Integer[] numeros=new Integer[10];
try {
numeros[0]=0;
for(int i=0; i<10; i++){
if(i>0){
numeros[i] = System.in.read();
}
if(numeros[i]==10){
i--;
}
else{
System.out.println("Ingrese el numero " +i);
}
}
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
Integer mayor=0;
for(int i=0; i<10; i++){
if(mayor<numeros[i]){
mayor=numeros[i];
}
}
System.out.println(mayor-48);
}
public static void main(String[] args) {
funcion9();
// TODO code application logic here
}
}
Matrices 1
package paqMatrices;
import javax.swing.JButton;
import javax.swing.JLabel;
/**
*
* @author COREDUCACION
*/
public class jMatrices extends javax.swing.JFrame {
/** Creates new form jMatrices */
public jMatrices() {
initComponents();
JLabel etiqueta1=new JLabel("Etiqueta 1");
etiqueta1.setBounds(20,50,100,200);
this.add(etiqueta1);
etiqueta1.setVisible(true);
JButton Button1=new JButton("Button 1");
Button1.setBounds(100,100,99,80);
this.add(Button1);
etiqueta1.setVisible(true);
}
/** 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">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new jMatrices().setVisible(true);
}
});
}
// Variables declaration - do not modify
// End of variables declaration
}
Matrices 2
package paqMatrices2;
import javax.swing.JLabel;
import javax.swing.JTextField;
/**
*
* @author MOISES
*/
public class jMatrices2 extends javax.swing.JFrame {
/** Creates new form jMatrices2 */
public jMatrices2() {
initComponents();
JLabel[][] Campos=new JLabel[4][4];
for(int i=0; i<4; i++){
for(int j=0; j<4; j++){
Campos[i][j]=new JLabel("1");
Campos[i][j].setBounds((80*i)+10,(40*j)+10,80,40);
this.add(Campos[i][j]);
Campos[i][j].setVisible(true);
}
}
Integer [][] numeros=new Integer[4][4];
Integer c=1;
for(int i=0; i<4; i++){
for(int j=0; j<4; j++){
if(i==0||i==2)
numeros[i][j]=1;
else{
numeros[i][j]=0;
}
}
}
for(int i=0; i<4; i++){
for(int j=0; j<4; j++){
Campos[i][j].setText(numeros[i][j].toString());
}
}
}
/** 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">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new jMatrices2().setVisible(true);
}
});
}
// Variables declaration - do not modify
// End of variables declaration
}
Menos -5 hasta el 5 positivo
Arreglo1[9]=Arreglo1[8]+Arreglo1[7];
System.out.println(Arreglo1[10]);
for(int i=0; i<11;i++)
{
Arreglo1[i]=i-5;
}
for(int i=0;i<10;i++)
{
System.out.println(Arreglo1[i]);
}
}
Impares
Arreglo1[9]=Arreglo1[8]+Arreglo1[7];
System.out.println(Arreglo1[9]);
for(int i=1; i<10;i++)
{
Arreglo1[i]=(i*2)-1;
}
for(int i=0;i<10;i++)
{
System.out.println(Arreglo1[i]);
}
}
public class ProArreglos2 {
static Integer[] Arreglo1 = new Integer[5];
public static void Funcion1 (){
Arreglo1[0]= 1;
Arreglo1[1]= 2;
Arreglo1[2]= 3;
Arreglo1[3]= 4;
Arreglo1[4]= 5;
Arreglo1[5]= 6;
Arreglo1[6]= 7;
Arreglo1[7]= 8;
Arreglo1[8]= 9;
Arreglo1[9]= 10;
System.out.println(Arreglo1[0]);
System.out.println(Arreglo1[1]);
System.out.println(Arreglo1[2]);
System.out.println(Arreglo1[3]);
System.out.println(Arreglo1[4]);
System.out.println(Arreglo1[5]);
System.out.println(Arreglo1[6]);
System.out.println(Arreglo1[7]);
System.out.println(Arreglo1[8]);
System.out.println(Arreglo1[9]);
Arreglo1[9]=Arreglo1[8]+Arreglo1[7];
System.out.println(Arreglo1[9]);
for(int i=0; i<10;i++)
{
Arreglo1[i]=i-5;
}
for(int i=0;i<10;i++)
{
System.out.println(Arreglo1[i]);
}
}
public static void main(String[] args) {
Funcion1();
// TODO code application logic here
viernes, 9 de noviembre de 2012
Pedro Responde
public class jpedro extends javax.swing.JFrame {
String frase="Pedro por favor responde";
String respuesta="";
Integer contador=0;
boolean bandera=false;
private void jTextField1KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField1KeyTyped
if (evt.getKeyChar()=='-'){
bandera=true;
}
if(bandera==false){
respuesta=respuesta+evt.getKeyChar();
}
if(contador<frase.length()){
evt.setKeyChar(frase.charAt(contador));
contador ++;
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
JOptionPane.showMessageDialog(null,respuesta);
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
respuesta="";
contador=0;
bandera=false;
jTextField1.setText("");
jTextField2.setText("");
public class jpedro extends javax.swing.JFrame {
String frase="Pedro por favor responde";
String respuesta="";
Integer contador=0;
boolean bandera=false;
private void jTextField1KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField1KeyTyped
if (evt.getKeyChar()=='-'){
bandera=true;
}
if(bandera==false){
respuesta=respuesta+evt.getKeyChar();
}
if(contador<frase.length()){
evt.setKeyChar(frase.charAt(contador));
contador ++;
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
JOptionPane.showMessageDialog(null,respuesta);
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
respuesta="";
contador=0;
bandera=false;
jTextField1.setText("");
jTextField2.setText("");
Suscribirse a:
Comentarios (Atom)