Created
September 22, 2011 13:18
-
-
Save khannedy/1234743 to your computer and use it in GitHub Desktop.
JLayer Demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| PanelMahasiswa panelMahasiswa = new PanelMahasiswa(); | |
| LayerUI<PanelMahasiswa> layerUI = new MyLayer(); | |
| JLayer<PanelMahasiswa> jLayer = new JLayer<PanelMahasiswa>(panelMahasiswa, layerUI); | |
| getContentPane().add(jLayer); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Copyright (c) 2011, StripBandunk and/or its affiliates. All rights reserved. | |
| * | |
| * http://stripbandunk.com/ | |
| * | |
| * STRIPBANDUNK PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. | |
| */ | |
| package com.stripbandunk.tutorial.jlayerdemo; | |
| import java.awt.AlphaComposite; | |
| import java.awt.Color; | |
| import java.awt.Graphics; | |
| import java.awt.Graphics2D; | |
| import javax.swing.JComponent; | |
| import javax.swing.plaf.LayerUI; | |
| /** | |
| * | |
| * @author Eko Kurniawan Khannedy | |
| */ | |
| public class MyLayer extends LayerUI<PanelMahasiswa> { | |
| private static final long serialVersionUID = 1L; | |
| @Override | |
| public void paint(Graphics g, JComponent c) { | |
| super.paint(g, c); | |
| Graphics2D gd = (Graphics2D) g.create(); | |
| gd.setComposite(AlphaComposite.SrcOver.derive(0.5F)); | |
| gd.setColor(Color.YELLOW); | |
| gd.fillRect(0, 0, c.getWidth() / 2, c.getHeight()); | |
| gd.setColor(Color.RED); | |
| gd.fillRect(c.getWidth() / 2, 0, c.getWidth(), c.getHeight()); | |
| gd.dispose(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment