/** Listener to handle button actions */
 public void actionPerformed(ActionEvent e) {
   // Check if the user changed the service filter option
   if (e.getSource() == service_box) {
     service_list.setEnabled(service_box.isSelected());
     service_list.clearSelection();
     remove_service_button.setEnabled(false);
     add_service_field.setEnabled(service_box.isSelected());
     add_service_field.setText("");
     add_service_button.setEnabled(false);
   }
   // Check if the user pressed the add service button
   if ((e.getSource() == add_service_button) || (e.getSource() == add_service_field)) {
     String text = add_service_field.getText();
     if ((text != null) && (text.length() > 0)) {
       service_data.addElement(text);
       service_list.setListData(service_data);
     }
     add_service_field.setText("");
     add_service_field.requestFocus();
   }
   // Check if the user pressed the remove service button
   if (e.getSource() == remove_service_button) {
     Object[] sels = service_list.getSelectedValues();
     for (int i = 0; i < sels.length; i++) {
       service_data.removeElement(sels[i]);
     }
     service_list.setListData(service_data);
     service_list.clearSelection();
   }
 }
Exemplo n.º 2
2
  AdminMain() {
    l = new JLabel();
    l.setBounds(10, 20, 1340, 1000);
    l.setBackground(Color.black);
    Font ft = new Font("Arial", Font.BOLD, 30);
    Font ft1 = new Font("Arial", Font.BOLD, 14);
    Font ft2 = new Font("Arial", Font.BOLD, 20);

    f1 = new Frame("Soft Test Management (Beta)");
    f1.setLayout(null);

    l1 = new Label("Test Instructions", l1.CENTER);
    l1.setBounds(10, 20, 1300, 60);
    l1.setForeground(Color.blue);
    l1.setBackground(Color.white);
    l1.setFont(ft);

    l2 = new JLabel("Deletion of Faculty/Students");
    l2.setBounds(20, 30, 1000, 500);
    l2.setBackground(Color.blue);
    l2.setFont(ft2);
    l3 = new JLabel("Test Pattern");
    l3.setBounds(20, 90, 1300, 500);
    l3.setBackground(Color.green);
    l3.setFont(ft2);

    b1 = new JButton("Go !");
    b1.setBounds(300, 220, 120, 30);
    b1.setBackground(Color.white);
    b1.setForeground(Color.blue);
    b1.setFont(ft2);

    b2 = new JButton("Go");
    b2.setBounds(300, 240, 120, 30);
    b2.setBackground(Color.white);
    b2.setForeground(Color.blue);
    b2.setFont(ft2);

    f1.add(l);
    l.add(l1);
    l2.add(b1);
    l.add(l2);
    l3.add(b2);
    l.add(l3);

    b1.addActionListener(this);
    b2.addActionListener(this);

    f1.setVisible(true);
    f1.setSize(1800, 800);
  }
Exemplo n.º 3
0
  private void warning(String msg) {
    final JDialog warn;
    JButton ok;
    JLabel message;

    warn = new JDialog();
    warn.setTitle(msg);

    message = new JLabel("CryoBay: " + msg);
    ok = new JButton("Ok");

    ok.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            warn.dispose();
          }
        });

    warn.getContentPane().setLayout(new BorderLayout());
    warn.getContentPane().add(message, "North");
    warn.getContentPane().add(ok, "South");

    warn.setSize(200, 80);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    warn.setLocation(screenSize.width / 2 - 100, screenSize.height / 2 - 40);
    warn.setResizable(false);
    warn.show();
  }
Exemplo n.º 4
0
  /** {@inheritDoc} */
  public void setEnabled(boolean b) {
    if (b != isEnabled()) {
      super.setEnabled(b);

      if ((selectedComponents & DISPLAY_DATE) > 0) {
        yearDecrButton.setEnabled(b);
        monthDecrButton.setEnabled(b);
        monthYearLabel.setEnabled(b);
        monthIncrButton.setEnabled(b);
        yearIncrButton.setEnabled(b);

        for (int day = 0; day < 7; day++) {
          dayOfWeekLabels[day].setEnabled(b);
        }

        for (int row = 0; row < 6; row++) {
          for (int day = 0; day < 7; day++) {
            if (dayButtons[row][day].getText().length() > 0) {
              dayButtons[row][day].setEnabled(b);
            }
          }
        }
      }

      if ((selectedComponents & DISPLAY_TIME) > 0) {
        spinner.setEnabled(b);
      }
    }
  }
 /** Stop talking to the server */
 public void stop() {
   if (socket != null) {
     // Close all the streams and socket
     if (out != null) {
       try {
         out.close();
       } catch (IOException ioe) {
       }
       out = null;
     }
     if (in != null) {
       try {
         in.close();
       } catch (IOException ioe) {
       }
       in = null;
     }
     if (socket != null) {
       try {
         socket.close();
       } catch (IOException ioe) {
       }
       socket = null;
     }
   } else {
     // Already stopped
   }
   // Make sure the right buttons are enabled
   start_button.setEnabled(true);
   stop_button.setEnabled(false);
   setStatus(STATUS_STOPPED);
 }
 /** Start talking to the server */
 public void start() {
   String codehost = getCodeBase().getHost();
   if (socket == null) {
     try {
       // Open the socket to the server
       socket = new Socket(codehost, port);
       // Create output stream
       out = new ObjectOutputStream(socket.getOutputStream());
       out.flush();
       // Create input stream and start background
       // thread to read data from the server
       in = new ObjectInputStream(socket.getInputStream());
       new Thread(this).start();
     } catch (Exception e) {
       // Exceptions here are unexpected, but we can't
       // really do anything (so just write it to stdout
       // in case someone cares and then ignore it)
       System.out.println("Exception! " + e.toString());
       e.printStackTrace();
       setErrorStatus(STATUS_NOCONNECT);
       socket = null;
     }
   } else {
     // Already started
   }
   if (socket != null) {
     // Make sure the right buttons are enabled
     start_button.setEnabled(false);
     stop_button.setEnabled(true);
     setStatus(STATUS_ACTIVE);
   }
 }
 /** Show the filter dialog */
 public void showDialog() {
   empty_border = new EmptyBorder(5, 5, 0, 5);
   indent_border = new EmptyBorder(5, 25, 5, 5);
   include_panel =
       new ServiceFilterPanel("Include messages based on target service:", filter_include_list);
   exclude_panel =
       new ServiceFilterPanel("Exclude messages based on target service:", filter_exclude_list);
   status_box = new JCheckBox("Filter messages based on status:");
   status_box.addActionListener(this);
   status_active = new JRadioButton("Active messages only");
   status_active.setSelected(true);
   status_active.setEnabled(false);
   status_complete = new JRadioButton("Complete messages only");
   status_complete.setEnabled(false);
   status_group = new ButtonGroup();
   status_group.add(status_active);
   status_group.add(status_complete);
   if (filter_active || filter_complete) {
     status_box.setSelected(true);
     status_active.setEnabled(true);
     status_complete.setEnabled(true);
     if (filter_complete) {
       status_complete.setSelected(true);
     }
   }
   status_options = new JPanel();
   status_options.setLayout(new BoxLayout(status_options, BoxLayout.Y_AXIS));
   status_options.add(status_active);
   status_options.add(status_complete);
   status_options.setBorder(indent_border);
   status_panel = new JPanel();
   status_panel.setLayout(new BorderLayout());
   status_panel.add(status_box, BorderLayout.NORTH);
   status_panel.add(status_options, BorderLayout.CENTER);
   status_panel.setBorder(empty_border);
   ok_button = new JButton("Ok");
   ok_button.addActionListener(this);
   cancel_button = new JButton("Cancel");
   cancel_button.addActionListener(this);
   buttons = new JPanel();
   buttons.setLayout(new FlowLayout());
   buttons.add(ok_button);
   buttons.add(cancel_button);
   panel = new JPanel();
   panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
   panel.add(include_panel);
   panel.add(exclude_panel);
   panel.add(status_panel);
   panel.add(buttons);
   dialog = new JDialog();
   dialog.setTitle("SOAP Monitor Filter");
   dialog.setContentPane(panel);
   dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
   dialog.setModal(true);
   dialog.pack();
   Dimension d = dialog.getToolkit().getScreenSize();
   dialog.setLocation((d.width - dialog.getWidth()) / 2, (d.height - dialog.getHeight()) / 2);
   ok_pressed = false;
   dialog.show();
 }
 /** Listener to handle service list selection changes */
 public void valueChanged(ListSelectionEvent e) {
   if (service_list.getSelectedIndex() == -1) {
     remove_service_button.setEnabled(false);
   } else {
     remove_service_button.setEnabled(true);
   }
 }
 public CFSecuritySwingISOCurrencyAskDeleteJPanel(
     ICFSecuritySwingSchema argSchema, ICFSecurityISOCurrencyObj argFocus) {
   super();
   final String S_ProcName = "construct-schema-focus";
   if (argSchema == null) {
     throw CFLib.getDefaultExceptionFactory()
         .newNullArgumentException(getClass(), S_ProcName, 1, "argSchema");
   }
   // argFocus is optional; focus may be set later during execution as
   // conditions of the runtime change.
   swingSchema = argSchema;
   swingFocus = argFocus;
   // Construct the various objects
   textAreaMessage = new JTextArea("Are you sure you want to delete this ISO Currency?");
   actionOk = new ActionOk();
   actionCancel = new ActionCancel();
   buttonOk = new JButton(actionOk);
   buttonCancel = new JButton(actionCancel);
   attrJPanel = argSchema.getISOCurrencyFactory().newAttrJPanel(argFocus);
   scrollPane = new CFHSlaveJScrollPane(attrJPanel);
   // Lay out the widgets
   setSize(1024, 480);
   Dimension min = new Dimension(480, 300);
   setMinimumSize(min);
   add(textAreaMessage);
   textAreaMessage.setBounds(0, 0, 1024, 50);
   int xparts = (768 - (2 * 125)) / 3;
   add(buttonOk);
   buttonOk.setBounds(xparts, 55, 125, 40);
   add(buttonCancel);
   buttonCancel.setBounds(xparts + 125 + xparts, 55, 125, 40);
   add(scrollPane);
   scrollPane.setBounds(0, 100, 1024, 480 - 100);
 }
  /** Simple test program. */
  public static void main(String[] args) {
    final JFrame frame = new JFrame("Testing AddPersonDialog");
    JButton button = new JButton("Click me");
    button.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            FamilyTree tree = new FamilyTree();
            AddPersonDialog dialog = new AddPersonDialog(frame, tree);
            dialog.pack();
            dialog.setLocationRelativeTo(frame);
            dialog.setVisible(true);

            Person newPerson = dialog.getPerson();
            if (newPerson != null) {
              tree.addPerson(newPerson);
              PrettyPrinter pretty = new PrettyPrinter(new PrintWriter(System.out, true));
              pretty.dump(tree);
            }
          }
        });
    frame.getContentPane().add(button);

    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(1);
          }
        });
    frame.pack();
    frame.setVisible(true);
  }
Exemplo n.º 11
0
 public void actionPerformed(ActionEvent ae) {
   JButton b = (JButton) ae.getSource();
   //      System.out.println("NumberEar: button="+b.getText());
   int i = new Integer(b.getText()).intValue() - 1;
   number[date].setForeground(Color.BLUE);
   date = i;
   number[i].setForeground(Color.CYAN);
 }
 /** Handle changes to the text field */
 public void changedUpdate(DocumentEvent e) {
   String text = add_service_field.getText();
   if ((text != null) && (text.length() > 0)) {
     add_service_button.setEnabled(true);
   } else {
     add_service_button.setEnabled(false);
   }
 }
 public void doLayout() {
   Dimension sz = getSize();
   textAreaMessage.setBounds(0, 0, sz.width, 50);
   int xparts = (sz.width - (2 * 125)) / 3;
   buttonOk.setBounds(xparts, 55, 125, 40);
   buttonCancel.setBounds(xparts + 125 + xparts, 55, 125, 40);
   scrollPane.setBounds(0, 100, sz.width, sz.height - 100);
   scrollPane.doLayout();
 }
Exemplo n.º 14
0
  // create and position GUI components; register event handlers
  private void createUserInterface() {
    // get content pane for attaching GUI components
    Container contentPane = getContentPane();

    // enable explicit positioning of GUI components
    contentPane.setLayout(null);

    // set up principalJLabel
    principalJLabel = new JLabel();
    principalJLabel.setBounds(20, 20, 80, 20);
    principalJLabel.setText("Principal:");
    contentPane.add(principalJLabel);

    // set up principalJTextField
    principalJTextField = new JTextField();
    principalJTextField.setBounds(80, 20, 90, 20);
    principalJTextField.setText("0");
    principalJTextField.setHorizontalAlignment(JTextField.RIGHT);
    contentPane.add(principalJTextField);

    // set up resultJLabel
    resultJLabel = new JLabel();
    resultJLabel.setBounds(20, 60, 100, 20);
    resultJLabel.setText("Result:");
    contentPane.add(resultJLabel);

    // set up resultJTextArea
    resultJTextArea = new JTextArea();
    resultJTextArea.setBounds(20, 85, 260, 120);
    resultJTextArea.setEditable(false);
    contentPane.add(resultJTextArea);

    // set up calculateJButton
    calculateJButton = new JButton();
    calculateJButton.setBounds(190, 20, 90, 20);
    calculateJButton.setText("Calculate");
    contentPane.add(calculateJButton);
    calculateJButton.addActionListener(
        new ActionListener() // anonymous inner class
        {
          // event handler called when calculateJButton is pressed
          public void actionPerformed(ActionEvent event) {
            calculateJButtonActionPerformed(event);
          }
        } // end anonymous inner class
        ); // end call to addActionListener

    // set properties of application's window
    setTitle("Comparing Rates"); // set title bar text
    setSize(310, 255); // set window size
    setVisible(true); // display window
  } // end method createUserInterface
 /** Constructor */
 public ServiceFilterPanel(String text, Vector list) {
   empty_border = new EmptyBorder(5, 5, 0, 5);
   indent_border = new EmptyBorder(5, 25, 5, 5);
   service_box = new JCheckBox(text);
   service_box.addActionListener(this);
   service_data = new Vector();
   if (list != null) {
     service_box.setSelected(true);
     service_data = (Vector) list.clone();
   }
   service_list = new JList(service_data);
   service_list.setBorder(new EtchedBorder());
   service_list.setVisibleRowCount(5);
   service_list.addListSelectionListener(this);
   service_list.setEnabled(service_box.isSelected());
   service_scroll = new JScrollPane(service_list);
   service_scroll.setBorder(new EtchedBorder());
   remove_service_button = new JButton("Remove");
   remove_service_button.addActionListener(this);
   remove_service_button.setEnabled(false);
   remove_service_panel = new JPanel();
   remove_service_panel.setLayout(new FlowLayout());
   remove_service_panel.add(remove_service_button);
   service_area = new JPanel();
   service_area.setLayout(new BorderLayout());
   service_area.add(service_scroll, BorderLayout.CENTER);
   service_area.add(remove_service_panel, BorderLayout.EAST);
   service_area.setBorder(indent_border);
   add_service_field = new JTextField();
   add_service_field.addActionListener(this);
   add_service_field.getDocument().addDocumentListener(this);
   add_service_field.setEnabled(service_box.isSelected());
   add_service_button = new JButton("Add");
   add_service_button.addActionListener(this);
   add_service_button.setEnabled(false);
   add_service_panel = new JPanel();
   add_service_panel.setLayout(new BorderLayout());
   JPanel dummy = new JPanel();
   dummy.setBorder(empty_border);
   add_service_panel.add(dummy, BorderLayout.WEST);
   add_service_panel.add(add_service_button, BorderLayout.EAST);
   add_service_area = new JPanel();
   add_service_area.setLayout(new BorderLayout());
   add_service_area.add(add_service_field, BorderLayout.CENTER);
   add_service_area.add(add_service_panel, BorderLayout.EAST);
   add_service_area.setBorder(indent_border);
   setLayout(new BorderLayout());
   add(service_box, BorderLayout.NORTH);
   add(service_area, BorderLayout.CENTER);
   add(add_service_area, BorderLayout.SOUTH);
   setBorder(empty_border);
 }
 // 定义添加一行格式化文本框的方法
 private void addRow(String labelText, final JFormattedTextField field) {
   mainPanel.add(new JLabel(labelText));
   mainPanel.add(field);
   final JLabel valueLabel = new JLabel();
   mainPanel.add(valueLabel);
   // 为"确定"按钮添加事件监听器
   // 当用户单击“确定”按钮时,文本框后显示文本框内的值
   okButton.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent event) {
           Object value = field.getValue();
           // 如果该值是数组,使用Arrays的toString方法输出数组
           if (value.getClass().isArray()) {
             StringBuilder builder = new StringBuilder();
             builder.append('{');
             for (int i = 0; i < Array.getLength(value); i++) {
               if (i > 0) builder.append(',');
               builder.append(Array.get(value, i).toString());
             }
             builder.append('}');
             valueLabel.setText(builder.toString());
           } else {
             // 输出格式化文本框的值
             valueLabel.setText(value.toString());
           }
         }
       });
 }
Exemplo n.º 17
0
 public objUpdate() {
   super("Person");
   setBounds(150, 150, 200, 120);
   setResizable(false);
   setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
   Container con = this.getContentPane();
   con.setLayout(new FlowLayout());
   con.add(n);
   con.add(d);
   next.setMnemonic('N');
   newPerson.setMnemonic('P');
   con.add(next);
   con.add(newPerson);
   this.addWindowListener(new Window());
   next.addActionListener(new Next());
   newPerson.addActionListener(new NewPerson());
   setVisible(true);
 }
 public JPanel getGuiPanel() {
   JPanel panel = new JPanel();
   JButton button = new JButton();
   button.addActionListener(new DoItListener());
   outputLabel = new JLabel("date appears here");
   DateFormatSymbols dateStuff = new DateFormatSymbols();
   month = new JComboBox(dateStuff.getMonths());
   day = new JTextField(8);
   year = new JTextField(8);
   JPanel inputPanel = new JPanel(new GridLayout(3, 2));
   inputPanel.add(new JLabel("Month"));
   inputPanel.add(month);
   inputPanel.add(new JLabel("Day"));
   inputPanel.add(day);
   inputPanel.add(new JLabel("Year"));
   inputPanel.add(button);
   inputPanel.add(outputLabel);
   return panel;
 }
 /** Listener to handle table selection changes */
 public void valueChanged(ListSelectionEvent e) {
   int row = table.getSelectedRow();
   // Check if they selected a specific row
   if (row > 0) {
     remove_button.setEnabled(true);
   } else {
     remove_button.setEnabled(false);
   }
   // Check for "most recent" selection
   if (row == 0) {
     row = model.getRowCount() - 1;
     if (row == 0) {
       row = -1;
     }
   }
   if (row == -1) {
     // Clear the details panel
     details_time_value.setText("");
     details_target_value.setText("");
     details_status_value.setText("");
     request_text.setText("");
     response_text.setText("");
   } else {
     // Show the details for the row
     SOAPMonitorData soap = model.getData(row);
     details_time_value.setText(soap.getTime());
     details_target_value.setText(soap.getTargetService());
     details_status_value.setText(soap.getStatus());
     if (soap.getSOAPRequest() == null) {
       request_text.setText("");
     } else {
       request_text.setText(soap.getSOAPRequest());
       request_text.setCaretPosition(0);
     }
     if (soap.getSOAPResponse() == null) {
       response_text.setText("");
     } else {
       response_text.setText(soap.getSOAPResponse());
       response_text.setCaretPosition(0);
     }
   }
 }
