jueves, 15 de noviembre de 2007

cosas

//all
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class frma extends JFrame {
//JFrame f;
JTextField tf;
Choice cho;
CheckboxGroup chb;
JButton l;
JComboBox cb;

public frma (){
//f= new JFrame("r");
tf=new JTextField(5);
cho=new Choice();
chb=new CheckboxGroup();
l=new JButton("ok");
cb=new JComboBox();

cb.addItem( "abc" );
cb.addItem( "def" );
Container f = getContentPane();

f.add( new

Checkbox("Primero",chb,true),BorderLayout.WEST);
f.add( new Checkbox("segundo",chb,

false),BorderLayout.SOUTH);


JPanel p1=new JPanel();
JPanel p2=new JPanel();
f.add(p1,BorderLayout.NORTH);
f.add(p2,BorderLayout.CENTER);
p1.add(tf);
p1.add(cho);
p2.add(l);
p2.add(cb);
setSize(250,250);
setVisible(true);

Manejador h =new Manejador();
l.addActionListener(h);


}
public class Manejador implements ActionListener{
public void actionPerformed(ActionEvent e){
if(e.getSource()==l)


tf.setText(cb.getSelectedItem().toString());
}
}
public static void main (String args[]){
frma a=new frma();
a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public boolean handleEvent( Event evt ) {
switch( evt.id ) {
case Event.WINDOW_DESTROY:
{
System.exit( 0 );
return true;
}
default:
return false;
}
}


}




//menu
public class ant extends JFrame{
MenuBar menub;
JFrame f;

public ant(){
f=new JFrame("a");
menub= new MenuBar();
Menu m= new Menu("Archivo");
Menu e= new Menu("Edicion");
m.add(new MenuItem("Nuevo"));
m.add(new MenuItem("Salir"));
menub.add(m);
menub.add(e);
f.setMenuBar( menub );

Container c= getContentPane();
f.setSize(200,200);
f.setVisible(true);



case Event.ACTION_EVENT:
{
if( evt.target instanceof MenuItem )
{
if( "Nuevo".equals( evt.arg ) )
frma f2 = new frma();
if( "Salir".equals( evt.arg ) )
System.exit( 0 );
if( "Edicion".equals( evt.arg ) )
System.out.println( "No hay ayuda" );
if( "Acerca de".equals( evt.arg ) )
System.out.println( "Opcion -Acerca de-" );
}
}


}
/*public static void main (String args[]){
ant a=new ant();
a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public boolean handleEvent( Event evt ) {
switch( evt.id ) {
case Event.WINDOW_DESTROY:
{
System.exit( 0 );
return true;
}
default:
return false;
}
}*/

}


//arch
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.*;
import java.util.*;

import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JTextField;

public class Matricula extends JFrame
{
JComboBox combo;
JTextField campo;
Vector matriculas= new Vector();
public Matricula(){
Container co = getContentPane();
co.setLayout(new FlowLayout());
combo = new JComboBox();
campo = new JTextField("",25);
int posicion = 0;
try
{
FileReader fr = new FileReader("alumnos.txt");
BufferedReader entrada = new BufferedReader(fr);
String s;
while ((s = entrada.readLine())!= null)
{
String[] alumno = s.split("\\s");
combo.insertItemAt(alumno[0], posicion);
matriculas.add(posicion, alumno[1]);
posicion++;
}
entrada.close();
}catch (java.io.FileNotFoundException e){
System.out.println("Archivo no se

encuentra");
}catch(java.io.IOException ex){
System.out.println("Error de E/S");
}

combo.addItemListener(new ComboListener());

co.add(combo);
co.add(campo);

setVisible(true);
setSize(400,400);

}
public class ComboListener implements ItemListener {

@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED)


campo.setText(matriculas.elementAt(combo.getSelectedIndex()));
}

}
public static void main (String [] args)
{
Matricula m = new Matricula();

}
}


//other
import java.io.*;
import java.util.*;

public class testArchivo
{
public static void main (String [] args)
{
String texto = "";
try
{
double d = 0.0;
FileReader fr = new FileReader("in.txt");
BufferedReader entrada = new BufferedReader(fr);
FileWriter fw = new FileWriter("nuevo.txt");
BufferedWriter salida = new BufferedWriter(fw);
String s;
while ((s = entrada.readLine())!= null)
{
texto = s;
StringTokenizer st = new

StringTokenizer(texto);
while (st.hasMoreTokens())
{
d =

Double.parseDouble(st.nextToken().toString())+100;/*lo paso de string a

double y le sumo 100*/
salida.write(String.format("%s",

d));
salida.newLine();
}
}
entrada.close();
salida.close();//del try
}
catch (java.io.FileNotFoundException e)
{
System.out.println("Archivo no se

encuentra");
}
catch(java.io.IOException ex)
{
System.out.println("Error de E/S");
}

}
}





//vs
//Controles
//JLabel
//JTextArea
//JTextField
//JPasswordField
//JButton
//Choice --- Selector.addItem( "Rojo" );
//CheckboxGroup
//JCheckbox --- JCheckbox( "Primero",Radio,true)
//JList ---- l.addItem( "Mercurio" )
//JComboBox ---cb.additem("ddd");

//JScrollbar( Scrollbar.VERTICAL,0,1,0,255 );
//MEnu --mbarra = new JMenuBar();
// Menu m = new Menu( "Archivo" );
// m.add( new MenuItem( "Nuevo") );
// m.addSeparator();
// mbarra.add( m );
// setMenuBar( mbarra );


//Contenedores
//Container--- getContentPane();
//JFrame
//JDialog
//JPanel
//JTabbedPane -- tp.addTab("Ficha1", null, panel1);

//setLayout
//GridLayout(2,2,1,10)
//FlowLayout(FlowLayout.RIGHT,1,2)
//f.add(j1,BorderLayout.NORTH);
//setLayout( new BorderLayout() );


//metodos - eventos
//Manejador h = new Manejador();
//btnOk.addActionListener(h);
//private class Manejador implements ActionListener {
// public void actionPerformed(ActionEvent e){
// if (e.getSource() == btnOk)


//otros
//setFont( new Font( "TimesRoman",Font.PLAIN,12 ) );
//setBackground( Color.white );
//setForeground( Color.black );
//setColor( Color.blue );
//drawString( getTitle(),30,50 );

//Main
//public static void main(String[] args) {
// Login log = new Login();
// log.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);



//cerrar
//public boolean handleEvent( Event evt ) {
// switch( evt.id ) {
// case Event.WINDOW_DESTROY:
// {
// System.exit( 0 );
// return true;
// }
// default:
// return false;
// }
// }


//app
import java.awt.Color;
import java.awt.BorderLayout;
import java.awt.event.*;
import javax.swing.*;
import java.applet.Applet;

public class ApptoAppl extends Applet
implements ActionListener {

JLabel text;
JButton button;
JPanel panel;
private boolean _clickMeMode = true;

public void init(){
setLayout(new BorderLayout(1, 2));
setBackground(Color.white);

text = new JLabel("I'm a Simple Program");
button = new JButton("Click Me");
button.addActionListener(this);
add("Center", text);
add("South", button);
}

public void start(){
System.out.println("Applet starting.");
}

public void stop(){
System.out.println("Applet stopping.");
}

public void destroy(){
System.out.println("Destroy method called.");
}

public void actionPerformed(ActionEvent event){
Object source = event.getSource();
if (_clickMeMode) {
text.setText("Button Clicked");
button.setText("Click Again");
_clickMeMode = false;
} else {
text.setText("I'm a Simple Program");
button.setText("Click Me");
_clickMeMode = true;
}
}
}

//canvas
import java.awt.*;
import java.applet.Applet;

public class Lienzo extends Applet {
Button boton;

public void init() {
setLayout( new BorderLayout( 15,15 ) );
boton = new Button( "Test" );
MiCanvas canv = new MiCanvas( 100,100 );

add( "Center",canv );
add( "South",boton );
}

public boolean action( Event evt,Object obj ) {
System.out.println( "Evento: " + obj );
return true;
}

public boolean mouseDown( Event evt,int x, int y ) {
System.out.println( "Raton: ("+x+","+y+")" );
return true;
}
}

class MiCanvas extends Canvas {
private int ancho;
private int alto;

public MiCanvas( int anc,int alt ) {
ancho = anc;
alto = alt;

reshape( 0,0,anc,alt );
}

public void paint( Graphics g ) {
g.setColor( Color.blue );
g.fillRect( 0,0,ancho,alto );
}

public boolean mouseDown( Event evt,int x, int y ) {
if( x < ancho && y < alto )
{
System.out.println( "Raton en Canvas: ("+x+","+y+")" );
return true;
}
return false;
}
}