Foros del Web » Programación para mayores de 30 ;) » Java »

Mi codigo no funciona en Netbeans Linux

Estas en el tema de Mi codigo no funciona en Netbeans Linux en el foro de Java en Foros del Web. Disculpen lo que sucede es que tengo un código que me dejaron de trabajo para una calificada, alli usan Netbeans 6.9 en Linux (Scientific Linux), ...
  #1 (permalink)  
Antiguo 03/07/2011, 09:55
Avatar de afranco  
Fecha de Ingreso: julio-2011
Mensajes: 2
Antigüedad: 12 años, 9 meses
Puntos: 0
Mi codigo no funciona en Netbeans Linux

Disculpen lo que sucede es que tengo un código que me dejaron de trabajo para una calificada, alli usan Netbeans 6.9 en Linux (Scientific Linux), yo uso Netbeans 6.9.1 en Windows, termine mi codigo y funciona en Windows, pero en mi Facultad no funciona, acabo de instalar Ubuntu en mi pc y tampoco funciona, y he comprobado otro Windows y si funciona, ¿que tengo que cambiar en el codigo? pensaba que en Windows y Linux era lo mismo por usar Netbeans. Este es mi codigo:

import java.util.*;
import javax.swing.JOptionPane;
import java.applet.*;
import javax.swing.JApplet;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Main extends JApplet implements Runnable,KeyListener{

Thread anima;
int radio=10; //radio de bala
int x, y; //posición de bala para grafica
int x0 = 20; //pos inicial
int y0 = 20;
int vx0 = 20; //vel inicial
int vy0 = 20;
double g=0.05; //Gravedad
int anchoApplet;
int altoApplet;
int retardo=10; //retardo
int res; //restitucion de bala
int friccion; //friccion
String Listener;
String Listen=" presione 'P' o 'V'";//muestra la seleccion
LinkedList<Bala> ListaBalas=new LinkedList<Bala>(); //Lista de balas
Image imag; //imagen donde se carga una foto de un instante
Graphics gg; //bufffer Graphics para cargar la imagen imag

public void init () {

setSize(400,400);//dimensiones del applet
anchoApplet=getSize().width;
altoApplet=getSize().height;
addKeyListener( this );//ESTE ES EL PROBLEMA PARECE NO FUNCIONA EN LINUX
res=Integer.parseInt(JOptionPane.showInputDialog(" Ingrese restitucion (0-100)"));
friccion=Integer.parseInt(JOptionPane.showInputDia log("Ingrese friccion (0-100)"));
}

public void paint(Graphics g){
imag=createImage(anchoApplet, altoApplet);
gg=imag.getGraphics();
gg.setColor(Color.black);
gg.drawOval(x0, y0, 2*radio, 2*radio);//posicion
gg.drawLine(x0+radio, y0+radio, x0+vx0+radio, y0+vy0+radio);//velocidad
gg.setColor(Color.blue);
gg.drawString("X0="+x0+" Y0="+y0+" Vx="+vx0+" Vy="+vy0+Listen,5, 15);//datos
gg.setColor(Color.red);
int ix=ListaBalas.size();
if(ix!=0){//grafica todas las balas
for (int ii=0;ii<=ix-1;ii++){
gg.fillOval((int)ListaBalas.get(ii).getpx()-radio,(int)ListaBalas.get(ii).getpy()-radio, 2*radio, 2*radio);
}
}
g.drawImage(imag, 0, 0, null);
}

public void start(){
if(anima ==null){
anima=new Thread(this);
anima.start();
}
}

public void run() {
long t=System.currentTimeMillis();
while (true) {
mueveBalas();
try{
t+=retardo;
Thread.sleep(Math.max(0, t-System.currentTimeMillis()));

}catch(InterruptedException ex){
break;
}
}
}

public void startBall(){
Bala b=new Bala();
b.setBala(x0+radio, y0+radio, vx0, vy0, radio);
ListaBalas.addFirst(b);
}

void mueveBalas(){
int i=ListaBalas.size();
//System.out.println(i);
if(i!=0){
for(int jj=0; jj<=i-1;jj++){
for (int ii=jj+1;ii<=i-1;ii++){
pruebaChoque(ListaBalas.get(ii),ListaBalas.get(jj) );
}
}
}
if(i!=0){
for (int ii=0;ii<=i-1;ii++){
moverBala(ListaBalas.get(ii));
if(ListaBalas.get(ii).getInactividad()>4){
ListaBalas.remove(ii);
i--;
ii--;
}
}
}
repaint();
}

void moverBala(Bala b) {
double vy;
double vx;
double xx;
double yy;
vy=b.getvy();//se obtiene los datos de la bala
vx=b.getvx();
xx=b.getpx();
yy=b.getpy();
if(((int)vx==0)&&((int)vy==0)&&((int)yy==(altoAppl et-radio))){
int Inac=b.getInactividad();
Inac++;//aplicamos conteo de inactividad
b.changeInactividad(Inac);
}
vy=vy+g;
if((Math.abs(vy)<1)&&(yy>=(altoApplet-radio))){
vx=vx*(100-friccion)/100;
}
//vx=(vx*(10000-friccion))/10000;
//vy=(vy*(10000-friccion))/10000;
xx=xx+vx;
yy=yy+vy+g/2;
x = (int)(xx);
y = (int)(yy);
if (Math.abs(vx)<0.007){vx=0;}//detiene la pelota
if (xx > (anchoApplet-radio) || xx < radio) {
vx+=(-2*(vx*(100+res))/200);
if((xx>(anchoApplet-radio))){
xx=(anchoApplet-radio);
}
if(xx<radio){
xx=radio;
}
}
if (yy > (altoApplet-radio) || yy < radio) {
vy+=(-2*(vy*(100+res))/200);//
if((vy<1)&&(yy>(altoApplet-radio))){
yy=(altoApplet-radio);
}
if(yy<radio){
yy=radio;
}
}
b.changePos(xx, yy);
b.changeVel(vx, vy);

}

public void pruebaChoque(Bala bala2,Bala bala1){
double x1,x2,y1,y2;
x1=bala1.getpx();
y1=bala1.getpy();
x2=bala2.getpx();
y2=bala2.getpy();
if((Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)))<(2*radio)){
double k,Vux,Vuy,V1px,V1py,V2px,V2py,V1ux,V1uy,V2ux,V2uy, Vcx,Vcy;//Vu: vector distancia
Vux=x1-x2;//componente del vector distancia x
Vuy=y1-y2;//componente del vector distancia y
k=(bala1.getvx()*Vux+bala1.getvy()*Vuy)/(Vux*Vux+Vuy*Vuy);//K constante de transformacion
V1ux=k*Vux;//componente x de V1 paralelo a Vu
V1uy=k*Vuy;//componente y de V1 paralelo a Vu
V1px=bala1.getvx()-V1ux;
V1py=bala1.getvy()-V1uy;
k=(bala2.getvx()*Vux+bala2.getvy()*Vuy)/(Vux*Vux+Vuy*Vuy);//K constante de transformacion
V2ux=k*Vux;//componente x de V1 paralelo a Vu
V2uy=k*Vuy;//componente y de V1 paralelo a Vu
V2px=bala2.getvx()-V2ux;
V2py=bala2.getvy()-V2uy;
Vcx=V1ux;//Vcx y Vcy hacen posible el cambio
Vcy=V1uy;
V1ux=V2ux;
V1uy=V2uy;
V2ux=Vcx;
V2uy=Vcy;
V2ux=V2ux*(100+res)/200;//Choque hace que sea mas lento
V2uy=V2uy*(100+res)/200;
V1ux=V1ux*(100+res)/200;
V1uy=V1uy*(100+res)/200;
bala1.changeVel(V1ux+V1px,V1uy+V1py);
bala2.changeVel(V2ux+V2px,V2uy+V2py);
}

}
public void keyPressed( KeyEvent LPres )
{
switch (LPres.getKeyCode()){
case KeyEvent.VK_LEFT:
if(Listener=="v"){
vx0--;
}
if(Listener=="p"){
x0--;
}
break;
case KeyEvent.VK_RIGHT:
if(Listener=="v"){
vx0++;
}
if(Listener=="p"){
x0++;
}
break;
case KeyEvent.VK_UP:
if(Listener=="v"){
vy0--;
}
if(Listener=="p"){
y0--;
}
break;
case KeyEvent.VK_DOWN:
if(Listener=="v"){
vy0++;
}
if(Listener=="p"){
y0++;
}
break;
}
}


