예제 #1
0
  public void startGui() {
    JTerminalListener listener = new JTerminalListener();

    jFrame = new JFrame("Glowstone");
    jTerminal = new JTerminal();
    jInput =
        new JTextField(80) {
          @Override
          public void setBorder(Border border) {}
        };
    jInput.paint(null);
    jInput.setFont(new Font("Monospaced", Font.PLAIN, 12));
    jInput.setBackground(Color.BLACK);
    jInput.setForeground(Color.WHITE);
    jInput.setMargin(new Insets(0, 0, 0, 0));
    jInput.addKeyListener(listener);

    JLabel caret = new JLabel("> ");
    caret.setFont(new Font("Monospaced", Font.PLAIN, 12));
    caret.setForeground(Color.WHITE);

    JPanel ipanel = new JPanel();
    ipanel.add(caret, BorderLayout.WEST);
    ipanel.add(jInput, BorderLayout.EAST);
    ipanel.setBorder(BorderFactory.createEmptyBorder());
    ipanel.setBackground(Color.BLACK);
    ipanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
    ipanel.setSize(jTerminal.getWidth(), ipanel.getHeight());

    jFrame.getContentPane().add(jTerminal, BorderLayout.NORTH);
    jFrame.getContentPane().add(ipanel, BorderLayout.SOUTH);
    jFrame.addWindowListener(listener);
    jFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    jFrame.setLocationRelativeTo(null);
    jFrame.pack();
    jFrame.setVisible(true);

    sender = new ColoredCommandSender();
    logger.removeHandler(consoleHandler);
    logger.addHandler(
        new StreamHandler(new TerminalOutputStream(), new DateOutputFormatter(CONSOLE_DATE)));
  }
예제 #2
0
  public Animation() {
    String[] keys = {"no Animator found"};
    if (tryDir(".")) // || tryDir("BLM305") || tryDir("CSE470"))
    keys = map.keySet().toArray(keys);
    System.out.println(map.size() + " classes loaded");
    menu = new JComboBox(keys);

    pan.setLayout(new BorderLayout(GAP, GAP - 4));
    pan.setBorder(new javax.swing.border.EmptyBorder(GAP, GAP, GAP, GAP));
    pan.setBackground(COLOR);

    last = new JPanel();
    last.setPreferredSize(DIM);
    pan.add(last, "Center");

    ref.setFont(NORM);
    ref.setEditable(false);
    ref.setColumns(35);
    ref.setDragEnabled(true);
    pan.add(ref, "North");

    pan.add(bottomPanel(), "South");

    pan.setToolTipText("A collective project for BLM320");
    menu.setToolTipText("Animator classes");
    who.setToolTipText("author()");
    ref.setToolTipText("description()");

    Closer ear = new Closer();
    menu.addActionListener(ear);
    stop.addActionListener(ear);
    frm.addWindowListener(ear);

    if (map.size() > 0) setItem(0);
    frm.setContentPane(pan);
    frm.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frm.setLocation(scaled(120), scaled(90));
    frm.pack(); // setSize() is called here
    frm.setVisible(true);
    start();
  }
  MyCustomizableGUI() {

    this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    textField = new JTextField(20);
    buttonPref = new JButton("Preferences");

    this.add(textField);
    this.add(buttonPref);

    buttonPref.addActionListener(evt -> prefDialog.setVisible(true));

    frame = new JFrame("My text editor");
    frame.setContentPane(this);
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);

    // Preferences dialog box
    prefDialog = new JDialog(frame, "Dialog", true);
    prefDialog.setLayout(new BorderLayout());
    JPanel p1 = new JPanel();
    p1.setLayout(new GridLayout(3, 2));
    JPanel p2 = new JPanel();
    p2.setLayout(new BoxLayout(p2, BoxLayout.X_AXIS));

    buttonSave = new JButton("Save");
    buttonCancel = new JButton("Cancel");

    buttonSave.addActionListener(
        evtSave -> {
          String fontChosen;
          int fontSizeChosen;

          prefDialog.setVisible(false);

          if ((String) color.getSelectedItem() == "Red") {
            textField.setForeground(Color.red);
          } else if ((String) color.getSelectedItem() == "Green") {
            textField.setForeground(Color.green);
          } else if ((String) color.getSelectedItem() == "Blue") {
            textField.setForeground(Color.blue);
          } else if ((String) color.getSelectedItem() == "Cyan") {
            textField.setForeground(Color.cyan);
          } else if ((String) color.getSelectedItem() == "Magenta") {
            textField.setForeground(Color.magenta);
          } else if ((String) color.getSelectedItem() == "Yellow") {
            textField.setForeground(Color.yellow);
          } else if ((String) color.getSelectedItem() == "Black") {
            textField.setForeground(Color.black);
          }

          fontChosen = (String) font.getSelectedItem();
          fontSizeChosen = Integer.parseInt((String) fontSize.getSelectedItem());
          textField.setFont(new Font(fontChosen, Font.PLAIN, fontSizeChosen));

          UserPreferences userPrefs = new UserPreferences();
          userPrefs.setColor((String) color.getSelectedItem());
          userPrefs.setFont(fontChosen);
          userPrefs.setFontSize(fontSizeChosen);

          try (FileOutputStream fileOut = new FileOutputStream("preferences.ser");
              ObjectOutputStream objectOut = new ObjectOutputStream(fileOut); ) {

            objectOut.writeObject(userPrefs);

          } catch (IOException ioe) {
            System.out.println("I/O error: " + ioe.getMessage());
          }
        });

    buttonCancel.addActionListener(evt -> prefDialog.setVisible(false));

    colorLabel = new JLabel("Color:");
    fontLabel = new JLabel("Font:");
    fontSizeLabel = new JLabel("Font size:");
    color = new JComboBox(colorList);
    font = new JComboBox(fontList);
    fontSize = new JComboBox(fontSizeList);

    p1.add(colorLabel);
    p1.add(color);
    p1.add(fontLabel);
    p1.add(font);
    p1.add(fontSizeLabel);
    p1.add(fontSize);
    p2.add(buttonCancel);
    p2.add(buttonSave);

    prefDialog.add(BorderLayout.NORTH, p1);
    prefDialog.add(BorderLayout.SOUTH, p2);

    prefDialog.pack();
  }
 public void setFont(String f, int fs) {
   textField.setFont(new Font(f, Font.PLAIN, fs));
 }
예제 #5
0
  /** The graphic handling and deployment. */
  private void initComponents() {
    jDesktopPane1 = new javax.swing.JDesktopPane();
    jInternalFrame1 = new javax.swing.JInternalFrame();
    tf = new javax.swing.JTextField();
    b1 = new javax.swing.JButton();
    jInternalFrame3 = new javax.swing.JInternalFrame();
    ta = new javax.swing.JTextArea();
    jsp_ta = new javax.swing.JScrollPane(ta);
    jMenuBar1 = new javax.swing.JMenuBar();
    jMenu1 = new javax.swing.JMenu();
    jMenuItem3 = new javax.swing.JMenuItem();
    jSeparator1 = new javax.swing.JSeparator();
    jMenuItem4 = new javax.swing.JMenuItem();

    jInternalFrame1
        .getContentPane()
        .setLayout(
            new javax.swing.BoxLayout(
                jInternalFrame1.getContentPane(), javax.swing.BoxLayout.X_AXIS));

    jInternalFrame1.setIconifiable(true);
    jInternalFrame1.setMaximizable(true);
    jInternalFrame1.setResizable(true);
    jInternalFrame1.setTitle("Message editor");
    jInternalFrame1.setToolTipText(
        "Move and resize all of these to make the chat room appearance match your preferences.");
    jInternalFrame1.setVisible(true);
    tf.setFont(new java.awt.Font("Lucida Sans", 0, 12));
    jInternalFrame1.getContentPane().add(tf);

    b1.setText("Send Message");
    jInternalFrame1.getContentPane().add(b1);

    jInternalFrame1.setBounds(10, 10, 440, 60);
    jDesktopPane1.add(jInternalFrame1, javax.swing.JLayeredPane.DEFAULT_LAYER);

    jInternalFrame3.setIconifiable(true);
    jInternalFrame3.setMaximizable(true);
    jInternalFrame3.setResizable(true);
    jInternalFrame3.setTitle("Messages");
    jInternalFrame3.setToolTipText(
        "Move and resize all of these to make the chat room appearance match your preferences.");
    jInternalFrame3.setVisible(true);
    ta.setBackground(new Color(255, 255, 255));
    ta.setEditable(false);
    ta.setFont(new java.awt.Font("Lucida Sans", 0, 12));
    // jsp_ta.setAutoscrolls(true);
    jsp_ta.setDoubleBuffered(true);

    jInternalFrame3.getContentPane().add(jsp_ta, java.awt.BorderLayout.CENTER);

    jInternalFrame3.setBounds(10, 80, 420, 240);

    jDesktopPane1.add(jInternalFrame3, javax.swing.JLayeredPane.DEFAULT_LAYER);

    getContentPane().add(jDesktopPane1, java.awt.BorderLayout.CENTER);

    jMenu1.setText("Private room options");
    jMenu1.setMnemonic(KeyEvent.VK_O);
    jMenu1.setToolTipText("Choose some options.");
    jMenuItem3.setText("Save conversation");
    jMenuItem3.setMnemonic(KeyEvent.VK_S);
    jMenuItem3.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
    jMenu1.add(jMenuItem3);
    jMenu1.add(jSeparator1);
    jMenuItem4.setText("Exit");
    jMenuItem4.setMnemonic(KeyEvent.VK_E);
    jMenuItem4.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.CTRL_MASK));
    jMenu1.add(jMenuItem4);
    jMenuBar1.add(jMenu1);
    setJMenuBar(jMenuBar1);

    this.pack();

    b1.addActionListener(this);
    tf.addActionListener(this);
    jMenuItem3.addActionListener(this);
    jMenuItem4.addActionListener(this);

    posx = (int) Math.random() * 640;
    posy = (int) Math.random() * 480;

    this.pack();
    this.setSize(dimx, dimy);
    this.setLocation(posx, posy);
    this.show();
  }