⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 colorselect.java

📁 Java 小游戏TetraSquare
💻 JAVA
字号:
/*
 * ColorSelect.java
 *
 * Created on 2007年4月28日, 下午1:05
 */

package tetrasquare;

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;

/**
 *
 * @author  Caviar
 */
public class ColorSelect extends javax.swing.JPanel {
    
    /** Creates new form ColorSelect */
    public ColorSelect(mainFrame frm) {
        this.frm=frm;
        initComponents();
        init();
    }
    
    private void init(){
       jPanel1.setBackground(frm.a[0][0].red);
       jPanel2.setBackground(frm.a[0][0].blue);
       for (int i = 0; i < 8; i++) {//让棋盘上即时反应
           for (int j = 0; j < 8; j++) {
               frm.a[i][j].repaint();
               
           }
       }
       for (int i = 0; i < 5; i++) {
           for (int j = 0; j < 5; j++) {
               frm.b[i][j].repaint();
           }
           
       }
    }
    /** 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.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jColorChooser1 = new javax.swing.JColorChooser();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        redChess = new javax.swing.JButton();
        blueChess = new javax.swing.JButton();
        setDefault = new javax.swing.JButton();

        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jPanel2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        redChess.setText("\u8bbe\u7f6e\u5b9e\u5fc3\u5706\u989c\u8272");
        redChess.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                redChessActionPerformed(evt);
            }
        });

        blueChess.setText("\u8bbe\u7f6e\u91cd\u5fc3\u5706\u989c\u8272");
        blueChess.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                blueChessActionPerformed(evt);
            }
        });

        setDefault.setText("\u91cd\u7f6e\u4e3a\u9ed8\u8ba4\u8bbe\u7f6e");
        setDefault.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                setDefaultActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jColorChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(redChess)
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(setDefault)
                                    .addComponent(blueChess)))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(25, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jColorChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(redChess)
                .addGap(32, 32, 32)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(37, 37, 37)
                .addComponent(blueChess)
                .addGap(24, 24, 24)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(16, 16, 16)
                .addComponent(setDefault))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void setDefaultActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_setDefaultActionPerformed
// TODO add your handling code here:
        Color red=new Color(174,0,15);
        Color blue = new Color(36,0,170);
         for(int i=0;i<8;i++)
              for(int j=0;j<8;j++){
                   frm.a[i][j].blue=blue;
                  }
         for(int i=0;i<5;i++)
              for(int j=0;j<5;j++)
                  frm.b[i][j].blue=blue;
                for(int i=0;i<8;i++)
              for(int j=0;j<8;j++){
                    frm.a[i][j].red=red;
              }
        for(int i=0;i<5;i++)
              for(int j=0;j<5;j++)
                  frm.b[i][j].red=red;    
        init();
       
    }//GEN-LAST:event_setDefaultActionPerformed

    private void blueChessActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_blueChessActionPerformed
// TODO add your handling code here:

        Color c=jColorChooser1.getColor();    

        for(int i=0;i<8;i++)
              for(int j=0;j<8;j++){
                   frm.a[i][j].blue=c;
                  }
         for(int i=0;i<5;i++)
              for(int j=0;j<5;j++)
                  frm.b[i][j].blue=c;       
                init();
    }//GEN-LAST:event_blueChessActionPerformed

    private void redChessActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_redChessActionPerformed
// TODO add your handling code here:
 
       Color c=jColorChooser1.getColor();
       
       
        for(int i=0;i<8;i++)
              for(int j=0;j<8;j++){
                    frm.a[i][j].red=c;
              }
        for(int i=0;i<5;i++)
              for(int j=0;j<5;j++)
                  frm.b[i][j].red=c;    
                        init(); 
    }//GEN-LAST:event_redChessActionPerformed

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton blueChess;
    private javax.swing.JColorChooser jColorChooser1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JButton redChess;
    private javax.swing.JButton setDefault;
    // End of variables declaration//GEN-END:variables
    public JPanel red=new JPanel();
    public JPanel blue=new JPanel();
    mainFrame frm;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -