Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
  public PuzzelHA() {

    window = new JFrame("PuzzelHA");
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    // window.setSize(800, 600);

    // -----------------Menü erstellen---------------------------------------
    JMenuBar menu = new JMenuBar();
    menu.setBorder(new LineBorder(Color.BLACK, 1));

    JMenu spiel = new JMenu("Spiel");
    JMenuItem reset = new JMenuItem("Reset");
    reset.addActionListener(this);
    reset.setActionCommand("reset");
    spiel.add(reset);

    JMenu ansicht = new JMenu("Ansicht");
    JMenu bild = new JMenu("BildNr.");
    ansicht.add(bild);
    ButtonGroup bg1 = new ButtonGroup();

    for (int j = 1; j <= bilder.size(); j++) {
      JRadioButtonMenuItem bn = new JRadioButtonMenuItem("" + j);
      bn.setName("" + j);
      bn.setActionCommand("b");
      bn.addActionListener(this);
      bg1.add(bn);
      bild.add(bn);
    }

    // --------------RadioButtons für Puzzelgröße----------------------------------
    JMenu pg = new JMenu("Puzzelgröße");
    ansicht.add(pg);
    ButtonGroup bg2 = new ButtonGroup();
    JRadioButtonMenuItem pgb1 = new JRadioButtonMenuItem("2x3");
    pgb1.setActionCommand("g1");
    pgb1.addActionListener(this);
    bg2.add(pgb1);
    pg.add(pgb1);

    for (int i = 2; i <= 4; i++) {
      JRadioButtonMenuItem pgb = new JRadioButtonMenuItem("" + (i * 2) + "x" + (i * 2 - 1));
      pgb.setActionCommand("g" + i);
      pgb.addActionListener(this);
      bg2.add(pgb);
      pg.add(pgb);
    }

    JMenu help = new JMenu("?");
    JMenuItem info = new JMenuItem("Info");
    info.addActionListener(this);
    info.setActionCommand("?");
    help.add(info);

    menu.add(spiel);
    menu.add(ansicht);
    menu.add(help);
    window.add(menu);
    window.setJMenuBar(menu);

    // ---------------- Menü END-------------------------------------

    baueButton();

    window.setResizable(false);
    window.setLocationRelativeTo(null);
    window.pack();
    window.setVisible(true);
  }