Exemplo n.º 20
0
 private JButton createCopyToClipboardButton() {
   JButton button = new JButton("COPY TO CLIPBOARD");
   button.setBackground(Color.BLACK);
   button.setForeground(Color.GRAY);
   button.addActionListener(
       new ActionListener() {
         @Override
         public void actionPerformed(ActionEvent e) {
           try {
             copyOverviewToClipboard();
           } catch (InsufficientDataException ex) {
             ex.printStackTrace();
             JOptionPane.showMessageDialog(
                 ReviewDialog.this,
                 "Failed to copy the overview to clipboard: " + ex.getMessage());
           }
         }
       });
   return button;
 }
Exemplo n.º 21
0
 public S3Lsq() {
   String s = "Data fitted to power law (nonlinear case)";
   df = new DatanFrame(getClass().getName(), s);
   // parameter input
   AuxJInputGroup ig = new AuxJInputGroup("Parameter input", "");
   JLabel errorLabel = new JLabel();
   ni[0] = new AuxJNumberInput("n", "number of data points (>=3)", errorLabel);
   ni[0].setProperties("n", true, 3);
   ni[0].setNumberInTextField(20);
   ig.add(ni[0]);
   ni[1] = new AuxJNumberInput("t_0", "first value of controlled variable (>=0)", errorLabel);
   ni[1].setProperties("t_0", false, 0.);
   ni[1].setNumberInTextField(0);
   ig.add(ni[1]);
   ni[2] = new AuxJNumberInput("delta_t", "step width of controlled variable (>=0)", errorLabel);
   ni[2].setProperties("delta_t", false, 0.);
   ni[2].setNumberInTextField(.1);
   ig.add(ni[2]);
   ni[3] = new AuxJNumberInput("x_1", "coefficient in front of exponential term (>0)", errorLabel);
   ni[3].setProperties("x_1", false, .000001);
   ni[3].setNumberInTextField(1.);
   ig.add(ni[3]);
   ni[4] = new AuxJNumberInput("x_2", "exponent (>=0)", errorLabel);
   ni[4].setProperties("x_2", false, 0.);
   ni[4].setNumberInTextField(2.);
   ig.add(ni[4]);
   ni[5] = new AuxJNumberInput("sigma", "size of measurement errors (>0)", errorLabel);
   ni[5].setProperties("sigma", false, 0.00001);
   ni[5].setNumberInTextField(.2);
   ig.add(ni[5]);
   df.add(ig);
   df.add(errorLabel);
   JButton goButton = new JButton("Go");
   GoButtonListener gl = new GoButtonListener();
   goButton.addActionListener(gl);
   df.add(goButton);
   df.pack();
   df.toFront();
 }
Exemplo n.º 22
0
 /**
  * The function creates a button, which opens a file chooser and writes a summary of the displayed
  * results into a user-selected file.
  *
  * @return The 'save to file' button.
  */
 private JButton createSaveToFileButton() {
   JButton b = new JButton("SAVE TO FILE");
   b.setBackground(Color.BLACK);
   b.setForeground(Color.GRAY);
   b.addActionListener(
       new ActionListener() {
         @Override
         public void actionPerformed(ActionEvent e) {
           try {
             checkTotal();
             fileChooser.setSelectedFile(new File(getDefaultFilename()));
             int returnValue = fileChooser.showDialog(ReviewDialog.this, "Save");
             if (returnValue != JFileChooser.APPROVE_OPTION) return;
             writeToFile(fileChooser.getSelectedFile());
             ReviewDialog.this.setVisible(false);
           } catch (Exception ex) {
             JOptionPane.showMessageDialog(
                 ReviewDialog.this, ex.getMessage(), "Error occurred", JOptionPane.ERROR_MESSAGE);
           }
         }
       });
   return b;
 }
Exemplo n.º 23
0
 public E3Min() {
   numForm = NumberFormat.getNumberInstance(Locale.US);
   numForm.setMaximumFractionDigits(12);
   numForm.setMinimumFractionDigits(12);
   String s =
       "Example demonstrating the use of class MinAsy by fitting a Gaussian to small sample"
           + " and determining the asymmetric errors of parameters by MinAsy";
   df = new DatanFrame(getClass().getName(), s);
   AuxJInputGroup ig = new AuxJInputGroup("Enter number N of events (>= 2, <= 10000)", "");
   JLabel errorLabel = new JLabel();
   ni[0] = new AuxJNumberInput("N", "number of events", errorLabel);
   ig.add(ni[0]);
   ni[0].setProperties("N", true);
   ni[0].setMinimum(2);
   ni[0].setMaximum(10000);
   ni[0].setNumberInTextField(10);
   df.add(ig);
   df.add(errorLabel);
   JButton goButton = new JButton("Go");
   GoButtonListener gl = new GoButtonListener();
   goButton.addActionListener(gl);
   df.add(goButton);
   df.repaint();
 }
 public void doLayout() {
   Dimension sz = getSize();
   final int buttonWidth = 100;
   final int buttonHeight = 25;
   final int buttonSpacing = 10;
   final int spTop = buttonSpacing + buttonHeight + buttonSpacing;
   int buttonStart = (sz.width - ((3 * buttonWidth) + (2 * buttonSpacing))) / 2;
   if (buttonStart < 0) {
     buttonStart = 0;
   }
   int spHeight = sz.height - spTop;
   if (spHeight < 0) {
     spHeight = 0;
   }
   buttonChooseNone.setBounds(buttonStart, buttonSpacing, buttonWidth, buttonHeight);
   buttonChooseSelected.setBounds(
       buttonStart + buttonWidth + buttonSpacing, buttonSpacing, buttonWidth, buttonHeight);
   buttonCancel.setBounds(
       buttonStart + buttonWidth + buttonSpacing + buttonWidth + buttonSpacing,
       buttonSpacing,
       buttonWidth,
       buttonHeight);
   dataScrollPane.setBounds(0, spTop, sz.width, spHeight);
 }
