Article View: es.comp.lenguajes.java
Article #29390Por si alguien se aventura...
From: Eustaquio Mart�n
Date: Wed, 10 Dec 1997 00:00
Date: Wed, 10 Dec 1997 00:00
153 lines
5227 bytes
5227 bytes
Por si alguien se aventura a descifrar este c�digo aqu� va mi consulta:
La pretensi�n de este c�digo es la de mostrar un panel en un applet que
cambia de aspecto cuando el rat�n pasa por encima.
Evidentemente no funciona, �c�mo si no?.
El caso es que el panel, anteriormente, lo constru� como un applet y
funcionaba perfectamente, despu�s lo convert� en un panel, se lo a�ad� al
applet y todo se jodior.
Me muestra el panel muy peque�o y no como lo dimensiono y me da el error
"java.lang.NullPointerException".
�Alg�n alma caritativa se atrever�a a revisar el c�digo?
package prlink;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class prlinkcl extends Applet {
boolean isStandalone = false;
linkcl link1 = new linkcl();
FlowLayout flowLayout1 = new FlowLayout();
//Get a parameter value
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}
//Construct the applet
public prlinkcl() {
}
//Initialize the applet
public void init() {
try { jbInit(); } catch (Exception e) { e.printStackTrace(); }
}
//Component initialization
public void jbInit() throws Exception{
this.setLayout(flowLayout1);
this.add(link1, null);
}
//Get Applet information
public String getAppletInfo() {
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo() {
return null;
}
}
class linkcl extends Panel {
BorderLayout borderLayout1 = new BorderLayout();
public String texto="Link";
public Font fuente=new Font("Dialog",0,18);
public byte alineacion=0;
public byte margen=10;
public Color colorFondo=new Color(192,192,192);
public Color colorTexto=new Color(64,64,64);
public Color colorLuz=new Color(255,255,255);
public Color colorSombra=new Color(0,0,0);
public int desplazamiento=0;
private boolean encendido=false;
private int ancho;
private int alto;
Image imagen;
Image imagenluz;
//Initialize the applet
public void init() {
try { jbInit(); } catch (Exception e) { e.printStackTrace(); }
}
//Component initialization
public void jbInit() throws Exception{
this.addMouseListener(new linkcl_this_mouseAdapter(this));
this.setLayout(borderLayout1);
this.reajusta();
}
public void paint(Graphics g){
this.setBackground(colorFondo);
if (encendido)
this.pintaEncendido(g);
else
this.pintaApagado(g);
}
private void pintaApagado(Graphics g){
g.drawImage(imagen,margen,margen,this);
}
private void pintaEncendido(Graphics g){
g.drawImage(imagenluz,margen,margen,this);
}
private void reajusta(){
// C�lculos generales
FontMetrics fm=getFontMetrics(fuente);
int despla;
if (desplazamiento<1){
despla=(int)(fm.getHeight()*0.01);
if (despla<1)
despla=1;
}else{
despla=desplazamiento;
}
ancho=fm.stringWidth(this.texto)+margen*2+despla*2;
alto=fm.getHeight()+margen*2+despla*2;
this.resize(ancho,alto);
// Crea imagen
Graphics imagenG;
imagen=createImage(ancho-margen*2,alto-margen*2);
imagenG=imagen.getGraphics();
imagenG.setColor(colorFondo);
imagenG.fillRect(0,0,ancho+despla*2-margen*2,alto+despla*2-margen*2);
imagenG.setColor(colorTexto);
imagenG.setFont(fuente);
imagenG.drawString(texto,despla*2,despla*2+(alto-margen*2)-(fm.getDescent()+
despla*6));
// Crea imagen con luz
Graphics imagenluzG;
imagenluz=createImage(ancho-margen*2,alto-margen*2);
imagenluzG=imagenluz.getGraphics();
imagenluzG.setColor(colorFondo);
imagenluzG.fillRect(0,0,ancho-margen*2,alto-margen*2);
imagenluzG.setFont(fuente);
imagenluzG.setColor(colorSombra);
imagenluzG.drawString(texto,despla*2,despla*2+(alto-margen*2)-(fm.getDescent
()+despla*6));
imagenluzG.setColor(colorLuz);
imagenluzG.drawString(texto,0,(alto-margen*2)-(fm.getDescent()+despla*6));
imagenluzG.setColor(colorTexto);
imagenluzG.drawString(texto,despla,despla+(alto-margen*2)-(fm.getDescent()+d
espla*6));
}
void this_mouseEntered(MouseEvent e) {
this.encendido=true;
repaint();
}
void this_mouseExited(MouseEvent e) {
this.encendido=false;
repaint();
}
}
class linkcl_this_mouseAdapter extends java.awt.event.MouseAdapter {
linkcl adaptee;
linkcl_this_mouseAdapter(linkcl adaptee) {
this.adaptee = adaptee;
}
public void mouseEntered(MouseEvent e) {
adaptee.this_mouseEntered(e);
}
public void mouseExited(MouseEvent e) {
adaptee.this_mouseExited(e);
}
}
Technical Details
Message-ID:
<66m9rn$b04$1@talia.mad.ibernet.es>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII X-Google-Thread: 1116f3,1dee89f701cf6e40,start X-Google-Attributes: gid1116f3,public From: "Eustaquio Mart�n" <eustma@softcom.es> Subject: Por si alguien se aventura... Date: 1997/12/10 Message-ID: <66m9rn$b04$1@talia.mad.ibernet.es> X-Deja-AN: 296924545 X-MimeOLE: Produced By Microsoft MimeOLE V4.71.1712.3 Organization: Unisource Espana NEWS SERVER Newsgroups: es.comp.lenguajes.java