Chords Pad GUI - 我希望能够存储三和弦,当我点击一个打击垫时,它会演奏和弦

时间:2017-04-27 14:43:08

标签: java maxmsp

import com.cycling74.max.*;
import javax.swing. *;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;

这是为了以后的代码创建gui

public class coursework3d extends MaxObject
{
    private program1 win;

    private static final String[] INLET_ASSIST = new String[]{
        "inlet 1 help"
    };
    private static final String[] OUTLET_ASSIST = new String[]{
        "outlet 1 help"
    };

    public coursework3d(Atom[] args)
    {
        declareInlets(new int[]{DataTypes.ALL,DataTypes.ALL});
        declareOutlets(new int[]{DataTypes.ALL,DataTypes.ALL,DataTypes.ALL,DataTypes.ALL});

        setInletAssist(INLET_ASSIST);
        setOutletAssist(OUTLET_ASSIST);

        win = new program1(this);
        win.setVisible (true);


    }

    public void bang()
    {
        int Cmajor[] = {0, 2,  4};
        int CSmajor[] = {1, 5, 8};
        int Dmajor[] = {2, 6, 9};
        int EFmajor[] = {3, 7, 10};
        int Emajor[] = {4, 8, 11};
        int Fmajor[] = {5, 9, 12};
        int FSmajor[] = {6, 8, 13};
        int Gmajor[] = {7, 11, 14};
        int AFmajor[] = {8, 12, 15};
        int Amajor[] = {9, 13, 16};
        int BFmajor[] = {10, 14, 17};
        int Bmajor[] = {11,  15, 18};
    }

    public void inlet(int i)
    {
    }


}

gui框架包含所有面板和jbuttons

class program1 extends JFrame 
{
    private int width = 1250;
    private int height = 200;
    private int x = 60;
    private int y = 60;

    private JButton CMAJOR;
    private JButton CSHARPMAJOR;
    private JButton DMAJOR; 
    private JButton EFLATMAJOR;
    private JButton EMAJOR;
    private JButton FMAJOR;
    private JButton FSHARPMAJOR;
    private JButton GMAJOR;
    private JButton AFLATMAJOR; 
    private JButton AMAJOR;
    private JButton BFLATMAJOR;
    private JButton BMAJOR;

    private JPanel P1;// Panel for title
    private JPanel P2;// Panel for buttons
    private JPanel P3;// Panel for sliders

    private JLabel J1;
    private JLabel J2;
    private JLabel J3;
    private JLabel J4;
    private JLabel J5;

    private MaxObject mobject;

