Cinta Transportadora en Applet
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
import java.awt.Image;
import java.awt.Graphics;
import java.applet.AudioClip;
import java.util.Random;
public class trans extends Applet implements ActionListener{
//VARIABLES
private TextField XNumero = new TextField(15);
private TextField YNumero = new TextField(15);
private Frame v = new Frame();
private Button mostrar;
private Button avanza;
private Image subfondo;
private Image fondo1;
private Image caja;
private Colormaleta maleta;
private Colormaleta2 maleta2;
private Colormaleta3 maleta3;
AudioClip sonido;
//INIT
public void init(){
gui();
//text field
YNumero.setEditable(false);
XNumero.setEditable(false);
//colores de maletas
maleta = new Colormaleta(100, 20, 20);
maleta2 = new Colormaleta2(200, 20, 20);
maleta3 = new Colormaleta3(20,100,160);
subfondo = getImage(getDocumentBase(),"fondoa.png");
fondo1 = getImage( getDocumentBase(),"cinta.png" );
caja = getImage( getDocumentBase(),"caja.png" );
// sonid0o
sonido = getAudioClip( getDocumentBase(),"1.wav" );
}//fin int
// metodos bucle sonido
public void start() { sonido.loop(); }
public void stop() { sonido.stop(); }
//CONSTRUYE GUI
public void gui(){
this.setSize(new Dimension(728,500));
v.setBackground(Color.cyan);
avanza = new Button("Avanza");
add(avanza);
avanza.addActionListener(this);
mostrar=new Button("Mostrar");
add(mostrar);
mostrar.addActionListener(this);
}//fin gui
//PAINT
@Override
public void paint(Graphics g){
g.drawImage( subfondo,0,0,this);
g.drawImage( fondo1, 0, 0, this );
//nombre de proyecto
g.setColor(Color.RED);
g.setFont(new Font ("Arial", Font.BOLD+Font.ITALIC,20));
g.drawString("CINTA TRANSPORTADORA", 25, 20 );
// nombre integentes
g.setFont(new Font ("Arial", Font.BOLD+Font.ITALIC,10));
g.drawString("Integrantes: Jose Medina - Valeria Olivares - Robert Calbul - Marcela Parra", 60, 480 );
maleta.display(g);
maleta2.display(g);
maleta3.display(g);
//se superpone una imagen
g.drawImage(caja, 0, 0, this);
}//fin paint
//EVENTOS
public void actionPerformed(ActionEvent e) {
if (e.getSource() == avanza){
maleta.trasladaX();
maleta2.trasladaX();
maleta3.trasladaX();
}
//abre ventana verificacion con voton mostrar
if(e.getSource()==mostrar){
v.add(XNumero);
v.add(YNumero);
v.setLocation(150, 300);
v.setSize(370, 90);
v.setVisible(true);
//mostar cadenas aleatorias
char A1,A2;
String B1,B2;
String[] Palabras= {
"** MALETA RETENIDA EN ADUANA ** ( X )",
" MALETA NO CONTIENE ELEMENTOS PELIGROSOS ( ? )",
"** MALETA LLEVA DROGAS ** ( X ) ",
" MALETA EN PERFECTAS CONDICIONES ( ? )",
"** MALETA RETENIDA POR CONTENER EXPLOSIVOS ** ( X )"
};
Random random = new Random( System.currentTimeMillis() );
String cadrandom = Palabras[ random.nextInt(Palabras.length)];
String output = String.valueOf(cadrandom);
YNumero.setText(output);
A1=cadrandom.charAt(0);
A2=cadrandom.charAt(1);
B1=String.valueOf(A1);
B2=String.valueOf(A2);
if(B1.equals("1") || B1.equals("2")|| B1.equals("3")){
int C1 = Integer.parseInt(B1);
C1=2-C1;
String D1=String.valueOf(C1);
B1=D1;
}
if(B2.equals("1") || B2.equals("2")){
int C2 = Integer.parseInt(B2);
C2=9-C2;
String D2=String.valueOf(C2);
B2=D2;
}
//imprime las cadenas aleatorias por separado
String resultado=(B1+B2);
String Salida = String.valueOf(resultado);
XNumero.setText(Salida);
}
else {v.setVisible(false);}
repaint();
}//FIN action performed
} // FIN DE LA CLASE TRANS
//-------------------------------------------------------------------------*
//CLASES COLOR
//-------------------------------------------------------------------------*
class Colormaleta extends maleta1 {
private Color color = new Color(200, 200, 200);
private Color colo = new Color(20,100,20);
//Constructor
public Colormaleta(int r, int g, int b) {
color = new Color(r, g, b);
}
//PINTAR
public void display(Graphics g) {
g.setColor(color);
g.fillPolygon(x,y,22);
g.setColor(colo);
g.fillPolygon(X,Y,22);
}
}// FIN DE LA CLASE color maleta 1
class Colormaleta2 extends maleta2 {
private Color color = new Color(200, 200, 200);
private Color col = new Color(50,10,130);
//Constructor
public Colormaleta2(int r, int g, int b) {
color = new Color(r, g, b);
}
//PINTAR
public void display(Graphics g) {
g.setColor(color);
g.fillPolygon(z,q,12);
g.setColor(col);
g.fillPolygon(Z,Q,14);
}
}//fin clase color maleta2
class Colormaleta3 extends maleta3 {
private Color color = new Color(200, 200, 200);
private Color colore= new Color(240, 130, 20);
//Constructor
public Colormaleta3(int r, int g, int b) {
color = new Color(r, g, b);
}
//PINTAR
public void display(Graphics g) {
g.setColor(color);
g.fillPolygon(a,b,14);
g.setColor(colore);
g.fillPolygon(A,B,12);
}
}// FIN DE LA CLASE color maleta 3
//------------------------------------------------------------------------*
// CLASES PARA DIBUJAR
//------------------------------------------------------------------------*
class maleta1{
int x[ ] = {40,41,42,60,60,80, 78,62,62,78,78,80, 80,98,99,100,100,99,98,42,41,40 } ;
int y[ ] = {252,251,250,250,240,240, 242,242,250,250,242,240, 250,250,251,252,288,289,290,290,289,288 };
int X[ ] = {-240,-241,-242,-260,-260,-280, -278,-262,-262,-278,-278,-280, -280,-298,-299,-300,-300,-299,-298,-242,-241,-240 } ;
int Y[ ] = {252,251,250,250,240,240, 242,242,250,250,242,240, 250,250,251,252,288,289,290,290,289,288 };
public void display(Graphics g) {
g.drawPolygon(x, y, 22);
g.drawPolygon(X, Y, 22);
}
// IMPLEMENTACION DE METODOS DE CONTROL
public void trasladaX(){
int tx = 10, ty = 0;
for(int i=0;i< 22; i++ ) {
x[i] = x[i] + tx;
y[i] = y[i] + ty;
X[i] = X[i] + tx;
Y[i] = Y[i] + ty;
}
}//fin metodo de control
}//fin clase maleta 1
class maleta2{
int z[ ] = {160,160,170,200, 200,170,170,200,200,200, 210,210} ;
int q[ ] = {290,260,250,250, 252,252,260,260,252,250, 260,290};
int Z[ ] = {-490,-490,-460,-460,-450, -452,-458,-458,-452,-452,-450, -450,-420,-420 } ;
int Q[ ] = {290,250,262,260,260, 263,263,264,267,263,260, 268,280,290};
public void display(Graphics g) {
g.drawPolygon(z, q, 12);
g.drawPolygon(Z, Q, 14);
}
//metodo de control
public void trasladaX(){
int tx = 10, ty = 0;
for(int i=0;i< 12; i++ ) {
z[i] = z[i] + tx;
q[i] = q[i] + ty;
}
for(int i=0;i< 14; i++ ) {
Z[i] = Z[i] + tx;
Q[i] = Q[i] + ty;
}
}
}//fin clase maleta
class maleta3{
int a[ ] = {-90,-90,-60,-60,-50, -52,-58,-58,-52,-52,-50, -50,-20,-20 } ;
int b[ ] = {290,250,262,260,260, 263,263,264,267,263,260, 268,280,290};
int A[ ] = {-560,-560,-570,-600, -600,-570,-570,-600,-600,-600, -610,-610} ;
int B[ ] = {290,260,250,250, 252,252,260,260,252,250, 260,290};
public void display(Graphics g) {
g.drawPolygon(a, b, 14);
g.drawPolygon(A, B, 12);
}
// IMPLEMENTACION DE METODOS DE CONTROL
public void trasladaX(){
int tx = 10, ty = 0;
for(int i=0;i< 14; i++ ) {
a[i] = a[i] + tx;
b[i] = b[i] + ty;
}
for(int i=0;i< 12; i++ ) {
A[i] = A[i] + tx;
B[i] = B[i] + ty;
}
}
}
import java.applet.Applet;
import java.awt.event.*;
import java.awt.Image;
import java.awt.Graphics;
import java.applet.AudioClip;
import java.util.Random;
public class trans extends Applet implements ActionListener{
//VARIABLES
private TextField XNumero = new TextField(15);
private TextField YNumero = new TextField(15);
private Frame v = new Frame();
private Button mostrar;
private Button avanza;
private Image subfondo;
private Image fondo1;
private Image caja;
private Colormaleta maleta;
private Colormaleta2 maleta2;
private Colormaleta3 maleta3;
AudioClip sonido;
//INIT
public void init(){
gui();
//text field
YNumero.setEditable(false);
XNumero.setEditable(false);
//colores de maletas
maleta = new Colormaleta(100, 20, 20);
maleta2 = new Colormaleta2(200, 20, 20);
maleta3 = new Colormaleta3(20,100,160);
subfondo = getImage(getDocumentBase(),"fondoa.png");
fondo1 = getImage( getDocumentBase(),"cinta.png" );
caja = getImage( getDocumentBase(),"caja.png" );
// sonid0o
sonido = getAudioClip( getDocumentBase(),"1.wav" );
}//fin int
// metodos bucle sonido
public void start() { sonido.loop(); }
public void stop() { sonido.stop(); }
//CONSTRUYE GUI
public void gui(){
this.setSize(new Dimension(728,500));
v.setBackground(Color.cyan);
avanza = new Button("Avanza");
add(avanza);
avanza.addActionListener(this);
mostrar=new Button("Mostrar");
add(mostrar);
mostrar.addActionListener(this);
}//fin gui
//PAINT
@Override
public void paint(Graphics g){
g.drawImage( subfondo,0,0,this);
g.drawImage( fondo1, 0, 0, this );
//nombre de proyecto
g.setColor(Color.RED);
g.setFont(new Font ("Arial", Font.BOLD+Font.ITALIC,20));
g.drawString("CINTA TRANSPORTADORA", 25, 20 );
// nombre integentes
g.setFont(new Font ("Arial", Font.BOLD+Font.ITALIC,10));
g.drawString("Integrantes: Jose Medina - Valeria Olivares - Robert Calbul - Marcela Parra", 60, 480 );
maleta.display(g);
maleta2.display(g);
maleta3.display(g);
//se superpone una imagen
g.drawImage(caja, 0, 0, this);
}//fin paint
//EVENTOS
public void actionPerformed(ActionEvent e) {
if (e.getSource() == avanza){
maleta.trasladaX();
maleta2.trasladaX();
maleta3.trasladaX();
}
//abre ventana verificacion con voton mostrar
if(e.getSource()==mostrar){
v.add(XNumero);
v.add(YNumero);
v.setLocation(150, 300);
v.setSize(370, 90);
v.setVisible(true);
//mostar cadenas aleatorias
char A1,A2;
String B1,B2;
String[] Palabras= {
"** MALETA RETENIDA EN ADUANA ** ( X )",
" MALETA NO CONTIENE ELEMENTOS PELIGROSOS ( ? )",
"** MALETA LLEVA DROGAS ** ( X ) ",
" MALETA EN PERFECTAS CONDICIONES ( ? )",
"** MALETA RETENIDA POR CONTENER EXPLOSIVOS ** ( X )"
};
Random random = new Random( System.currentTimeMillis() );
String cadrandom = Palabras[ random.nextInt(Palabras.length)];
String output = String.valueOf(cadrandom);
YNumero.setText(output);
A1=cadrandom.charAt(0);
A2=cadrandom.charAt(1);
B1=String.valueOf(A1);
B2=String.valueOf(A2);
if(B1.equals("1") || B1.equals("2")|| B1.equals("3")){
int C1 = Integer.parseInt(B1);
C1=2-C1;
String D1=String.valueOf(C1);
B1=D1;
}
if(B2.equals("1") || B2.equals("2")){
int C2 = Integer.parseInt(B2);
C2=9-C2;
String D2=String.valueOf(C2);
B2=D2;
}
//imprime las cadenas aleatorias por separado
String resultado=(B1+B2);
String Salida = String.valueOf(resultado);
XNumero.setText(Salida);
}
else {v.setVisible(false);}
repaint();
}//FIN action performed
} // FIN DE LA CLASE TRANS
//-------------------------------------------------------------------------*
//CLASES COLOR
//-------------------------------------------------------------------------*
class Colormaleta extends maleta1 {
private Color color = new Color(200, 200, 200);
private Color colo = new Color(20,100,20);
//Constructor
public Colormaleta(int r, int g, int b) {
color = new Color(r, g, b);
}
//PINTAR
public void display(Graphics g) {
g.setColor(color);
g.fillPolygon(x,y,22);
g.setColor(colo);
g.fillPolygon(X,Y,22);
}
}// FIN DE LA CLASE color maleta 1
class Colormaleta2 extends maleta2 {
private Color color = new Color(200, 200, 200);
private Color col = new Color(50,10,130);
//Constructor
public Colormaleta2(int r, int g, int b) {
color = new Color(r, g, b);
}
//PINTAR
public void display(Graphics g) {
g.setColor(color);
g.fillPolygon(z,q,12);
g.setColor(col);
g.fillPolygon(Z,Q,14);
}
}//fin clase color maleta2
class Colormaleta3 extends maleta3 {
private Color color = new Color(200, 200, 200);
private Color colore= new Color(240, 130, 20);
//Constructor
public Colormaleta3(int r, int g, int b) {
color = new Color(r, g, b);
}
//PINTAR
public void display(Graphics g) {
g.setColor(color);
g.fillPolygon(a,b,14);
g.setColor(colore);
g.fillPolygon(A,B,12);
}
}// FIN DE LA CLASE color maleta 3
//------------------------------------------------------------------------*
// CLASES PARA DIBUJAR
//------------------------------------------------------------------------*
class maleta1{
int x[ ] = {40,41,42,60,60,80, 78,62,62,78,78,80, 80,98,99,100,100,99,98,42,41,40 } ;
int y[ ] = {252,251,250,250,240,240, 242,242,250,250,242,240, 250,250,251,252,288,289,290,290,289,288 };
int X[ ] = {-240,-241,-242,-260,-260,-280, -278,-262,-262,-278,-278,-280, -280,-298,-299,-300,-300,-299,-298,-242,-241,-240 } ;
int Y[ ] = {252,251,250,250,240,240, 242,242,250,250,242,240, 250,250,251,252,288,289,290,290,289,288 };
public void display(Graphics g) {
g.drawPolygon(x, y, 22);
g.drawPolygon(X, Y, 22);
}
// IMPLEMENTACION DE METODOS DE CONTROL
public void trasladaX(){
int tx = 10, ty = 0;
for(int i=0;i< 22; i++ ) {
x[i] = x[i] + tx;
y[i] = y[i] + ty;
X[i] = X[i] + tx;
Y[i] = Y[i] + ty;
}
}//fin metodo de control
}//fin clase maleta 1
class maleta2{
int z[ ] = {160,160,170,200, 200,170,170,200,200,200, 210,210} ;
int q[ ] = {290,260,250,250, 252,252,260,260,252,250, 260,290};
int Z[ ] = {-490,-490,-460,-460,-450, -452,-458,-458,-452,-452,-450, -450,-420,-420 } ;
int Q[ ] = {290,250,262,260,260, 263,263,264,267,263,260, 268,280,290};
public void display(Graphics g) {
g.drawPolygon(z, q, 12);
g.drawPolygon(Z, Q, 14);
}
//metodo de control
public void trasladaX(){
int tx = 10, ty = 0;
for(int i=0;i< 12; i++ ) {
z[i] = z[i] + tx;
q[i] = q[i] + ty;
}
for(int i=0;i< 14; i++ ) {
Z[i] = Z[i] + tx;
Q[i] = Q[i] + ty;
}
}
}//fin clase maleta
class maleta3{
int a[ ] = {-90,-90,-60,-60,-50, -52,-58,-58,-52,-52,-50, -50,-20,-20 } ;
int b[ ] = {290,250,262,260,260, 263,263,264,267,263,260, 268,280,290};
int A[ ] = {-560,-560,-570,-600, -600,-570,-570,-600,-600,-600, -610,-610} ;
int B[ ] = {290,260,250,250, 252,252,260,260,252,250, 260,290};
public void display(Graphics g) {
g.drawPolygon(a, b, 14);
g.drawPolygon(A, B, 12);
}
// IMPLEMENTACION DE METODOS DE CONTROL
public void trasladaX(){
int tx = 10, ty = 0;
for(int i=0;i< 14; i++ ) {
a[i] = a[i] + tx;
b[i] = b[i] + ty;
}
for(int i=0;i< 12; i++ ) {
A[i] = A[i] + tx;
B[i] = B[i] + ty;
}
}
}
Comentarios
Publicar un comentario
Deja tus comentario