// Define method to return commands.
  private void buildFrame(int width, int height) {
    // Set JFrame title.
    setTitle("Communicator");

    // Initialize and set policies for JScrollPane(s).
    receiverScrollPane =
        setScrollPaneProperties(new JScrollPane(receiver = new JTextAreaPanel(COL, ROW)));
    senderScrollPane =
        setScrollPaneProperties(new JScrollPane(sender = new JTextAreaPanel(COL, ROW)));

    // Disable editability of receiver JTextAreaPanel.
    receiver.setEditable(false);

    // Initialize JButtonPanel.
    button = new JButtonPanel();

    // Define and initialize JButton(s).
    buildButtons();

    // Set panel size.
    setSize(width, height);

    // Set JPanel Layout.
    getContentPane().setLayout(new BorderLayout());

    // Add a JTextAreaPanel(s).
    getContentPane().add(receiverScrollPane, BorderLayout.NORTH);
    getContentPane().add(button, BorderLayout.CENTER);
    getContentPane().add(senderScrollPane, BorderLayout.SOUTH);

    // Build JMenuBar.
    buildMenu();

    // Build JButton action listeners.
    buildButtonActionListeners();

    // Set the screen and display dialog window in relation to screen size.
    dim = tk.getScreenSize();
    setLocation((dim.width / 100), (dim.height / 100));

    // --------------------- Begin Window ActionListener ---------------------/

    // Add window listener to the frame.
    addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent closingEvent) {
            // Exit on window frame close.
            System.exit(0);
          } // End of windowClosing() method.
        }); // End of addWindowListener() method for JFrame.

    // Set resizeable window off.
    setResizable(false);

    // Display the JFrame to the platform window manager.
    show();
  } // End of buildFrame() method.
Beispiel #2
0
 void centerFrame() {
   Toolkit t = getToolkit();
   Dimension scr = t.getScreenSize();
   setSize(scr.width / 2, scr.height / 2);
   setLocation(new Point((scr.width - getSize().width) / 2, (scr.height - getSize().height) / 2));
 }
// Define class.
public class StackTraceDialog extends JDialog implements ActionListener {
  // Define and initialize a default Toolkit.
  private Toolkit tk = Toolkit.getDefaultToolkit();

  // Define and initialize screen Dimension(s).
  private Dimension dim = tk.getScreenSize();

  // Define and initialize Container(s).
  private Container c = getContentPane();

  // Define and intialize phsyical size dimensions.
  int left = 0;
  int top = 0;
  int buttonWidth = 50;
  int buttonHeight = 25;
  int displayAreaWidth = dim.width - 400;
  int displayAreaHeight = dim.height - 400;
  int offsetMargin = 20;

  // The dialog width and height are derived from base objects.
  int dialogWidth = displayAreaWidth + offsetMargin;
  int dialogHeight = displayAreaHeight + buttonHeight + (3 * offsetMargin);

  // Define String(s).
  private String eStackTrace;

  // ---------------------------------/
  // Define AWT and Swing objects.
  // ---------------------------------/

  // Define and initialize JButton(s).
  private JButton okButton = new JButton("OK");

  // Define and initialize JTextArea(s).
  private JTextArea displayArea = new JTextArea();

  // Define Box(s).
  private Box displayBox;

  // ---------------------------- Constructor --------------------------------/

  // The class requires an owning frame and cannot be called from a default
  // constructor because none is defined in the JDialog class.
  public StackTraceDialog(Frame owner, String title, boolean modal) {
    // Call the constructor for JDialog.
    super(owner, modal);

    // The title argument is treated as overloaded because the stack trace
    // String is passed into an instance of this class by using it.  Then,
    // the String is assigned to a class level variable.
    eStackTrace = new String(title);

    // Call the buildDialogBox() method.
    buildDialogBox();
  } // End of StackTraceDialog constructor.

  // --------------------------- Begin Methods -------------------------------/

  // Method to build the dialog box for help.
  private void buildDialogBox() {
    // Set the JDialog window properties.
    setTitle("Stack Trace Detail");
    setResizable(false);
    setSize(dialogWidth, dialogHeight);

    // Append the stack trace output to the display area.
    displayArea.append(eStackTrace);

    // Create horizontal and vertical scrollbars for box.
    displayBox = Box.createHorizontalBox();
    displayBox = Box.createVerticalBox();

    // Add a JScrollPane to the Box.
    displayBox.add(new JScrollPane(displayArea));

    // Define behaviors of container.
    c.setLayout(null);
    c.add(displayBox);
    c.add(okButton);

    // Set scroll pane bounds.
    displayBox.setBounds(
        (dialogWidth / 2) - ((displayAreaWidth / 2) + 2),
        (top + (offsetMargin / 2)),
        displayAreaWidth,
        displayAreaHeight);

    // Set the behaviors, bounds and action listener for the button.
    okButton.setBounds(
        (dialogWidth / 2) - (buttonWidth / 2),
        (displayAreaHeight + offsetMargin),
        buttonWidth,
        buttonHeight);

    // Set the font to the platform default Font for the object with the
    // properties of bold and font size of 11.
    okButton.setFont(new Font(okButton.getFont().getName(), Font.BOLD, 11));

    // The class implements the ActionListener interface and therefore
    // provides an implementation of the actionPerformed() method.  When a
    // class implements ActionListener, the instance handler returns an
    // ActionListener.  The ActionListener then performs actionPerformed()
    // method on an ActionEvent.
    okButton.addActionListener(this);

    // Set the screen and display dialog window in relation to screen size.
    setLocation((dim.width / 2) - (dialogWidth / 2), (dim.height / 2) - (dialogHeight / 2));

    // Display JDialog.
    show();
  } // End of buildDialogBox method.

  // Class listener based on implementing ActionListener.
  public void actionPerformed(ActionEvent e) {

    this.setVisible(false);
    this.dispose();
  } // End of actionPerformed method.

  // ---------------------------- End Methods --------------------------------/

} // End of StackTraceDialog class.