Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class myjFrame extends JFrame{
- private JLabel lblBg, lblBtn, lblCur;
- private URL UrlImg(String filename)
- {
- URL url_img;
- url_img=Toolkit.getDefaultToolkit().getClass().getResource("/img/"+filename);
- return url_img;
- }
- public myjFrame()
- {
- setCursor(Toolkit.getDefaultToolkit().createCustomCursor(new ImageIcon(UrlImg("cur_empty.png")).getImage(),new Point(0,0),"cursor_default"));
- this.setLayout(new BorderLayout());
- lblBg= new JLabel();
- lblBg.setIcon(new ImageIcon(UrlImg("main_menu_bg.png")));
- lblBg.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
- public void mouseDragged(java.awt.event.MouseEvent evt) {
- cMouseDragged(evt);
- }
- public void mouseMoved(java.awt.event.MouseEvent evt) {
- cMouseMoved(evt);
- }
- });
- this.add(lblBg);
- lblBg.setLayout(null);
- lblBtn= new JLabel();
- lblBtn.setIcon(new ImageIcon(UrlImg("choi.png")));
- lblBtn.setBounds(120, 310, 345, 132);
- lblBtn.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mouseClicked(java.awt.event.MouseEvent evt) {
- lblChoiMouseClicked(evt);
- }
- public void mouseEntered(java.awt.event.MouseEvent evt) {
- lblChoiMouseEntered(evt);
- }
- public void mouseExited(java.awt.event.MouseEvent evt) {
- lblChoiMouseExited(evt);
- }
- });
- lblBg.add(lblBtn);
- lblCur= new JLabel();
- lblCur.setIcon(new ImageIcon(UrlImg("cur_def.png")));
- lblCur.setBounds(200, 200, 155, 155);
- lblCur.setText("");
- lblBg.add(lblCur);
- }
- private void cMouseMoved(java.awt.event.MouseEvent evt) {
- lblBg.add(lblBtn);
- lblCur.setLocation(evt.getX()-40,evt.getY()-40);
- }
- private void cMouseDragged(java.awt.event.MouseEvent evt) {
- lblCur.setLocation(evt.getX()-40,evt.getY()-40);
- }
- private void lblChoiMouseEntered(java.awt.event.MouseEvent evt) {
- lblBtn.setIcon(new ImageIcon(UrlImg("choi_hover.png")));
- }
- private void lblChoiMouseExited(java.awt.event.MouseEvent evt) {
- lblBtn.setIcon(new ImageIcon(UrlImg("choi.png")));
- }
- private void lblChoiMouseClicked(java.awt.event.MouseEvent evt) {
- this.dispose();
- }
- public static void main(String[] args) {
- myjFrame main= new myjFrame();
- main.setBounds(100, 100, 769,892);
- main.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement