Tolong pilih kategori sesuai, jenis posting (pertanyaan atau bukan) dan sertakan tag/topik yang sesuai misal komputer, php, mysql, dll.
Promosi atau posting tidak pada tempatnya akan kami hapus.
Mencantumkan kode program di posting Anda, tolong ikuti aturan yang sesuai, baca http://diskusiweb.com/discussion/39204/aturan-cara-menyisipkan-kode-program-di-diskusiweb

Baca cara posting gambar/image di post Anda: http://www.diskusiweb.com/discussion/47345/cara-menyisipkan-menyertakan-image-pada-posting/p1

maksud dari coding ini apa yah?

package usu.perpustakaan.buku.widget.template;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.border.EmptyBorder;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import usu.perpustakaan.buku.util.StringUtil;
import usu.widget.TextBox;
import usu.widget.text.DefaultDocument;

/**
*
* @author usu
*/
public class TextBoxGlass extends TextBox {

private static final long serialVersionUID = -1;

/**
*
*/
public TextBoxGlass() {
super();
setDocument(new DefaultDocument() {

private static final long serialVersionUID = -1;

@Override
public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
if (StringUtil.containSemiColomn(str)) {
return;
}
super.insertString(offs, str, a);
}
});
setOpaque(false);
setBorder(new EmptyBorder(5, 10, 5, 10));
setHorizontalAlignment(CENTER);
addMouseListener(new MouseAdapter() {

@Override
public void mouseEntered(MouseEvent e) {
setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
}

@Override
public void mouseExited(MouseEvent e) {
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
});

}

@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);

if (isEnabled()) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

Color dark = new Color(1F, 1F, 1F, 0F);
Color light = new Color(1F, 1F, 1F, 0.3F);
GradientPaint paint = new GradientPaint(0, 0, light, 0, getHeight() / 2, dark);
g2.setPaint(paint);
g2.fillRoundRect(0, 0, getWidth(), getHeight(), getHeight(), getHeight());
g2.setColor(Color.BLACK);
g2.drawRoundRect(0, 0, getWidth() - 1, getHeight() - 1, getHeight(), getHeight());

g2.dispose();
} else {
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

Color light = new Color(1F, 1F, 1F, 0.3F);
g2.setColor(light);
g2.fillRoundRect(0, 0, getWidth(), getHeight(), getHeight(), getHeight());
g2.setColor(Color.BLACK);
g2.drawRoundRect(0, 0, getWidth() - 1, getHeight() - 1, getHeight(), getHeight());

g2.dispose();
}
}
}

Tanggapan

  • dimulai dari public"ny itu saya gk ngerti semua..ngeblank..
    kata teman itu buat palette baru...jadi sebuah text field hiasan sendiri..

    ->public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
    if (StringUtil.containSemiColomn(str)
    ->getPredefinedCursor
    ->protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    ->if (isEnabled()) { ////====>> ini koq langsung di "isenabled ya?..emang apany yang di enabled???
    Graphics2D g2 = (Graphics2D) g.create();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    -->Color dark = new Color(1F, 1F, 1F, 0F);
    Color light = new Color(1F, 1F, 1F, 0.3F);//////nah apa maksudnya ini.1F,1F,1F,0.3F kode apaan itu..itu binary kali yah?

    ->GradientPaint paint = new GradientPaint(0, 0, light, 0, getHeight() / 2, dark);
    g2.setPaint(paint);
    g2.fillRoundRect(0, 0, getWidth(), getHeight(), getHeight(), getHeight());
    g2.setColor(Color.BLACK);
    g2.drawRoundRect(0, 0, getWidth() - 1, getHeight() - 1, getHeight(), getHeight());

    yang ini sejenis yang kyk // Dimension dim = ToolKit.getDefaultToolKit().getScreenSize(); gini yah?

    ->setRenderingHint
    -->g2.fillRoundRect(0, 0, getWidth(), getHeight(), getHeight(), getHeight());
    g2.setColor(Color.BLACK);
    g2.drawRoundRect(0, 0, getWidth() - 1, getHeight() - 1, getHeight(), getHeight());

    banyak amet -,-
  • edited April 2013
    Color light = new Color(1F, 1F, 1F, 0.3F);//////nah apa maksudnya ini.1F,1F,1F,0.3F kode apaan itu..itu binary kali yah?

    itu kode untuk color gan :D
    class diatas mrupakn class Graphics2D Java, biasa digunakn untk design antarmuka dn jga bsa dgunakn mmbuat animasi gan. kalau di jelsin panjng pkoknya.
    cba ente tnya sma mbah google tentang Graphics2D
    Java.
    smoga membantu  ;)
Sign In or Register to comment.