Exemplo n.º 25
0
  public GradeCalcPanel() {
    calculator = new GradeCalculator(); // Create a calculator instance
    // setLayout( new GridLayout(1,5,10,10));
    prompt = new JLabel("Grade:");
    resultLabel = new JLabel("Average:");
    inputField = new JTextField(10);
    resultField = new JTextField(20);
    resultField.setEditable(false);
    button = new JButton("Enter");
    button.addActionListener(this);

    add(prompt);
    add(inputField);
    add(button);
    add(resultLabel);
    add(resultField);
    inputField.setText("");
  } // GradeCalcPanel()
Exemplo n.º 26
0
  /** Initializes this dialog. */
  private void initDialog() {
    setMinimumSize(new Dimension(640, 480));

    final JComponent settingsPane = createSettingsPane();
    final JComponent previewPane = createPreviewPane();

    final JPanel contentPane = new JPanel(new GridBagLayout());
    contentPane.add(
        settingsPane,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.NORTH,
            GridBagConstraints.NONE,
            new Insets(2, 0, 2, 0),
            0,
            0));
    contentPane.add(
        previewPane,
        new GridBagConstraints(
            1,
            0,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTH,
            GridBagConstraints.BOTH,
            new Insets(2, 0, 2, 0),
            0,
            0));

    final JButton runAnalysisButton = ToolUtils.createRunAnalysisButton(this);
    this.runAnalysisAction = (RestorableAction) runAnalysisButton.getAction();

    final JButton exportButton = ToolUtils.createExportButton(this);
    this.exportAction = exportButton.getAction();
    this.exportAction.setEnabled(false);

    final JButton closeButton = ToolUtils.createCloseButton();
    this.closeAction = closeButton.getAction();

    final JComponent buttons =
        SwingComponentUtils.createButtonPane(runAnalysisButton, exportButton, closeButton);

    SwingComponentUtils.setupWindowContentPane(this, contentPane, buttons, runAnalysisButton);
  }
Exemplo n.º 27
0
 /**
  * Adds a row to the main panel.
  *
  * @param labelText the label of the field
  * @param field the sample field
  */
 public void addRow(String labelText, final JFormattedTextField field) {
   mainPanel.add(new JLabel(labelText));
   mainPanel.add(field);
   final JLabel valueLabel = new JLabel();
   mainPanel.add(valueLabel);
   okButton.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent event) {
           Object value = field.getValue();
           Class<?> cl = value.getClass();
           String text = null;
           if (cl.isArray()) {
             if (cl.getComponentType().isPrimitive()) {
               try {
                 text = Arrays.class.getMethod("toString", cl).invoke(null, value).toString();
               } catch (ReflectiveOperationException ex) {
                 // ignore reflection exceptions
               }
             } else text = Arrays.toString((Object[]) value);
           } else text = value.toString();
           valueLabel.setText(text);
         }
       });
 }
Exemplo n.º 28
0
  /** Create and layout the visual components. */
  private void initComponents() {
    setTitle("Chart Settings");
    setSize(new Dimension(450, 375));
    setResizable(false);

    addWindowListener(
        new java.awt.event.WindowAdapter() {
          public void windowClosing(java.awt.event.WindowEvent evt) {
            closeDialog(evt);
          }
        });

    Box mainView = new Box(VERTICAL);
    getContentPane().add(mainView);

    Box row;

    Box yAxisView = new Box(VERTICAL);
    yAxisView.setBorder(border);
    mainView.add(yAxisView);

    yAutoScaleCheckbox = new JCheckBox("Auto Scale");
    yAutoScaleCheckbox.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            yAutoScaleCheckboxActionPerformed(evt);
          }
        });
    row = new Box(HORIZONTAL);
    row.add(Box.createHorizontalGlue());
    row.add(yAutoScaleCheckbox);
    yAxisView.add(row);

    yAxisMinValueField = new JTextField(10);
    yAxisMinValueField.setMaximumSize(yAxisMinValueField.getPreferredSize());
    yAxisMinValueField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
    yAxisMinValueField.addFocusListener(
        new FocusAdapter() {
          public void focusGained(FocusEvent event) {
            yAxisMinValueField.selectAll();
          }

          public void focusLost(FocusEvent event) {
            yAxisMinValueField.setCaretPosition(0);
            yAxisMinValueField.moveCaretPosition(0);
          }
        });
    row = new Box(HORIZONTAL);
    row.add(Box.createHorizontalGlue());
    row.add(new JLabel("Min:"));
    row.add(yAxisMinValueField);
    yAxisView.add(row);

    yAxisMaxValueField = new JTextField(10);
    yAxisMaxValueField.setMaximumSize(yAxisMaxValueField.getPreferredSize());
    yAxisMaxValueField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
    yAxisMaxValueField.addFocusListener(
        new FocusAdapter() {
          public void focusGained(FocusEvent event) {
            yAxisMaxValueField.selectAll();
          }

          public void focusLost(FocusEvent event) {
            yAxisMaxValueField.setCaretPosition(0);
            yAxisMaxValueField.moveCaretPosition(0);
          }
        });
    row = new Box(HORIZONTAL);
    row.add(Box.createHorizontalGlue());
    row.add(new JLabel("Max:"));
    row.add(yAxisMaxValueField);
    yAxisView.add(row);

    yAxisDivisionsField = new JTextField(10);
    yAxisDivisionsField.setMaximumSize(yAxisDivisionsField.getPreferredSize());
    yAxisDivisionsField.setHorizontalAlignment(JTextField.RIGHT);
    yAxisDivisionsField.addFocusListener(
        new FocusAdapter() {
          public void focusGained(FocusEvent event) {
            yAxisDivisionsField.selectAll();
          }

          public void focusLost(FocusEvent event) {
            yAxisDivisionsField.setCaretPosition(0);
            yAxisDivisionsField.moveCaretPosition(0);
          }
        });
    row = new Box(HORIZONTAL);
    row.add(Box.createHorizontalGlue());
    row.add(new JLabel("Major Divisions:"));
    row.add(yAxisDivisionsField);
    yAxisView.add(row);

    Box buttonView = new Box(HORIZONTAL);
    mainView.add(buttonView);
    buttonView.add(Box.createHorizontalGlue());

    JButton revertButton = new JButton("Revert");
    revertButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            revertButtonActionPerformed(event);
          }
        });
    buttonView.add(revertButton);

    JButton applyButton = new JButton("Apply");
    applyButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            applyButtonActionPerformed(event);
          }
        });
    buttonView.add(applyButton);

    pack();
  }
  /**
   * Creates a new <code>AddPersonDialog</code> with a given owner <code>JFrame</code> and <code>
   * FamilyTree</code>.
   */
  public AddPersonDialog(JFrame owner, FamilyTree tree) {
    super(owner, "Add New Person", true /* modal */);

    Container pane = this.getContentPane();
    pane.setLayout(new BorderLayout());

    JPanel infoPanel = new JPanel();
    infoPanel.setLayout(new GridLayout(0, 2));
    Border infoBorder = BorderFactory.createEmptyBorder(5, 5, 5, 5);
    infoPanel.setBorder(infoBorder);

    infoPanel.add(new JLabel("id:"));
    final JTextField idField = new JTextField();
    infoPanel.add(idField);

    final ButtonGroup group = new ButtonGroup();

    final JRadioButton male = new JRadioButton("male", true);
    group.add(male);
    infoPanel.add(male);

    final JRadioButton female = new JRadioButton("female");
    group.add(female);
    infoPanel.add(female);

    infoPanel.add(new JLabel("First name:"));
    final JTextField firstNameField = new JTextField();
    infoPanel.add(firstNameField);

    infoPanel.add(new JLabel("Middle name:"));
    final JTextField middleNameField = new JTextField();
    infoPanel.add(middleNameField);

    infoPanel.add(new JLabel("Last name:"));
    final JTextField lastNameField = new JTextField();
    infoPanel.add(lastNameField);

    infoPanel.add(new JLabel("Date of Birth:"));
    final JTextField dobField = new JTextField();
    infoPanel.add(dobField);

    infoPanel.add(new JLabel("Date of Death:"));
    final JTextField dodField = new JTextField();
    infoPanel.add(dodField);

    infoPanel.add(new JLabel("Father:"));
    JPanel fatherPanel = new JPanel();
    fatherPanel.setLayout(new FlowLayout());
    final JTextField fatherText = new JTextField("Click to choose");
    fatherText.setEditable(false);
    fatherText.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            // Pop up a PersonChooseDialog, place name in TextField
            System.out.println("Clicked father");
          }
        });
    fatherPanel.add(fatherText);
    infoPanel.add(fatherPanel);

    infoPanel.add(new JLabel("Mother:"));
    JPanel motherPanel = new JPanel();
    motherPanel.setLayout(new FlowLayout());
    final JTextField motherText = new JTextField("Click to choose");
    motherText.setEditable(false);
    motherText.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            // Pop up a PersonChooseDialog, place name in TextField
            System.out.println("Clicked mother");
          }
        });
    motherPanel.add(motherText);
    infoPanel.add(motherPanel);

    pane.add(infoPanel, BorderLayout.NORTH);

    // "Add" and "Cancel" buttons
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
    buttonPanel.add(Box.createHorizontalGlue());

    JButton addButton = new JButton("Add");
    addButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Create a new person based on the information entered in
            // this dialog
            int id = 0;
            try {
              id = Integer.parseInt(idField.getText());

            } catch (NumberFormatException ex) {
              error("Invalid id: " + idField.getText());
              return;
            }

            String text = null;

            text = dobField.getText();
            Date dob = null;
            if (text != null && !text.equals("")) {
              dob = parseDate(dobField.getText());
              if (dob == null) {
                // Parse error
                return;
              }
            }

            text = dodField.getText();
            Date dod = null;
            if (text != null && !text.equals("")) {
              dod = parseDate(dodField.getText());
              if (dod == null) {
                // Parse error
                return;
              }
            }

            Person.Gender gender;
            if (group.getSelection().equals(male)) {
              gender = Person.MALE;

            } else {
              gender = Person.FEMALE;
            }

            // Okay, everything parsed alright
            newPerson = new Person(id, gender);
            newPerson.setFirstName(firstNameField.getText());
            newPerson.setMiddleName(middleNameField.getText());
            newPerson.setLastName(lastNameField.getText());
            newPerson.setDateOfBirth(dob);
            newPerson.setDateOfDeath(dod);

            if (mother != null) {
              newPerson.setMother(mother);
            }

            if (father != null) {
              newPerson.setFather(father);
            }

            // We're all happy
            AddPersonDialog.this.dispose();
          }
        });
    buttonPanel.add(addButton);

    buttonPanel.add(Box.createHorizontalGlue());

    JButton cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Read my lips, no new Person!

            AddPersonDialog.this.newPerson = null;

            AddPersonDialog.this.dispose();
          }
        });
    buttonPanel.add(cancelButton);

    buttonPanel.add(Box.createHorizontalGlue());

    pane.add(buttonPanel, BorderLayout.SOUTH);
  }
  // create and position GUI components; register event handlers
  private void createUserInterface() {
    // get content pane for attaching GUI components
    Container contentPane = getContentPane();

    // enable explicit positioning of GUI components
    contentPane.setLayout(null);

    // set up principalJLabel
    principalJLabel = new JLabel();
    principalJLabel.setBounds(16, 16, 56, 24);
    principalJLabel.setText("Principal:");
    contentPane.add(principalJLabel);

    // set up principalJTextField
    principalJTextField = new JTextField();
    principalJTextField.setBounds(100, 16, 100, 24);
    principalJTextField.setHorizontalAlignment(JTextField.RIGHT);
    contentPane.add(principalJTextField);

    // set up interestRateJLabel
    interestRateJLabel = new JLabel();
    interestRateJLabel.setBounds(16, 56, 80, 24);
    interestRateJLabel.setText("Interest rate:");
    contentPane.add(interestRateJLabel);

    // set up interestRateJTextField
    interestRateJTextField = new JTextField();
    interestRateJTextField.setBounds(100, 56, 100, 24);
    interestRateJTextField.setHorizontalAlignment(JTextField.RIGHT);
    contentPane.add(interestRateJTextField);

    // set up yearsJLabel
    yearsJLabel = new JLabel();
    yearsJLabel.setBounds(16, 96, 48, 24);
    yearsJLabel.setText("Years:");
    contentPane.add(yearsJLabel);

    // set up yearsJSpinner
    yearsJSpinner = new JSpinner(new SpinnerNumberModel(1, 1, 10, 1));
    yearsJSpinner.setBounds(100, 96, 100, 24);
    contentPane.add(yearsJSpinner);

    // set up yearlyBalanceJLabel
    yearlyBalanceJLabel = new JLabel();
    yearlyBalanceJLabel.setBounds(16, 136, 150, 24);
    yearlyBalanceJLabel.setText("Yearly account balance:");
    contentPane.add(yearlyBalanceJLabel);

    // set up yearlyBalanceJTextArea
    yearlyBalanceJTextArea = new JTextArea();
    yearlyBalanceJTextArea.setEditable(false);

    // set up yearlyBalanceJScrollPane
    yearlyBalanceJScrollPane = new JScrollPane(yearlyBalanceJTextArea);
    yearlyBalanceJScrollPane.setBounds(16, 160, 300, 92);
    contentPane.add(yearlyBalanceJScrollPane);

    // set up calculateJButton
    calculateJButton = new JButton();
    calculateJButton.setBounds(216, 16, 100, 24);
    calculateJButton.setText("Calculate");
    contentPane.add(calculateJButton);
    calculateJButton.addActionListener(
        new ActionListener() // anonymous inner class
        {
          // event handler called when calculateJButton is clicked
          public void actionPerformed(ActionEvent event) {
            calculateJButtonActionPerformed(event);
          }
        } // end anonymous inner class
        ); // end call to addActionListener

    // set properties of application's window
    setTitle("Interest Calculator"); // set title bar text
    setSize(340, 296); // set window size
    setVisible(true); // display window
  } // end method createUserInterface