Esempio n. 1
0
  public ReverseFlashCard() {
    // basic init
    setTitle("WayMemo -Reverse Flash Card Mode");
    this.setSize(800, 600);
    paneCenter = new JPanel(new GridLayout(7, 1));

    add(ln, "North");
    add(paneCenter, "Center");
    add(b2, "West");
    add(bReset, "South");
    add(b1, "East");
    paneCenter.add(l1);
    paneCenter.add(l2);
    paneCenter.add(l3);
    paneCenter.add(l4);
    paneCenter.add(l5);
    paneCenter.add(b3);
    paneCenter.add(pMark);
    pMark.add(bMark);
    pMark.add(bUnMark);
    pMark.add(lt);

    // text area init

    Utility.initTextAreaView(l1);
    Utility.initTextAreaView(l2);
    Utility.initTextAreaView(l3);
    Utility.initTextAreaView(l4);
    Utility.initTextAreaView(l5);

    // action

    //
    Action actionNext =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            num++;
            wordDisplay();
          }
        };
    b1.getInputMap().put(KeyStroke.getKeyStroke("C"), "pressed");
    b1.getActionMap().put("released", actionNext);
    //
    Action actionBack =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            num--;
            wordDisplay();
          }
        };
    b2.getInputMap().put(KeyStroke.getKeyStroke("Z"), "pressed");
    b2.getActionMap().put("released", actionBack);
    //
    Action actionShow =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            l1.setText(dtr[num]);
            l3.setText(d2[num]);
            l4.setText(d3[num]);
            l5.setText(d4[num]);
          }
        };
    b3.getInputMap().put(KeyStroke.getKeyStroke("X"), "pressed");
    b3.getActionMap().put("released", actionShow);
    //
    //
    Action actionMark =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            d1[num] = "[MARKED*]" + d1[num];
            l2.setText(d1[num]);
          }
        };
    bMark.getInputMap().put(KeyStroke.getKeyStroke("S"), "pressed");
    bMark.getActionMap().put("released", actionMark);
    //
    //
    //
    Action actionUnmark =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            d1[num] = od1[num];
            l2.setText(d1[num]);
          }
        };
    bUnMark.getInputMap().put(KeyStroke.getKeyStroke("F2"), "pressed");
    bUnMark.getActionMap().put("released", actionUnmark);
    //
    //
    Action actionReset =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            num = 0;
            wordDisplay();
          }
        };
    bReset.getInputMap().put(KeyStroke.getKeyStroke("r"), "pressed");
    bReset.getActionMap().put("released", actionReset);
    //
    //
    b1.setMnemonic(KeyEvent.VK_C);
    b2.setMnemonic(KeyEvent.VK_Z);
    b3.setMnemonic(KeyEvent.VK_X);
    bMark.setMnemonic(KeyEvent.VK_S);
    bUnMark.setMnemonic(KeyEvent.VK_D);
    bReset.setMnemonic(KeyEvent.VK_R);

    b1.addActionListener(actionNext);
    b2.addActionListener(actionBack);
    b3.addActionListener(actionShow);
    bReset.addActionListener(actionReset);
    bMark.addActionListener(actionMark);
    bUnMark.addActionListener(actionUnmark);
    //
    //
    try {
      this.fileScan(new OpenFileDTR().getPathDTR());
    } catch (IOException e) {
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (InstantiationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (UnsupportedLookAndFeelException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Esempio n. 2
0
  /** creating GUI, partially using parameters from the shape passed in the constructor */
  private void createGUI() {
    // initializing
    JPanel main = new JPanel(new BorderLayout());
    JPanel middle = new JPanel(new GridLayout(6, 1, 10, 10));
    JPanel bottom = new JPanel();
    JLabel manual = new JLabel("Edit the information of your shape:");
    JLabel hrefDesc = new JLabel("Enter the link it should lead to:");
    hrefDesc.setLabelFor(href);
    JLabel titleDesc = new JLabel("Enter the tootlip which should be shown:");
    titleDesc.setLabelFor(title);
    JLabel altDesc = new JLabel("Enter alternative text:");
    altDesc.setLabelFor(alt);
    JButton ok = new JButton("Save");
    JButton cancel = new JButton("Cancel");

    // assembling
    middle.add(hrefDesc, BorderLayout.NORTH);
    middle.add(href, BorderLayout.SOUTH);
    middle.add(altDesc, BorderLayout.NORTH);
    middle.add(alt, BorderLayout.SOUTH);
    middle.add(titleDesc, BorderLayout.NORTH);
    middle.add(title, BorderLayout.SOUTH);
    middle.setBorder(new EmptyBorder(10, 10, 10, 10));
    ok.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            doSave();
          }
        });
    cancel.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            dispose();
          }
        });
    KeyStroke keySave = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
    Action performSave =
        new AbstractAction("Save") {
          private static final long serialVersionUID = 1L;

          public void actionPerformed(ActionEvent e) {
            doSave();
          }
        };
    ok.getActionMap().put("performSave", performSave);
    ok.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keySave, "performSave");

    KeyStroke keyExit = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
    Action performExit =
        new AbstractAction("Exit") {
          private static final long serialVersionUID = 1L;

          public void actionPerformed(ActionEvent e) {
            dispose();
          }
        };
    cancel.getActionMap().put("performExit", performExit);
    cancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyExit, "performExit");
    bottom.add(ok);
    bottom.add(cancel);
    main.add(manual, BorderLayout.NORTH);
    main.add(middle, BorderLayout.CENTER);
    main.add(bottom, BorderLayout.SOUTH);
    main.setBorder(new EmptyBorder(10, 10, 10, 10));

    // finalizing
    href.setText(shape.getHref());
    alt.setText(shape.getAlt());
    title.setText(shape.getTooltip());
    this.setSize(300, 400);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    this.setLocation((d.width - this.getSize().width) / 2, (d.height - this.getSize().height) / 2);
    this.add(main);
  }
Esempio n. 3
0
  public JChat() {
    this.setSize(500, 600);
    this.setResizable(false);
    this.setLayout(new BorderLayout());

    JPanel topPanel = new JPanel();
    topPanel.setLayout(new GridLayout(2, 1));

    // set up buttons
    openChat = new JButton("Open to chat");
    openChat.addActionListener(new OpenChat());
    chatWith = new JButton("Chat with");
    chatWith.addActionListener(new ChatWith());
    send = new JButton("send");
    send.addActionListener(new Send());
    send.setEnabled(false);
    InputMap inputMap = send.getInputMap(JButton.WHEN_IN_FOCUSED_WINDOW);
    KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
    inputMap.put(enter, "ENTER");
    send.getActionMap().put("ENTER", new ClickAction(send));

    // set up labels
    pickPort = new JLabel();
    pickPort.setText("Pick your port number:");
    desPort = new JLabel();
    desPort.setText("Or enter a destinaltion port number:");

    // set up text fields
    pickText = new JTextField();
    pickText.setPreferredSize(new Dimension(150, 30));
    desText = new JTextField();
    desText.setPreferredSize(new Dimension(150, 30));
    chatText = new JTextField();
    chatText.setPreferredSize(new Dimension(400, 30));
    chatText.setEnabled(false);

    JPanel top1 = new JPanel();
    top1.add(pickPort);
    top1.add(pickText);
    top1.add(openChat);

    JPanel top2 = new JPanel();
    top2.add(desPort);
    top2.add(desText);
    top2.add(chatWith);

    topPanel.add(top1);
    topPanel.add(top2);

    chatField = new JTextArea();
    chatField.setAutoscrolls(true);
    chatField.setDragEnabled(true);
    chatField.setEditable(false);
    chatField.setAlignmentY(TOP_ALIGNMENT);

    JPanel bottomPanel = new JPanel();
    bottomPanel.add(chatText);
    bottomPanel.add(send);

    this.add(topPanel, BorderLayout.NORTH);
    this.add(chatField, BorderLayout.CENTER);
    this.add(bottomPanel, BorderLayout.SOUTH);

    this.setVisible(true);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }