viernes, 1 de enero de 2010
Caracteristicas del los sliders
Las caracteristicas del los sliders ocupados son
private JSlider createSlider(int VAL) {
JSlider sl=new JSlider();
sl.setOrientation(JSlider.VERTICAL);
sl.setPaintLabels(true);
sl.setPaintTicks(true);
sl.setMinimum(Menor);
sl.setMaximum(Mayor);
sl.setValue(VAL);
sl.setMajorTickSpacing(25);
sl.setMinorTickSpacing(5);
sl.addChangeListener(this);
return sl;
}
}
private JSlider createSlider(int VAL) {
JSlider sl=new JSlider();
sl.setOrientation(JSlider.VERTICAL);
sl.setPaintLabels(true);
sl.setPaintTicks(true);
sl.setMinimum(Menor);
sl.setMaximum(Mayor);
sl.setValue(VAL);
sl.setMajorTickSpacing(25);
sl.setMinorTickSpacing(5);
sl.addChangeListener(this);
return sl;
}
}
Validación de los eventos de los botones del mouse
Validador de eventos de los botones
public void actionPerformed(ActionEvent e){
if(e.getSource()==pre){
System.exit(0);//Sale del sistema
}
if(e.getSource()==cc){
click = 1;//ocupo estas variables para establecer el pinta con o sin click del mouse
}
if(e.getSource()==sc){
click = 2;//ocupo estas variables para establecer el pinta con o sin click del mouse
}
if(e.getSource()==br){
click = 3;
}
if(e.getSource()==imagen){
FileDialog fd = new FileDialog(this,"ABRIR",FileDialog.LOAD);
fd.show();
File f = new File( fd.getDirectory(),fd.getFile() );
ImageIcon image = new ImageIcon(f.toString());
dibujar.add(img);
img.setIcon(image);
img.setSize(135,135);
img.setLocation(550,20);
img.setVisible(true);
}
if(e.getSource()==limagen){
img.setVisible(false);
}
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==pre){
System.exit(0);//Sale del sistema
}
if(e.getSource()==cc){
click = 1;//ocupo estas variables para establecer el pinta con o sin click del mouse
}
if(e.getSource()==sc){
click = 2;//ocupo estas variables para establecer el pinta con o sin click del mouse
}
if(e.getSource()==br){
click = 3;
}
if(e.getSource()==imagen){
FileDialog fd = new FileDialog(this,"ABRIR",FileDialog.LOAD);
fd.show();
File f = new File( fd.getDirectory(),fd.getFile() );
ImageIcon image = new ImageIcon(f.toString());
dibujar.add(img);
img.setIcon(image);
img.setSize(135,135);
img.setLocation(550,20);
img.setVisible(true);
}
if(e.getSource()==limagen){
img.setVisible(false);
}
}
Oyente de cambios
Este es el oyente de cambios empleado para los JSliders
public void stateChanged(ChangeEvent e) {
int crojo,cazul,cverde;
Cambia el valor de los colores con respecto al slider
crojo=rojo.getValue();
cazul=azul.getValue();
cverde=verde.getValue();
cambia el color de el panel inferior
cambiacolor.setBackground(new Color(crojo,cverde,cazul));
r.setText("ROJO "+ crojo);
r.setForeground(new Color(crojo,0,0));
v.setText("VERDE "+ cverde);
v.setForeground(new Color(0,cverde,0));
a.setText("AZUL "+ cazul);
a.setForeground(new Color(0,0,cazul));
crojo1=crojo;
cazul1=cazul;
cverde1=cverde;
}
public void stateChanged(ChangeEvent e) {
int crojo,cazul,cverde;
Cambia el valor de los colores con respecto al slider
crojo=rojo.getValue();
cazul=azul.getValue();
cverde=verde.getValue();
cambia el color de el panel inferior
cambiacolor.setBackground(new Color(crojo,cverde,cazul));
r.setText("ROJO "+ crojo);
r.setForeground(new Color(crojo,0,0));
v.setText("VERDE "+ cverde);
v.setForeground(new Color(0,cverde,0));
a.setText("AZUL "+ cazul);
a.setForeground(new Color(0,0,cazul));
crojo1=crojo;
cazul1=cazul;
cverde1=cverde;
}
Paneles para los Sliders
Se utilizan algunos paneles para los sliders y el area de dibujo como los que se muestran
JSlider rojo;
JSlider verde;
JSlider azul;
JPanel panelColor1;
JPanel panelcolor2;
JPanel panelcolor3;
JPanel dibujar;
JPanel cambiacolor;
JButton pre=new JButton("SALIR");
JButton cc=new JButton("Dibujar con Click");
JButton sc=new JButton("Dibujar sin Click");
JButton br=new JButton ("Borrador");
JButton imagen=new JButton("Abrir imagen");
JButton limagen=new JButton("Limpiar imagen");
JLabel r=new JLabel("ROJO 127");
JLabel v=new JLabel("VERDE 127");
JLabel a=new JLabel("AZUL 127");
JLabel img=new JLabel(" ");
JSlider rojo;
JSlider verde;
JSlider azul;
JPanel panelColor1;
JPanel panelcolor2;
JPanel panelcolor3;
JPanel dibujar;
JPanel cambiacolor;
JButton pre=new JButton("SALIR");
JButton cc=new JButton("Dibujar con Click");
JButton sc=new JButton("Dibujar sin Click");
JButton br=new JButton ("Borrador");
JButton imagen=new JButton("Abrir imagen");
JButton limagen=new JButton("Limpiar imagen");
JLabel r=new JLabel("ROJO 127");
JLabel v=new JLabel("VERDE 127");
JLabel a=new JLabel("AZUL 127");
JLabel img=new JLabel(" ");
Variables de color
Variables ocupadas para revolver los colores
int Menor = 0;
int Mayor = 255;
int medio = 127;
int colorinicial=127;
int uX=0;
int uY=0;
int crojo1=127;
int cazul1=127;
int cverde1=127;
int click=0,c=0,c2=4;
int Menor = 0;
int Mayor = 255;
int medio = 127;
int colorinicial=127;
int uX=0;
int uY=0;
int crojo1=127;
int cazul1=127;
int cverde1=127;
int click=0,c=0,c2=4;
Detalle del color
El Main instancia el frame y se le da las características en este caso se le colocan los colores ha utilizar el dibujo
public static void main(String[]args){
Colores slider = new Colores();
slider.setSize(900,450);
slider.setTitle("DIBUJO");
slider.setLocationRelativeTo(null);
slider.setVisible(true);
}
public static void main(String[]args){
Colores slider = new Colores();
slider.setSize(900,450);
slider.setTitle("DIBUJO");
slider.setLocationRelativeTo(null);
slider.setVisible(true);
}
Suscribirse a:
Entradas (Atom)