    public program1(MaxObject mob)
    {
        mobject = mob;

        setTitle (" ChordPad " );
        setBounds ( x, y, width, height );
        setLayout ( new BorderLayout() );

    //TOP

        P1 = new JPanel();

        //P1.setBackground ( Color.BLACK );

        P1.setLayout ( new BorderLayout() );

        add( P1, BorderLayout.NORTH);

        J5 = new JLabel (" Chord Pads");

        J5.setFont(new Font("Avenir", Font.PLAIN, 40));

        J5.setForeground(Color.WHITE);

        P1.add (J5, BorderLayout.NORTH);



    //MIDDLE

         P2 = new JPanel();
         P2.setBackground ( Color.BLACK);
         P2.setLayout ( new GridLayout( 1 , 1 ));
         add( P2, BorderLayout.CENTER );

         CMAJOR = new JButton( "CMajor" );
         P2.add( CMAJOR );

         CSHARPMAJOR = new JButton( "C\u266FMajor" );
         P2.add( CSHARPMAJOR );


         DMAJOR = new JButton( "DMajor " );         
         P2.add( DMAJOR );


         EFLATMAJOR = new JButton( "E\u266DMajor" );
         P2.add( EFLATMAJOR );


         EMAJOR = new JButton( "EMajor)" );
         P2.add( EMAJOR );


         FMAJOR = new JButton( "FMajor " );
         P2.add( FMAJOR );


         FSHARPMAJOR = new JButton( "F\u266FMajor" );
         P2.add( FSHARPMAJOR );


         GMAJOR = new JButton( "GMajor" );
         P2.add( GMAJOR );


         AFLATMAJOR = new JButton( "A\u266DMajor" );
         P2.add( AFLATMAJOR );


         AMAJOR = new JButton( "AMajor" );
         P2.add( AMAJOR );


         BFLATMAJOR = new JButton( "B\u266DMajor" );
         P2.add( BFLATMAJOR );

         BMAJOR = new JButton( "BMajor" );
         P2.add( BMAJOR );

        Action Listener for each chord

返回动作监听器,使其发送回最大对象,通过爆炸发挥每个和弦

        CMAJOR.addActionListener( 
            new ActionListener()
            {
                public void actionPerformed ( ActionEvent aent )
                {
                    CMAJOR();
                }
            }
         );
        CSHARPMAJOR.addActionListener( new ActionListener()
            {
                public void actionPerformed ( ActionEvent aent )
                {
                    CSHARPMAJOR();
                }
            } );

        DMAJOR.addActionListener(   new ActionListener()
            {
                public void actionPerformed ( ActionEvent aent )
                {
                    DMAJOR();

                }
            } );

        EFLATMAJOR.addActionListener(   new ActionListener()
            {
                public void actionPerformed ( ActionEvent aent )
                {
                    EFLATMAJOR();

                }
            } );

        EMAJOR.addActionListener(   new ActionListener()
            {
                public void actionPerformed ( ActionEvent aent )
                {
                    EMAJOR();

                }
            } );

        FSHARPMAJOR.addActionListener(  new ActionListener()
            {
                public void actionPerformed ( ActionEvent aent )
                {
                    FSHARPMAJOR();

                }
            } 
         );

        GMAJOR.addActionListener( 
            new ActionListener()
            {
                public void actionPerformed ( ActionEvent aent )
                {
                    GMAJOR();
                }
            }
         );

        AFLATMAJOR.addActionListener( 
            new ActionListener()
            {
                public void actionPerformed ( ActionEvent aent )
                {
                    AFLATMAJOR();
                }
            }
         );

        AMAJOR.addActionListener( 
            new ActionListener()
            {
                public void actionPerformed ( ActionEvent aent )
                {
                    AMAJOR();
                }
            }
         );

        BFLATMAJOR.addActionListener( 
            new ActionListener()
            {
                public void actionPerformed ( ActionEvent aent )
                {
                    BFLATMAJOR();
                }
            }
         );

        BMAJOR.addActionListener( 
            new ActionListener()
            {
                public void actionPerformed ( ActionEvent aent )
                {
                    BMAJOR();
                }
            }
         );
        }



        public void CMAJOR()
        {
        System.out.println ("CMAJOR");
        mobject.outletBang(1);
        }

        private void CSHARPMAJOR()
        {
        System.out.println ("CSHARPMAJOR");
        mobject.outletBang(2);
        }

        private void DMAJOR()
        {
        System.out.println ("DMAJOR");
        mobject.outletBang(3);
        }

        private void EFLATMAJOR()
        {
        System.out.println ("EFLATMAJOR");
        mobject.outletBang(4);
        }

        private void EMAJOR()
        {
        System.out.println ("EMAJOR");
        mobject.outletBang(5);
        }

        private void FMAJOR()
        {
        System.out.println ("FSHARPMAJOR");
        mobject.outletBang(6);
        }

        private void FSHARPMAJOR()
        {
        System.out.println ("FSHARPMAJOR");
        mobject.outletBang(7);
        }

        private void GMAJOR()
        {
        System.out.println ("GMAJOR");
        mobject.outletBang(8);
        }

        private void AFLATMAJOR()
        {
        System.out.println ("AFLATMAJOR");
        mobject.outletBang(9);
        }

        private void AMAJOR()
        {
        System.out.println ("AMAJOR");
        mobject.outletBang(10);
        }

        private void BFLATMAJOR()
        {
        System.out.println ("BFLATMAJOR");
        mobject.outletBang(11);
        }

        private void BMAJOR()
        {
        System.out.println ("BMAJOR");
        mobject.outletBang(12);
        }



}
`

0 个答案:

没有答案