Escolar Documentos
Profissional Documentos
Cultura Documentos
}
});
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(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>
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);
//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;
}
}