2 Probleme mit einem Applet

steff aka sId

Erfahrenes Mitglied
Hi erstmal folgender Code(Es handelt sich um eine signierte .jar) dann mein Problem:
Code:
import java.awt.Color;
import java.awt.Font;
import java.awt.FontFormatException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import javax.swing.JApplet;
import javax.swing.JLabel;
import javax.swing.border.LineBorder;

/*
 * Created on 21.02.2005
 */

/**
 * @author Steffen Rumpf
 */
public class Main extends JApplet {
    
    /**
     * the label which will contain the text
     */
    private JLabel customLabel = null;
    
    public void init() {
        this.getContentPane().setLayout(null);
        
        customLabel = new JLabel("Hello World(custom)");
        customLabel.setBounds(25,75,150,50);
        customLabel.setBorder(new LineBorder(Color.black, 1));
        
        Font customFont = null;
        
        try {
            //Create a special font which is not in the system
            customFont = Font.createFont(
                    Font.TRUETYPE_FONT, 
                    new FileInputStream("comicf"));
            customFont = customFont.deriveFont( 50f);
            customFont = customFont.deriveFont( Font.BOLD );
        } catch (FileNotFoundException e) {
            // Not used add this time
            customFont = new Font("serif", 12, Font.BOLD);
            //e.printStackTrace();
        } catch (FontFormatException e) {
            // Not used add this time
            customFont = new Font("serif", 12, Font.BOLD);
            //e.printStackTrace();
        } catch (IOException e) {
            // Not used add this time
            customFont = new Font("serif", 12, Font.BOLD);
            //e.printStackTrace();
        }
        customLabel.setFont(customFont);
      
            this.addMouseMotionListener(new MouseMotionListener() {
            public void mouseDragged(MouseEvent arg0) {
                    int x = arg0.getX();
                    int y = arg0.getY();
                    if(x < 0) {
                        x = 0;
                    }else if( x > 200 - 150 ) {
                        x = 200 - 150;
                    }
                    if(y < 0) {
                        y = 0;
                    }else if( y > 200 - 50 ) {
                        y = 200 - 50;
                    }
                    customLabel.setBounds(x, y, 150,50);
                    customLabel.repaint();
            }

            public void mouseMoved(MouseEvent arg0) {
                // Not used    
            }
            
       });
        this.getContentPane().add(customLabel);
    }
}

Also mein erstes Problem ist das ich mit customFont = customFont.deriveFont( 50f); sich nicht die Schriftgröße ändern lässt im Appletvierwer kein Probelm gibt es da irgend eine andere Methode mit der man das machen kann oder gibt es dabei irgend etwas zu beachten bei Applets?

Mein zweites Problem ist der MouseListener mit dem will ich das JLabel in meinem Applet verschieben können funktioniert im Appletvierwer auch einwand frei aber in html nicht mehr. Weiß jemand woran das liegen kann (Gelöst hab einfach den MouseMotionListener mit implements eingebunden dann gings)

Lg Steff
 
Zuletzt bearbeitet:
Anders gefragt:
Gibt es noch andere Möglichkeiten als mit deriveFont die Größe einer Schriftart zu verändern. Bzw. sind Probleme mit deriveFont in Verbindung mit Applets bekannt?

Das Problem entsteht dadurch das wenn ich mit createFont eine "neue" Schriftart erzeuge diese die Schriftgröße 1 hat.

Gruß Steff
 
Zurück