hello guys !
hows it going?
hows it going?
now,I want to share awesome articles Java Swing, how to edit JLabel with Icon Reflection effect,
Screenshot
lets Rock and extream !A. create new project and rename EfekLabelicon
B. create new Java Class and rename ClassUtilitas
C. and recreate new Java Class rename to LabelEfek
D. create new JFrame form rename to mainForm
like image structur below
E. type source code below into tab source ClassUtilitas.java
package efeklabelicon;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
/**
*
* @author CodeMaster
*/ // MASUNDUH II
public class ClassUtilitas {
public static final BufferedImage convertToBufferedGambar(Image sumber)
{
int width = sumber.getWidth(null);
int height = sumber.getHeight(null);
BufferedImage destinasi = new BufferedImage(width, height, 2);
Graphics2D g2 = (Graphics2D)destinasi.getGraphics();
g2.drawImage(sumber, 0, 0, null);
g2.dispose();
return destinasi;
}
public static final BufferedImage convertToBufferedGambarRefleksi(BufferedImage sumber){
BufferedImage destinasi = new BufferedImage(sumber.getWidth(),
sumber.getHeight() + sumber.getHeight()/2,2);
Graphics2D g2d = (Graphics2D) destinasi.getGraphics();
g2d.drawImage(sumber, 0, 0,null);
g2d.scale(1.0D, -1.0D);
g2d.drawImage(sumber, 0, -sumber.getHeight()*2,null);
g2d.scale(1.0D, -1.0D);
g2d.translate(0, sumber.getHeight());
g2d.setPaint(new GradientPaint(0.0F, 0.0F, new Color(1.0F, 1.0F, 1.0F, 0.3F),
0.0F, sumber.getHeight()/2,new Color(1.0F, 1.0F, 1.0F,0.0F)));
g2d.setComposite(AlphaComposite.DstIn);
g2d.fillRect(0, 0, sumber.getWidth(), sumber.getHeight());
g2d.dispose();
return destinasi;
}
public static final BufferedImage
convertToBufferedGambarRefleksi(Image sumber)
{
return convertToBufferedGambarRefleksi
(convertToBufferedGambar(sumber));
}
}
F. and retype source code below into Class LabelEfek.java
package efeklabelicon;
import java.awt.image.BufferedImage;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
/**
*
* @author CodeMaster
*/ // MASUNDUH II
public class LabelEfek extends JLabel{
private Icon IkonRefleksi;
public LabelEfek()
{
setIkonRefleksi(null);
}
public Icon getIkonRefleksi() {
return IkonRefleksi;
}
public void setIkonRefleksi(Icon IkonRefleksi)
throws IllegalArgumentException {
if (IkonRefleksi == null) {
firePropertyChange("IkonRefleksi", getIkonRefleksi(), IkonRefleksi);
this.IkonRefleksi = IkonRefleksi;
setIcon(null);
} else {
if (!(IkonRefleksi instanceof ImageIcon)) {
throw new IllegalArgumentException();
}
firePropertyChange("IkonRefleksi",getIkonRefleksi(), IkonRefleksi);
this.IkonRefleksi = IkonRefleksi;
BufferedImage image = ClassUtilitas.convertToBufferedGambarRefleksi
(((ImageIcon)IkonRefleksi).getImage());
setIcon(new ImageIcon(image));
}
}
}
G.Clean and Build or press Shift+F6
H.open or click 2x mainForm.java.
I. and on tab Design, drag and drop Class ClassUtilitas.java and LabelEfek.java into
mainForm.java. like image below !
Screenshot
its easy guys !please write comment and share this !
0 Response to "tutorial java how to edit jlabel with icon reflection effect."
Post a Comment