Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import javax.swing.event.DocumentEvent;
- import javax.swing.event.DocumentListener;
- import java.awt.*;
- import java.awt.event.*;
- import java.util.*;
- import java.io.*;
- public class gui extends JFrame implements ActionListener, ItemListener, DocumentListener{
- ArrayList <String> ChordsAL = new ArrayList();
- public gui()
- {
- setTitle("Moosic");
- setSize(500, 500);
- setLocationRelativeTo(null);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- JButton Okay = new JButton("Okay");
- JLabel ChordLabel = new JLabel("Check the chords you would like to randomly generate here: ");
- JCheckBox A = new JCheckBox("A", false);
- JCheckBox B = new JCheckBox("B", false);
- JCheckBox C = new JCheckBox("C", false);
- JCheckBox D = new JCheckBox("D", false);
- JCheckBox E = new JCheckBox("E", false);
- JCheckBox F = new JCheckBox("F", false);
- JCheckBox G = new JCheckBox("G", false);
- JTextArea ChordArea = new JTextArea(8, 40);
- JPanel ChordGenerator = new JPanel();
- JPanel Button = new JPanel();
- JPanel Label = new JPanel();
- GridLayout Grid = new GridLayout(7,1);
- FlowLayout ButLay = new FlowLayout();
- add(Label);
- Label.add(ChordLabel);
- add(ChordGenerator);
- setLayout(Grid);
- ChordGenerator.add(A);
- A.addItemListener(this);
- ChordGenerator.add(B);
- B.addItemListener(this);
- ChordGenerator.add(C);
- C.addItemListener(this);
- ChordGenerator.add(D);
- D.addItemListener(this);
- ChordGenerator.add(E);
- E.addItemListener(this);
- ChordGenerator.add(F);
- F.addItemListener(this);
- ChordGenerator.add(G);
- G.addItemListener(this);
- setLayout(ButLay);
- add(Okay);
- Okay.addActionListener(this);
- add(ChordArea);
- ChordArea.setText("kjsf;lkasdjf;lkasdjf;lkadjf;laksdjf;laskdjf;laksdjf;lkashflkjndlknb dfkjvhbajfhasdfhaosdijfoasihfkjshgouhg");
- ChordArea.setEditable(false);
- ChordArea.setLineWrap(true);
- setVisible(true);
- }
- public void itemStateChanged(ItemEvent evt)
- {
- if(evt.getItemSelectable() instanceof JCheckBox)
- {
- JCheckBox Temp = (JCheckBox)evt.getItemSelectable();
- if(evt.getStateChange() == ItemEvent.SELECTED)
- {
- ChordsAL.add(Temp.getText());
- }
- if(evt.getStateChange() == ItemEvent.DESELECTED)
- {
- ChordsAL.remove(Temp.getText());
- }
- //System.out.print(" " + ChordsAL);
- }
- }
- public void actionPerformed(ActionEvent event)
- {
- String command = event.getActionCommand();
- if(command.equals("Okay"))
- {
- String Amount = JOptionPane.showInputDialog("How many chords would you like to generate? ");
- int AmountInt = Integer.parseInt(Amount);
- int Counter = 0;
- while(Counter < AmountInt)
- {
- int Rand = (int)((Math.random() * ChordsAL.size()));
- String Chord = ChordsAL.get(Rand);
- Counter++;
- }
- }
- }
- public void changedUpdate(DocumentEvent evt)
- {
- }
- public void insertUpdate(DocumentEvent evt)
- {
- }
- public void removeUpdate(DocumentEvent evt)
- {
- }
- public static void main(String[] args)
- {
- gui ShowGUI = new gui();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement