Ver Mensaje Individual
  #1 (permalink)  
Antiguo 21/01/2007, 07:17
mrdax
 
Fecha de Ingreso: enero-2007
Mensajes: 1
Antigüedad: 17 años, 4 meses
Puntos: 0
Problema con applet

Código:
Wenas, estoy liado con una practica para la uni en java que me tiene bastante harto. Vereis, el problema radica en el text field que no recoge los datos. El resto esta bien, ya que si meto los datos internamente, hace el dibujo correctamente.

A ver si alguno de vosotros tiene mas acierto que yo con el error.

import java.awt.*;
import java.applet.*;
import java.util.*;


public class applet extends Applet
{

float x1,y1,c;
float x2,y2,d;


TextField tfx1 = new TextField (1);
TextField tfy1 = new TextField (1);
TextField tfx2 = new TextField (1);
TextField tfy2 = new TextField (1);

TextField tfc = new TextField (1);
TextField tfd = new TextField (1);

Font fuente=new Font("TimesRoman", Font.PLAIN, 11);
Color amarillo=new Color(255,255,51);

Label inici1 = new Label ("Determina el ");
Label inici2 = new Label (" sistema ");
Label inici3 = new Label ("d'equacions que");
Label inici4 = new Label (" vols introduir");
Label inici5 = new Label (" introduir: ");
Label lx1 = new Label (" x +");
Label ly1 = new Label (" y = ");
Label lx2 = new Label (" x +");
Label ly2 = new Label (" y = ");

Label l=new Label(" ");

Button boton = new Button("Calcula");



FlowLayout flowLayout1= new FlowLayout();
GridLayout gridLayout2 =new GridLayout(3,6);//Tabla GridLayout(filas,columnas);
Panel panel1=new Panel();



public void init()
{

this.setSize(new Dimension(750, 300));
this.setFont(fuente);
this.setLayout(flowLayout1);
flowLayout1.setAlignment(2);
this.add(panel1);

panel1.setSize(300,50);
panel1.setLayout( gridLayout2);
panel1.add(inici1,null);
panel1.add(inici2,null);
panel1.add(inici3,null);
panel1.add(inici4,null);
panel1.add(inici5,null);

gridLayout2.setVgap(5);//Interlineado

panel1.add(tfx1, null);
panel1.add(lx1, null);
panel1.add(tfy1, null);
panel1.add(ly1, null);
panel1.add(tfc, null);

panel1.add(tfx2, null);
panel1.add(lx2, null);
panel1.add(tfy2, null);
panel1.add(ly2, null);
panel1.add(tfd, null);




}

public void datos ()
{

x1=Float.parseFloat(tfx1.getText());
// l.setText(tfx1.getText());
y1= Float.parseFloat(tfy1.getText());
c= Float.parseFloat(tfc.getText());

x2= Float.parseFloat(tfx2.getText());
y2=Float.parseFloat(tfy2.getText());

d= Float.parseFloat(tfd.getText());
}

public void paint(Graphics g) {

g.setColor(amarillo);
g.fillRect(0, 0, 500,500);

g.setColor(Color.blue);
g.drawLine(250,0,250,500); // eix y
g.drawLine(0,250,500,250); // eix x



g.setColor(Color.red);
// g.drawLine(125, 515, 180,515);
g.drawString("EN CONSTRUCCIÓ", 100,100);
/* g.drawString("valor x1: "+x1, 75, 530);
g.drawString("valor y1: "+y1, 170, 530);
g.drawString("valor c: "+c, 265, 530);*/


}



}
Un saludo y gracias