Herzlich Willkommen

Live processing contents

Friday, November 5, 2010

CASCADING WINDOWS 3 GUI JAVA

GUI JAVA  CASCADING WINDOWS & BLINKING  FRAME
@uthor   :  AGINTA GENIUSA

import java.awt.Color;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
//import java.util.Timer;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.Timer;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GUIginta.java
 *
 * Created on 04 Nov 10, 5:23:11
 */
/**
 *
 * @author potatosalad
 */
public class GUIginta extends javax.swing.JFrame {

    /** Creates new form GUIginta */
    Timer blinkTimer = new Timer(100, new Blinker());
    Timer blinkTimer2 = new Timer(100, new Blinker2());
    Timer blinkTimer3 = new Timer(100, new Blinker3());
    Timer blinkTimer4 = new Timer(100, new Blinker4());
    //int counter = 1,kedipan=0;
    //tiga []anak = new tiga[50];
    int id = -1;
    //public static JFrame baru;
    tiga []FrGinta = new tiga[50];

    public GUIginta() {
        initComponents();
    }

    class Blinker implements ActionListener {

        boolean on = false;

        public void actionPerformed(ActionEvent e) {
            // blink the button background on and off
            jButton1.setBackground(on ? Color.ORANGE : null);
            on = !on;
        }
    }

    class Blinker2 implements ActionListener {

        boolean on = false;

        public void actionPerformed(ActionEvent e) {
            // blink the label background on and off
            jButton2.setBackground(on ? Color.cyan : null);
            on = !on;
        }
    }

    class Blinker3 implements ActionListener {

        boolean on = false;

        public void actionPerformed(ActionEvent e) {
            // blink the label background on and off
            jButton3.setBackground(on ? Color.pink : null);
            on = !on;
        }
    }

    class Blinker4 implements ActionListener {

        boolean on = false;

        public void actionPerformed(ActionEvent e) {
            // blink the label background on and off
            jButton4.setBackground(on ? Color.magenta : null);
            on = !on;
        }
    }



    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                         
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(102, 153, 255));
        setForeground(new java.awt.Color(102, 102, 255));

        jButton1.setBackground(new java.awt.Color(102, 255, 102));
        jButton1.setFont(new java.awt.Font("Khmer UI", 1, 12)); // NOI18N
        jButton1.setForeground(new java.awt.Color(255, 255, 51));
        jButton1.setText("Buka Jendela Baru");
        jButton1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jButton1.setDebugGraphicsOptions(javax.swing.DebugGraphics.NONE_OPTION);
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jButton1MouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jButton1MouseExited(evt);
            }
        });
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setBackground(new java.awt.Color(0, 51, 255));
        jButton2.setFont(new java.awt.Font("Tempus Sans ITC", 0, 12)); // NOI18N
        jButton2.setForeground(new java.awt.Color(255, 51, 51));
        jButton2.setText("Tutup Jendela");
        jButton2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, null, new java.awt.Color(255, 204, 0), null, null));
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jButton2MouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jButton2MouseExited(evt);
            }
        });
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setBackground(new java.awt.Color(255, 51, 0));
        jButton3.setFont(new java.awt.Font("Trebuchet MS", 1, 11)); // NOI18N
        jButton3.setForeground(new java.awt.Color(102, 0, 102));
        jButton3.setText("Interaksi Jendela");
        jButton3.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jButton3MouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jButton3MouseExited(evt);
            }
        });
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setBackground(new java.awt.Color(255, 0, 0));
        jButton4.setFont(new java.awt.Font("Mongolian Baiti", 0, 18)); // NOI18N
        jButton4.setForeground(new java.awt.Color(255, 255, 255));
        jButton4.setText("Keluar");
        jButton4.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED, new java.awt.Color(255, 51, 0), new java.awt.Color(255, 0, 0), null, new java.awt.Color(255, 255, 51)));
        jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jButton4MouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jButton4MouseExited(evt);
            }
        });
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(17, 17, 17)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(24, 24, 24)
                .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 106, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(84, 84, 84))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(392, Short.MAX_VALUE)
                .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(77, 77, 77)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 115, Short.MAX_VALUE)
                .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>                       

    private void jButton1MouseEntered(java.awt.event.MouseEvent evt) {                                     
        // TODO add your handling code here:

        blinkTimer.start();
    }                                    

    private void jButton1MouseExited(java.awt.event.MouseEvent evt) {                                    
        // TODO add your handling code here:
        blinkTimer.stop();
        jButton1.setBackground(Color.cyan);
    }                                   

    private void jButton2MouseEntered(java.awt.event.MouseEvent evt) {                                     
        // TODO add your handling code here:
        blinkTimer2.start();

    }                                    

    private void jButton3MouseEntered(java.awt.event.MouseEvent evt) {                                     
        // TODO add your handling code here:
        blinkTimer3.start();

    }                                    

    private void jButton4MouseEntered(java.awt.event.MouseEvent evt) {                                     
        // TODO add your handling code here:
        blinkTimer4.start();
jButton4.setBackground(Color.WHITE);
    }                                    

    private void jButton2MouseExited(java.awt.event.MouseEvent evt) {                                    
        // TODO add your handling code here:
        blinkTimer2.stop();
        jButton2.setBackground(Color.pink);
    }                                   

    private void jButton3MouseExited(java.awt.event.MouseEvent evt) {                                    
        // TODO add your handling code here:
        blinkTimer3.stop();
        jButton3.setBackground(Color.YELLOW);
    }                                   

    private void jButton4MouseExited(java.awt.event.MouseEvent evt) {                                    
        // TODO add your handling code here:
        blinkTimer4.stop();
        jButton4.setBackground(Color.blue);
    }                                   

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        System.exit(0);
    }                                       

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:

        if(id<49){
            id++;
           FrGinta[id]=new tiga();
           FrGinta[id].setVisible(true);
        }
       



    }                                       

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        if (id!=-1){
            for (int i=0;i<=id;i++){
                FrGinta[i].dispose();
            }
            id=-1;
        }

    }                                       

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
//        for(int j=0;j<=id;j++){
//            if(kedipan==0){
//                kedipan++;
//                FrGinta[j].kedip();
//            }else {
//                FrGinta[j].takkedip();
//                kedipan--;
//            }
//        }
        if (id!=-1){
            for (int i=0;i<=id;i++){
                FrGinta[i].setLocation(i*40, i*45);
                FrGinta[i].dokedip(id);
            }
        }
    }                                       

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new GUIginta().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                    
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    // End of variables declaration                  
}











+ MAKES UR OWN JBUTTON ?



>> DESIGN



NEXT RUN >


~ FIN~

No comments:

Post a Comment