Você está na página 1de 10

/*

* To change this template, choose Tools | Templates


* and open the template in the editor.
*/
package conversiones;
import javax.swing.JOptionPane;
/**
*
* @author vivivaie
*/
public class piel extends javax.swing.JFrame {
/**
* Creates new form piel
*/
public piel() {
initComponents();
this.setLocationRelativeTo(null);
}
/**
* 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() {
jTF = new javax.swing.JTextField();
JEtqs = new javax.swing.JComboBox();
jLabel1 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("ConNum 0.2");
setBackground(new java.awt.Color(70, 110, 170));
setBounds(new java.awt.Rectangle(0, 0, 0, 0));
setForeground(new java.awt.Color(204, 204, 255));
jTF.setFont(new java.awt.Font("Candara", 0, 12)); // NOI18N
jTF.setHorizontalAlignment(javax.swing.JTextField.CENTER);
jTF.setText("12");
jTF.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jTFMouseClicked(evt);
}
});
jTF.addInputMethodListener(new java.awt.event.InputMethodListener() {
public void caretPositionChanged(java.awt.event.InputMethodEvent evt
) {
}
public void inputMethodTextChanged(java.awt.event.InputMethodEvent e
vt) {
jTFInputMethodTextChanged(evt);

}
});
jTF.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
jTFKeyReleased(evt);
}
public void keyTyped(java.awt.event.KeyEvent evt) {
jTFKeyTyped(evt);
}
});
JEtqs.setMaximumRowCount(13);
JEtqs.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Sele
ccionar", "- Bin-Oct", "- Bin-Dec", "- Bin-Hex", "- Oct-Bin", "- Oct-Dec", "- Oc
t-Hex", "- Dec-Bin", "- Dec-Oct", "- Dec-Hex", "- Hex-Bin", "- Hex-Oct", "- HexDec" }));
JEtqs.setAutoscrolls(true);
JEtqs.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
JEtqsActionPerformed(evt);
}
});
jLabel1.setFont(new java.awt.Font("Segoe Print", 0, 11)); // NOI18N
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setText("-:-");
jButton1.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
jButton1.setText("Limpiar");
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton1MouseClicked(evt);
}
});
jButton2.setFont(new java.awt.Font("Tahoma", 1, 10)); // NOI18N
jButton2.setText("?");
jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton2MouseClicked(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentP
ane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(JEtqs, javax.swing.GroupLayout.PREFERRED_S
IZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZ
E)
.addGap(18, 18, 18)
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacem

ent.UNRELATED)
.addComponent(jButton2)
.addGap(0, 8, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout
.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLa
yout.Alignment.TRAILING)
.addComponent(jLabel1, javax.swing.GroupLayout.Align
ment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFA
ULT_SIZE, Short.MAX_VALUE)
.addComponent(jTF))
.addContainerGap())))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.BASELINE)
.addComponent(JEtqs, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1)
.addComponent(jButton2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRE
LATED)
.addComponent(jTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax
.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED, 12, Short.MAX_VALUE)
.addComponent(jLabel1)
.addContainerGap())
);
pack();
}// </editor-fold>
String op="";int op1=0,nbo=0,nbd=0;
boolean click=false;
private void jTFMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
if (click==false){
jTF.setText(null);
}
click=true;
}
private void jTFKeyTyped(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
char car = evt.getKeyChar();
if(op1==0){
evt.consume();
}
if(op1>=1&&op1<=3){
if(car!='0' && car!='1') evt.consume();
}
if(op1>=4&&op1<=6){

if((car<'0' || car>'7')) evt.consume();


}
if(op1>=7&&op1<=9){
if((car<'0' || car>'9')) evt.consume();
}
if(op1>=10&&op1<=12){
if((car<'0' || car>'9') && ((car<'a' || car>'f') && (car<'A' || car>
'F'))) evt.consume();
}
}
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
jTF.setText(null);
jLabel1.setText("-:-");
}
private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
JOptionPane.showMessageDialog(null,
"- Presione en 'Seleccionar' para escoger la conversin \n"
+ "- El boton 'Limpiar' le sirve para borrar todo el nmero que ha e
scrito\n"
+ "- Al escribir automticamente se convierte, tambien al cambiar la
seleccion,\n"
+ " mientras no sea retroceder de un nmero Hex excrito (por ejempl
o 'A' se borra) a uno infeior");
}
private void jTFInputMethodTextChanged(java.awt.event.InputMethodEvent evt)
{
// TODO add your handling code here:
}
private void JEtqsActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
op=(JEtqs.getSelectedItem().toString());
op1=JEtqs.getSelectedIndex();
if(op1>=1&&op1<=3){
nbo=2;
if(op1==1){nbd=8;}
else if(op1==2){nbd=10;}
else{nbd=16;}
}
if(op1>=4&&op1<=6){
nbo=8;
if(op1==4){nbd=2;}
else if(op1==5){nbd=10;}
else{nbd=16;}
}
if(op1>=7&&op1<=9){
nbo=10;
if(op1==7){nbd=2;}
else if(op1==8){nbd=8;}
else{nbd=16;}

}
if(op1>=10&&op1<=12){
nbo=16;
if(op1==10){nbd=2;}
else if(op1==11){nbd=8;}
else{nbd=10;}
}
try {
int nba=Integer.parseInt(jTF.getText(),nbo);
String nbb=Integer.toString(nba, nbd);
jLabel1.setText(nbb);
}
catch (Exception ex) {
jTF.setText("");
jLabel1.setText("-:-");
}
}
private void jTFKeyReleased(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
try {
jTF.setText(jTF.getText().toUpperCase());
int nba=Integer.parseInt(jTF.getText(),nbo);
String nbb=Integer.toString(nba, nbd);
jLabel1.setText(nbb);
}
catch (Exception ex) {
jTF.setText("");
jLabel1.setText("-:-");
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting cod
e (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the d
efault look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lo
okandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIMana
ger.getInstalledLookAndFeels()) {
if ("Windows".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException | InstantiationException | IllegalAccess
Exception | javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(piel.class.getName()).log(java.ut
il.logging.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */


java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new piel().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JComboBox JEtqs;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JTextField jTF;
// End of variables declaration
}
________________________________________________________________________________
________________________________________________________________________________
_______________
//operaciones
package operaciones;
import javax.swing.*;
import java.awt.event.*;
public class Formulario extends JFrame implements ActionListener{
private JTextField textfield1,textfield2, textfield3;
private JButton boton1,boton2,boton3,boton4;
public Formulario() {
setLayout(null);
textfield1=new JTextField();
textfield1.setBounds(10,10,100,30);
add(textfield1);
textfield2=new JTextField();
textfield2.setBounds(10,50,100,30);
add(textfield2);
textfield3=new JTextField();
textfield3.setBounds(10,90,100,30);
add(textfield3);
boton1=new JButton("Sumar");
boton1.setBounds(10,140,100,30);
add(boton1);
boton1.addActionListener(this);
boton2=new JButton("Restar");
boton2.setBounds(10,170,100,30);
add(boton2);
boton2.addActionListener(this);
boton3=new JButton("Multiplicar");
boton3.setBounds(10,200,100,30);
add(boton3);
boton3.addActionListener(this);
boton4=new JButton("Dividir");
boton4.setBounds(10,230,100,30);
add(boton4);
boton4.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {

int
int

int
int

int
int

int
int

if (e.getSource()==boton1) {
String cad1=textfield1.getText();
String cad2=textfield2.getText();
String cad3=textfield3.getText();
x1=Integer.parseInt(cad1);
x2=Integer.parseInt(cad2);
int suma=x1+x2;
String total=String.valueOf(suma);
textfield3.setText(total);
}
if(e.getSource()==boton2)
{
String cad1=textfield1.getText();
String cad2=textfield2.getText();
String cad3=textfield3.getText();
x1=Integer.parseInt(cad1);
x2=Integer.parseInt(cad2);
int resta=x1-x2;
String total=String.valueOf(resta);
textfield3.setText(total);
}
if(e.getSource()==boton3)
{
String cad1=textfield1.getText();
String cad2=textfield2.getText();
String cad3=textfield3.getText();
x1=Integer.parseInt(cad1);
x2=Integer.parseInt(cad2);
int multiplicar=x1*x2;
String total=String.valueOf(multiplicar);
textfield3.setText(total);
}
if(e.getSource()==boton4)
{
String cad1=textfield1.getText();
String cad2=textfield2.getText();
String cad3=textfield3.getText();
x1=Integer.parseInt(cad1);
x2=Integer.parseInt(cad2);
int dividir=x1/x2;
String total=String.valueOf(dividir);
textfield3.setText(total);
}
}
public static void main(String[] ar) {
Formulario formulario1=new Formulario();
formulario1.setBounds(0,0,130,320);
formulario1.setVisible(true);
}

}
________________________________________________________________________________
________
//imegenes
package radio;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class RadioButtonDemo extends JPanel {

static
static
static
static
static
static
JLabel

JFrame frame;
String birdString = "Bird";
String catString = "Cat";
String dogString = "Dog";
String rabbitString = "Rabbit";
String pigString = "Pig";
picture;

public RadioButtonDemo() {
JRadioButton birdButton = new JRadioButton(birdString);
birdButton.setMnemonic('b');
birdButton.setActionCommand(birdString);
birdButton.setSelected(true);
JRadioButton catButton = new JRadioButton(catString);
catButton.setMnemonic('c');
catButton.setActionCommand(catString);
JRadioButton dogButton = new JRadioButton(dogString);
dogButton.setMnemonic('d');
dogButton.setActionCommand(dogString);
JRadioButton rabbitButton = new JRadioButton(rabbitString);
rabbitButton.setMnemonic('r');
rabbitButton.setActionCommand(rabbitString);
JRadioButton pigButton = new JRadioButton(pigString);
pigButton.setMnemonic('p');
pigButton.setActionCommand(pigString);
//creamos un grupo y los anyadimos
ButtonGroup group = new ButtonGroup();
group.add(birdButton);
group.add(catButton);
group.add(dogButton);
group.add(rabbitButton);
group.add(pigButton);
//como en los ejemplos anteriores
RadioListener myListener = new RadioListener();

birdButton.addActionListener(myListener);
catButton.addActionListener(myListener);
dogButton.addActionListener(myListener);
rabbitButton.addActionListener(myListener);
pigButton.addActionListener(myListener);
// utilizamos un objeto Icon como argumento para el constructor
//de JLabel
//de inico mostraremos la imagen Bird.gif
picture = new JLabel(new ImageIcon("C:\\Documents and Settings/ITTAP-ALUMNO/Mis
documentos/Mis imgenes/" + birdString + ".JPEG"));
//establecemos la dimension
picture.setPreferredSize(new Dimension(177,122));
//establecemos un panel para la ordenacion de los componentes
JPanel radioPanel = new JPanel();
radioPanel.setLayout(new GridLayout(0, 1));
radioPanel.add(birdButton);
radioPanel.add(catButton);
radioPanel.add(dogButton);
radioPanel.add(rabbitButton);
radioPanel.add(pigButton);

//con BorderLayout podemos ordenar los componentes en cinco


//regiones: norte, sur ,este,oeste y centro
setLayout(new BorderLayout());
//el panel se cargara en el oeste y la imagen se mostrara en el
//centro
add(radioPanel, BorderLayout.WEST);
add(picture, BorderLayout.CENTER);
setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
}
//como en la creacion de los botones hicimos
________________________________________________________________________________
____________________________________

//birdButton.setActionCommand(birdString);
//en todos los botones de radio, ahora sabemos que
//imagen tenemos que mostrar con
//e.getActionCommand()
class RadioListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
picture.setIcon(new ImageIcon("C:\\Documents and Settings/ITTAP-ALUMNO/Mis docum
entos/Mis imgenes/" + e.getActionCommand()+ ".JPEG"));
}
}
public static void main(String s[]) {
frame = new JFrame("RadioButtonDemo");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e)
{System.exit(0);}
});
frame.getContentPane().add(new
RadioButtonDemo(), BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
}}
_______________________________________
package pack01;
import javax.swing.JOptionPane;
public class arreglouni
{
public static void main(String arg[])
{
int tam=Integer.parseInt(JOptionPane.showInputDialog("INGRESE EL NUMERO DE
ELEMENTOS"));
//int arr[]=new int[tam];
int a=llenado(tam);
JOptionPane.showMessageDialog(null, "EL VECTOR ES EL SIGUIENTE : "+a);
}
public static int llenado(int tama)
{
int acum=0;
int arr[]=new int[tama];
for(int i=0;i<tama;i++)
{

arr[i]=Integer.parseInt(JOptionPane.showInputDialog("INGRESE DATO"));
acum=acum+arr[i];
}
return acum;
}
}

Você também pode gostar