Lieber Besucher, herzlich willkommen bei: Banana-Coding.com - Java Knuddels Emulator. Falls dies dein erster Besuch auf dieser Seite ist, lies bitte die Hilfe durch. Dort wird dir die Bedienung dieser Seite näher erläutert. Darüber hinaus solltest du dich registrieren, um alle Funktionen dieser Seite nutzen zu können. Benutze das Registrierungsformular, um dich zu registrieren oder informiere dich ausführlich über den Registrierungsvorgang. Falls du dich bereits zu einem früheren Zeitpunkt registriert hast, kannst du dich hier anmelden.



Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »uncopyable« (3. Mai 2012, 11:59)
|
|
PHP-Quelltext |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JTextPane;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Mentos
*/
public class KPanel extends JTextPane {
private StringBuilder contentBuilder = new StringBuilder("<html></html>");
private Image backgroundImage = null;
private BACKGROUNDPOSITION position = BACKGROUNDPOSITION.CENTERED;
private Color backgroundColor = Color.BLUE;
public KPanel() {
setBackground(new Color(0,0,0,0));
setContentType("text/html");
}
public void setBackgroundImage(String imagePath, BACKGROUNDPOSITION position) {
if (imagePath.startsWith("http://")) {
try {
/*String parameter = java.net.URLEncoder.encode(imagePath.substring(imagePath.lastIndexOf("/") + 1), "UTF-8");
imagePath = String.format("%s/%s", imagePath.substring(0, imagePath.lastIndexOf("/")), parameter);*/
backgroundImage = Toolkit.getDefaultToolkit().getImage(new URL(imagePath));
} catch (Exception x) {
Logger.getLogger(getClass().getName()).log(Level.WARNING, String.format("Couldn't load Background-Image: %s\r\n%s", imagePath,
x.toString()));
}
} else {
try {
backgroundImage = Toolkit.getDefaultToolkit().getImage(imagePath);
} catch (Exception x) {
Logger.getLogger(getClass().getName()).log(Level.WARNING, String.format("Couldn't load Background-Image: %s\r\n%s", imagePath,
x.toString()));
}
}
this.position = position;
}
public void setBackgroundColor(Color backgroundColor){
this.backgroundColor = backgroundColor;
}
@Override
protected void paintComponent(Graphics g) {
g.setColor(backgroundColor);
g.fillRect(0, 0, getWidth(), getHeight());
if (backgroundImage != null) {
switch(position)
{
case LEFT:
g.drawImage(backgroundImage, 0, 0, this);
break;
case SCALED:
g.drawImage(backgroundImage, 0, 0, getWidth(), getHeight(), this);
break;
case CENTERED:
g.drawImage(backgroundImage, (getWidth() - backgroundImage.getWidth(this))/2,
(getHeight() - backgroundImage.getHeight(this))/2, this);
break;
}
}
super.paintComponent(g);
}
public void addMessage(Color nickColor, String senderNick, String message) {
contentBuilder.delete(contentBuilder.length() - "</html>".length(), contentBuilder.length());
contentBuilder.append("<b><font color="#").append(Integer.toHexString( nickColor.getRGB() & 0x00ffffff ))
.append("">").append(senderNick).append("</font></b>: ").append(message).append("<br>");
contentBuilder.append("</html>");
setText(contentBuilder.toString());
}
public static enum BACKGROUNDPOSITION {
LEFT,
CENTERED,
SCALED
}
//Uncool overrides
@Override
public void setEditable(boolean b) {
super.setEditable(false);
}
@Override
public void setOpaque(boolean isOpaque) {
super.setOpaque(false);
}
}
|