public void keyReleased( KeyEvent LPres )//ESTO NO FUNCIONA EN LINUX
{
switch (LPres.getKeyCode()){
case KeyEvent.VK_V:
Listener="v";
Listen=" Velocidad seleccionado";
break;
case KeyEvent.VK_P:
Listener="p";
Listen=" Posicion seleccionado";
break;
case KeyEvent.VK_LEFT:
if(Listener=="v"){
vx0--;
}
if(Listener=="p"){
x0--;
}
break;
case KeyEvent.VK_RIGHT:
if(Listener=="v"){
vx0++;
}
if(Listener=="p"){
x0++;
}
break;
case KeyEvent.VK_UP:
if(Listener=="v"){
vy0--;
}
if(Listener=="p"){
y0--;
}
break;
case KeyEvent.VK_DOWN:
if(Listener=="v"){
vy0++;
}
if(Listener=="p"){
y0++;
}
break;
case KeyEvent.VK_SPACE:
startBall();
break;
}
}

public void keyTyped( KeyEvent LPres )
{
}

}

***
Manejamos con las flechas y las letras P y V (posicion y velocidad) las esferas chocan entre si (a veces las esferas se juntan y no se chocan pero eso no es el problema), tambien tengo la clase objeto Bala si lo necesitan me dicen, el problema del profesor lo saco de un examen del internet [URL="http://www.bamtanggames.com/exams/cpp/exam_es.htm"]http://www.bamtanggames.com/exams/cpp/exam_es.htm[/URL]
es la numero 7, gracias desde ya por la atencion.

Etiquetas: linux, netbeans, windows
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 12:52.