DeKaDeNz (02.02.2012)
Thema: [Java] Popup
-
02.02.2012, 16:18 #1
- Registriert seit
- 06.11.2011
- Beiträge
- 418
Thanked 686 Times in 246 Posts[Java] Popup
/**
*
* @author Flav
*/
public class Popup {
private String title, subtitle, message;
private int width, height;
private String background;
private PacketWriter packet;
public Popup(String title, String subtitle, String message, int width, int height) {
this(title, subtitle, message, width, height, "pics/cloudsblue.gif");
}
public Popup(String title, String subtitle, String message, int width, int height, String background) {
this.title = title;
this.subtitle = subtitle;
this.message = message;
this.width = width;
this.height = height;
this.background = background;
}
private void addSize(int size) {
packet.write(size + 'A');
}
private void addString(String str) {
packet.writeString(str);
packet.write(0xF5);
}
private void addForeground(int[] color) {
packet.write('f');
for (int c : color) {
packet.write(c);
}
}
private void addBackground(int[] color) {
packet.write('h');
for (int c : color) {
packet.write(c);
}
}
private void addFontStyle(char weight, int size) {
if (weight != 'p') {
packet.write(weight);
}
packet.write('g');
addSize(size);
}
private void addPanel(char layout) {
packet.write('p');
packet.write(layout);
}
private void addPanelSize(int width, int height) {
packet.write('s');
packet.writeShort(width);
packet.writeShort(height);
}
private void addBackgroundImage(String image, int alignment) {
packet.write('i');
addString(image);
packet.writeShort(alignment);
}
public String toString() {
packet = new PacketWriter();
packet.writeString("k");
packet.write(0x00);
addString(title);
addForeground(new int[] { 0x00, 0x00, 0x00 });
addBackground(new int[] { 0xBE, 0xBC, 0xFB });
packet.write(0xE3);
packet.write('N');
packet.write('l');
addString(" ");
addFontStyle('p', 5);
packet.write(0xE3);
packet.write('W');
packet.write('l');
addString(" ");
addFontStyle('p', 5);
packet.write(0xE3);
packet.write('E');
packet.write('l');
addString(" ");
addFontStyle('p', 5);
packet.write(0xE3);
packet.write('C');
addPanel('B');
if (subtitle != null) {
packet.write('N');
addPanel('B');
packet.write('C');
packet.write('l');
addString(subtitle);
addFontStyle('b', 16);
addBackground(new int[] { 0xE5, 0xE5, 0xFF });
packet.write(0xE3);
packet.write('S');
packet.write('l');
addString(" ");
addFontStyle('p', 5);
packet.write(0xE3);
packet.write(0xE3);
}
if (message != null) {
packet.write('C');
packet.write('c');
addString(message);
addPanelSize(width, height);
addBackground(new int[] { 0xBE, 0xBC, 0xFB });
if (background != null) {
addBackgroundImage(background, 17);
}
packet.write(0xE3);
}
packet.write(0xE3);
packet.write('S');
addPanel('F');
packet.write('b');
addString(" OK ");
addFontStyle('p', 16);
packet.write('d');
addBackground(new int[] { 0xBE, 0xBC, 0xFB });
packet.write(0xE3);
packet.write(0xE3);
packet.write(0xE3);
return packet.toString();
}
}
Dies ist eine sehr vereinfachte Version, ich hab das Paket schon vor langer Zeit inkl. aller Komponenten analysiert. Für Anfänger dürfte das aber uninteressant sein, deshalb diese einfache Version. Fortgeschrittene können ja mal versuchen die Komponenten selbst zu analysieren, oder es aus dem Banana-Chat extrahieren.
Beispiel
groupChat.receive(new Popup("Beispiel", "Popup", "Da ist ein Beispiel für ein Popup.", 400, 300).toString());
Edit: Wenn ich Zeit finde mich da nochmal ranzusetzen werde ich das Ganze auch noch kommentieren, jedes einzelne Byte hat natürlich eine Bedeutung.Geändert von Flav (21.04.2012 um 14:14 Uhr)
-
The Following User Says Thank You to Flav For This Useful Post:
-
21.04.2012, 12:04 #2
AW: [Java] Popup
public Popup(String title, String subtitle, String message, int width, int height, String backgroundImage) {
this.title = title;
this.subtitle = subtitle;
this.message = message;
this.width = width;
this.height = height;
this.background = background;
}
Solltest du anpassen, das this.background = background; ist ein assigning to itsself
Müsste this.background = backgroundImage; sein
-
21.04.2012, 12:21 #3
AW: [Java] Popup
Dann kann man auch gleich background = backgroundImage; schreiben^^
„Es sind nicht unsere Fähigkeiten, die zeigen, wer wir wirklich sind, es sind unsere Entscheidungen.“
- Albus Dumbledore, Harry Potter 2
/guestchat registerGuest
-
21.04.2012, 12:24 #4
AW: [Java] Popup
Wobei this.background = backgroundImage; trotzdem besser wäre. Stilsicherer
-
21.04.2012, 14:14 #5
- Registriert seit
- 06.11.2011
- Beiträge
- 418
Thanked 686 Times in 246 PostsAW: [Java] Popup
Da hab ich mich vertippt, der Parameter sollte background und nicht backgroundImage heißen.
-
21.04.2012, 14:17 #6
AW: [Java] Popup
Naja immerhin berichtigt
Wie man das denn am Ende macht ist ja dann auch egal.
-
27.05.2012, 07:47 #7
AW: [Java] Popup
Wie kann man das verwenden? Ich hatte vor mich ein wenig mit Java zu beschäftigen aber wie verwende ich das, bzw. wo ?
-
27.05.2012, 13:00 #8
AW: [Java] Popup
Kannst du z.B im KRClient verwenden.
while( behappy() ) { code(); }
Ähnliche Themen
-
Win7 Java in Safari ausführen (Fehlermeldung Java nicht installiert)
Von Silverstar im Forum WindowsAntworten: 8Letzter Beitrag: 02.12.2013, 23:41 -
[JS] Knuddels Popup-Parser
Von Bubble Gum im Forum WebentwicklungAntworten: 3Letzter Beitrag: 31.10.2013, 16:44 -
Popup Hindergrundbild
Von uncopyable im Forum Knuddels ProgrammierungAntworten: 6Letzter Beitrag: 17.12.2011, 15:14 -
Schützling annehmen - Popup
Von Devon im Forum Knuddels AllgemeinAntworten: 4Letzter Beitrag: 12.12.2011, 21:51 -
Popup Jugendschutztest 1 und 2
Von AFU im Forum Knuddels AllgemeinAntworten: 0Letzter Beitrag: 11.12.2011, 13:14
Diese Seite nutzt Cookies, um das Nutzererlebnis zu verbessern. Klicken Sie hier, um das Cookie-Tracking zu deaktivieren.