示例#1
0
 private static JRadioButtonMenuItem createLookAndFeelItem(
     String lafName, String lafClassName, final ButtonGroup lookAndFeelRadioGroup) {
   JRadioButtonMenuItem lafItem = new JRadioButtonMenuItem();
   lafItem.setSelected(lafClassName.equals(lookAndFeel));
   lafItem.setHideActionText(true);
   lafItem.setAction(
       new AbstractAction() {
         @Override
         public void actionPerformed(ActionEvent e) {
           ButtonModel m = lookAndFeelRadioGroup.getSelection();
           try {
             setLookAndFeel(m.getActionCommand());
           } catch (ClassNotFoundException
               | InstantiationException
               | IllegalAccessException
               | UnsupportedLookAndFeelException ex) {
             ex.printStackTrace();
           }
         }
       });
   lafItem.setText(lafName);
   lafItem.setActionCommand(lafClassName);
   lookAndFeelRadioGroup.add(lafItem);
   return lafItem;
 }
示例#2
0
  // Public constructor
  public ElectronicOrganFrame(String title) {
    // Call parent constructor to give title to frame
    super(title);

    // Make this frame its own window listener
    addWindowListener(windowListener);

    // Panel components: waveformPanel
    waveformPanel.setBorder(
        new TitledBorder(new BevelBorder(BevelBorder.RAISED), "Waveform Options"));
    GridBagLayout waveformPanelGridBag = new GridBagLayout();
    GridBagConstraints waveformPanelConstr = new GridBagConstraints();
    waveformPanel.setLayout(waveformPanelGridBag);
    waveformPanelConstr.anchor = GridBagConstraints.CENTER;
    waveformPanelConstr.weightx = 1.0;
    waveformPanelConstr.weighty = 1.0;
    waveformPanelConstr.fill = GridBagConstraints.BOTH;
    waveformPanelConstr.gridx = 0;
    waveformPanelConstr.gridy = 0;
    waveformPanelConstr.gridwidth = 1;
    waveformPanelConstr.gridheight = 1;
    waveformPanelGridBag.setConstraints(sineButton, waveformPanelConstr);
    waveformPanel.add(sineButton);
    waveformPanelRadio.add(sineButton);
    sineButton.addActionListener(actionListener);
    waveformPanelConstr.gridx = 1;
    waveformPanelConstr.gridy = 0;
    waveformPanelConstr.gridwidth = 1;
    waveformPanelConstr.gridheight = 1;
    waveformPanelGridBag.setConstraints(squareButton, waveformPanelConstr);
    waveformPanel.add(squareButton);
    waveformPanelRadio.add(squareButton);
    squareButton.addActionListener(actionListener);
    waveformPanelConstr.gridx = 2;
    waveformPanelConstr.gridy = 0;
    waveformPanelConstr.gridwidth = 1;
    waveformPanelConstr.gridheight = 1;
    waveformPanelGridBag.setConstraints(sawtoothButton, waveformPanelConstr);
    waveformPanel.add(sawtoothButton);
    waveformPanelRadio.add(sawtoothButton);
    sawtoothButton.addActionListener(actionListener);
    waveformPanelConstr.gridx = 3;
    waveformPanelConstr.gridy = 0;
    waveformPanelConstr.gridwidth = 1;
    waveformPanelConstr.gridheight = 1;
    waveformPanelGridBag.setConstraints(triangleButton, waveformPanelConstr);
    waveformPanel.add(triangleButton);
    waveformPanelRadio.add(triangleButton);
    triangleButton.addActionListener(actionListener);

    // Panel components: exitPanel
    exitPanel.setLayout(new GridLayout(1, 5));
    exitPanel.add(label1);
    exitPanel.add(label2);
    exitPanel.add(exitButton);
    exitButton.addActionListener(actionListener);
    exitPanel.add(label3);
    exitPanel.add(label4);
    GridBagLayout thisGridBag = new GridBagLayout();
    GridBagConstraints thisConstr = new GridBagConstraints();
    this.getContentPane().setLayout(thisGridBag);
    thisConstr.anchor = GridBagConstraints.CENTER;
    thisConstr.weightx = 1.0;
    thisConstr.weighty = 1.0;
    thisConstr.fill = GridBagConstraints.BOTH;
    thisConstr.gridx = 0;
    thisConstr.gridy = 0;
    thisConstr.gridwidth = 3;
    thisConstr.gridheight = 1;
    thisGridBag.setConstraints(label5, thisConstr);
    this.getContentPane().add(label5);
    thisConstr.gridx = 0;
    thisConstr.gridy = 1;
    thisConstr.gridwidth = 1;
    thisConstr.gridheight = 1;
    thisGridBag.setConstraints(label6, thisConstr);
    this.getContentPane().add(label6);
    thisConstr.gridx = 1;
    thisConstr.gridy = 1;
    thisConstr.gridwidth = 1;
    thisConstr.gridheight = 1;
    thisGridBag.setConstraints(waveformPanel, thisConstr);
    this.getContentPane().add(waveformPanel);
    thisConstr.gridx = 2;
    thisConstr.gridy = 1;
    thisConstr.gridwidth = 1;
    thisConstr.gridheight = 1;
    thisGridBag.setConstraints(label7, thisConstr);
    this.getContentPane().add(label7);
    thisConstr.gridx = 1;
    thisConstr.gridy = 2;
    thisConstr.gridwidth = 1;
    thisConstr.gridheight = 1;
    thisGridBag.setConstraints(exitPanel, thisConstr);
    this.getContentPane().add(exitPanel);

    // Set frame size and show it
    setSize(500, 200);
    setVisible(true);
  } // Frame constructor ElectronicOrganFrame ()