Created
January 3, 2014 02:52
-
-
Save resarahadian/8231766 to your computer and use it in GitHub Desktop.
Membuat Shadow JFrame
This file contains 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
import javax.swing.JPanel; | |
import java.awt.Color; | |
import java.awt.Graphics; | |
import java.awt.Graphics2D; | |
@SuppressWarnings("serial") | |
public class ClPanelTransparan extends JPanel | |
{ | |
private Color clr; | |
public ClPanelTransparan() | |
{ | |
setOpaque(false); | |
clr = new Color(getBackground().getRed(), getBackground().getRed(), getBackground().getGreen(),50); | |
} | |
public void setBackground(Color bg) | |
{ | |
super.setBackground(bg); | |
clr = new Color(getBackground().getRed(), getBackground().getRed(), getBackground().getGreen(),50); | |
repaint(); | |
} | |
protected void paintComponent(Graphics graph) | |
{ | |
super.paintComponent(graph); | |
Graphics2D g2d = (Graphics2D) graph.create(); | |
g2d.setColor(clr); | |
g2d.fillRect(0, 0, getWidth(), getHeight()); | |
g2d.dispose(); | |
} | |
} | |
This file contains 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
import java.awt.Color; | |
import java.awt.EventQueue; | |
import java.awt.Graphics; | |
import javax.swing.JComponent; | |
import javax.swing.JFrame; | |
import javax.swing.JOptionPane; | |
import javax.swing.JPanel; | |
import javax.swing.UIManager; | |
import javax.swing.border.EmptyBorder; | |
import javax.swing.JButton; | |
import java.awt.event.ActionListener; | |
import java.awt.event.ActionEvent; | |
import javax.swing.JLabel; | |
import javax.swing.JTextField; | |
import javax.swing.ImageIcon; | |
import java.awt.Font; | |
@SuppressWarnings("serial") | |
public class shadowJFrame extends JFrame | |
{ | |
private JPanel contentPane; | |
private JButton btnSimpan; | |
private JLabel lblId; | |
private JTextField txtID; | |
private JTextField txtJudul; | |
private JLabel lblJudul; | |
private JTextField txtStock; | |
private JButton btnUbah; | |
private JPanel panel; | |
private JLabel lblWall; | |
private JLabel lblIcon; | |
/** | |
* Create the frame. | |
*/ | |
public shadowJFrame() | |
{ | |
setTitle("Shadow Frame"); | |
setResizable(false); | |
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
setBounds(100, 100, 665, 380); | |
contentPane = new JPanel(); | |
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); | |
setContentPane(contentPane); | |
contentPane.setLayout(null); | |
btnSimpan = new ClButtonTransparan("Simpan"); | |
btnSimpan.setIcon(new ImageIcon(shadowJFrame.class.getResource("/shadowFrame/simpan.png"))); | |
btnSimpan.addActionListener(new ActionListener() | |
{ | |
public void actionPerformed(ActionEvent act) | |
{ | |
getRootPane().getGlassPane().setVisible(true); | |
JOptionPane.showMessageDialog(shadowJFrame.this, "Data berhasil Disimpan","Pesan",JOptionPane.INFORMATION_MESSAGE, new ImageIcon(("src/shadowFrame/popSimpan.png"))); | |
getRootPane().getGlassPane().setVisible(false); | |
} | |
}); | |
btnSimpan.setBounds(131, 258, 122, 51); | |
contentPane.add(btnSimpan); | |
btnUbah = new ClButtonTransparan("Ubah"); | |
btnUbah.setIcon(new ImageIcon(shadowJFrame.class.getResource("/shadowFrame/ubah.png"))); | |
btnUbah.addActionListener(new ActionListener() | |
{ | |
public void actionPerformed(ActionEvent act) | |
{ | |
getRootPane().getGlassPane().setVisible(true); | |
JOptionPane.showMessageDialog(shadowJFrame.this, "Data berhasil Diubah","Pesan",JOptionPane.INFORMATION_MESSAGE, new ImageIcon(("src/shadowFrame/popUpdate.png"))); | |
getRootPane().getGlassPane().setVisible(false); | |
} | |
}); | |
btnUbah.setBounds(323, 258, 129, 51); | |
contentPane.add(btnUbah); | |
panel = new ClPanelTransparan(); | |
panel.setBounds(131, 19, 377, 215); | |
contentPane.add(panel); | |
panel.setLayout(null); | |
txtID = new JTextField(); | |
txtID.setBounds(84, 20, 122, 27); | |
panel.add(txtID); | |
txtID.setColumns(10); | |
lblId = new JLabel("ID : "); | |
lblId.setFont(new Font("Comic Sans MS", Font.BOLD, 12)); | |
lblId.setForeground(new Color(255, 255, 255)); | |
lblId.setBounds(6, 26, 60, 15); | |
panel.add(lblId); | |
lblJudul = new JLabel("Judul : "); | |
lblJudul.setFont(new Font("Comic Sans MS", Font.BOLD, 12)); | |
lblJudul.setForeground(new Color(255, 255, 255)); | |
lblJudul.setBounds(6, 71, 60, 15); | |
panel.add(lblJudul); | |
txtJudul = new JTextField(); | |
txtJudul.setBounds(84, 65, 281, 27); | |
panel.add(txtJudul); | |
txtJudul.setColumns(10); | |
JLabel lblStock = new JLabel("Stock : "); | |
lblStock.setFont(new Font("Comic Sans MS", Font.BOLD, 12)); | |
lblStock.setForeground(new Color(255, 255, 255)); | |
lblStock.setBounds(6, 120, 60, 15); | |
panel.add(lblStock); | |
txtStock = new JTextField(); | |
txtStock.setBounds(84, 114, 122, 27); | |
panel.add(txtStock); | |
txtStock.setColumns(10); | |
lblIcon = new JLabel(""); | |
lblIcon.setIcon(new ImageIcon(shadowJFrame.class.getResource("/shadowFrame/icon.png"))); | |
lblIcon.setBounds(520, 206, 137, 141); | |
contentPane.add(lblIcon); | |
lblWall = new JLabel(""); | |
lblWall.setIcon(new ImageIcon(shadowJFrame.class.getResource("/shadowFrame/wall.jpg"))); | |
lblWall.setBounds(0, -15, 663, 368); | |
contentPane.add(lblWall); | |
setLocationRelativeTo(null); | |
getRootPane().setGlassPane(new JComponent() | |
{ | |
public void paintComponent(Graphics g) | |
{ | |
g.setColor(new Color(0, 0, 0, 100)); | |
g.fillRect(0, 0, getWidth(), getHeight()); | |
super.paintComponent(g); | |
} | |
}); | |
} | |
/** | |
* Launch the application. | |
*/ | |
public static void main(String[] args) { | |
EventQueue.invokeLater(new Runnable() { | |
public void run() { | |
try { | |
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); | |
shadowJFrame frame = new shadowJFrame(); | |
frame.setVisible(true); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment