Exemplo n.º 1
0
  private Game() {
    // Top-level frame
    final JFrame frame = new JFrame("Falling Blocks");
    frame.setLocation(200, 50);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Main playing area
    final TetrisCourt court = new TetrisCourt();
    frame.add(court, BorderLayout.CENTER);

    // Reset button
    final JPanel panel = new JPanel();
    frame.add(panel, BorderLayout.NORTH);
    final JButton reset = new JButton("Reset");
    reset.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            court.reset();
          }
        });

    panel.add(reset);

    // Put the frame on the screen
    frame.pack();
    frame.setVisible(true);
    // Start the game running
    court.reset();
  }
  public void actionPerformed(ActionEvent e) {

    if (e.getSource() == creer) {

      this.setVisible(false);
      JFrame fenetremilieu = new FenetreMilieu(this);
      fenetremilieu.setVisible(true);
      fenetremilieu.setLocation(500, 500);
    }

    if (e.getSource() == quitter) {

      this.dispose();
    }

    if (e.getSource() == options) {

      String message = "Choisissez le port";
      numport = Integer.parseInt(JOptionPane.showInputDialog(this, message));

      // JFrame fenetreoptions = new FenetreOptions();
      // fenetreoptions.setVisible(true);

    }
  }
Exemplo n.º 3
0
  /**
   * Init JWhiteBoard interface
   *
   * @throws Exception
   */
  public void go() throws Exception {
    if (!noChannel && !useState) channel.connect(groupName);
    mainFrame = new JFrame();
    mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    drawPanel = new DrawPanel(useState);
    drawPanel.setBackground(backgroundColor);
    subPanel = new JPanel();
    mainFrame.getContentPane().add("Center", drawPanel);
    clearButton = new JButton("Clean");
    clearButton.setFont(defaultFont);
    clearButton.addActionListener(this);
    leaveButton = new JButton("Exit");
    leaveButton.setFont(defaultFont);
    leaveButton.addActionListener(this);
    subPanel.add("South", clearButton);
    subPanel.add("South", leaveButton);
    mainFrame.getContentPane().add("South", subPanel);
    mainFrame.setBackground(backgroundColor);
    clearButton.setForeground(Color.blue);
    leaveButton.setForeground(Color.blue);
    mainFrame.pack();
    mainFrame.setLocation(15, 25);
    mainFrame.setBounds(new Rectangle(250, 250));

    if (!noChannel && useState) {
      channel.connect(groupName, null, stateTimeout);
    }
    mainFrame.setVisible(true);
  }
Exemplo n.º 4
0
  // Initialize all the GUI components and display the frame
  private static void initGUI() {
    // Set up the status bar
    statusField = new JLabel();
    statusField.setText(statusMessages[DISCONNECTED]);
    statusColor = new JTextField(1);
    statusColor.setBackground(Color.red);
    statusColor.setEditable(false);
    statusBar = new JPanel(new BorderLayout());
    statusBar.add(statusColor, BorderLayout.WEST);
    statusBar.add(statusField, BorderLayout.CENTER);

    // Set up the options pane
    JPanel optionsPane = initOptionsPane();

    // Set up the chat pane
    JPanel chatPane = new JPanel(new BorderLayout());
    chatText = new JTextArea(10, 20);
    chatText.setLineWrap(true);
    chatText.setEditable(false);
    chatText.setForeground(Color.blue);
    JScrollPane chatTextPane =
        new JScrollPane(
            chatText,
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    chatLine = new JTextField();
    chatLine.setEnabled(false);
    chatLine.addActionListener(
        new ActionAdapter() {
          public void actionPerformed(ActionEvent e) {
            String s = chatLine.getText();
            if (!s.equals("")) {
              appendToChatBox("OUTGOING: " + s + "\n");
              chatLine.selectAll();

              // Send the string
              sendString(s);
            }
          }
        });
    chatPane.add(chatLine, BorderLayout.SOUTH);
    chatPane.add(chatTextPane, BorderLayout.CENTER);
    chatPane.setPreferredSize(new Dimension(200, 200));

    // Set up the main pane
    JPanel mainPane = new JPanel(new BorderLayout());
    mainPane.add(statusBar, BorderLayout.SOUTH);
    mainPane.add(optionsPane, BorderLayout.WEST);
    mainPane.add(chatPane, BorderLayout.CENTER);

    // Set up the main frame
    mainFrame = new JFrame("Simple TCP Chat");
    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    mainFrame.setContentPane(mainPane);
    mainFrame.setSize(mainFrame.getPreferredSize());
    mainFrame.setLocation(200, 200);
    mainFrame.pack();
    mainFrame.setVisible(true);
  }
Exemplo n.º 5
0
 public static void main(String[] args) {
   Plot2D test = new Plot2D();
   JFrame f = new JFrame();
   f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   f.add(test.getContent());
   f.add(test.getUIPanel(), "Last");
   f.setSize(400, 400);
   f.setLocation(50, 50);
   f.setVisible(true);
 }
Exemplo n.º 6
0
  // function to center the frame
  public static void center(JFrame jfrm) {
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    int width = jfrm.getSize().width;
    int height = jfrm.getSize().height;

    int x = (dim.width - width) / 2;
    int y = (dim.height - height) / 2;

    jfrm.setLocation(x, y);
  }
Exemplo n.º 7
0
 /** The main routine simply opens a window that shows a PaintWithOffScreenCanvas panel. */
 public static void main(String[] args) {
   JFrame window = new JFrame("PaintWithOffScreenCanvas");
   AdvancedGUIEX1 content = new AdvancedGUIEX1();
   window.setContentPane(content);
   window.setJMenuBar(content.getMenuBar());
   window.pack();
   window.setResizable(false);
   Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
   window.setLocation(
       (screenSize.width - window.getWidth()) / 2, (screenSize.height - window.getHeight()) / 2);
   window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   window.setVisible(true);
 }
Exemplo n.º 8
0
 public static void main(String[] args) {
   JFrame frame = new JFrame("Cwiczenie5_4");
   Container cp = frame.getContentPane();
   Cwiczenie5_4 Cwiczenie5_4 = new Cwiczenie5_4();
   cp.add(Cwiczenie5_4);
   frame.addKeyListener(Cwiczenie5_4.bar);
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.setResizable(false);
   frame.setLocation(300, 300);
   frame.pack();
   frame.show();
   Cwiczenie5_4.startGame();
 }
Exemplo n.º 9
0
  public TestFrame() {
    super("Control Window");
    setLayout(new BorderLayout());
    setSize(400, 300);
    setLocation(500, 10);
    setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
    panel = new JPanel();
    getContentPane().add(panel, BorderLayout.NORTH);
    makeSHButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            makeSHButtonActionPerformed(e);
          }
        });
    panel.add(makeSHButton);

    JButton graphButton = new JButton("morph");
    graphButton.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            graphButtonActionPerformed(evt);
          }
        });
    panel.add(graphButton);

    pushAllSHButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            pushAllSHButtonActionPerformed(e);
          }
        });
    panel.add(pushAllSHButton);

    makeRelationsButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            makeRelationsButtonActionPerformed(e);
          }
        });
    panel.add(makeRelationsButton);

    panel.setPreferredSize(new java.awt.Dimension(20, 80));
    panel.setBorder(new LineBorder(Color.black));
    JFrame frame = new JFrame("Relationship Frame");
    frame.setSize(500, 500);
    frame.setLocation(10, 10);
    frame.getContentPane().add(testPanel);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
  }
Exemplo n.º 10
0
 public static void main(String[] args) {
   TableModelDemo applet = new TableModelDemo();
   JFrame frame = new JFrame();
   // EXIT_ON_CLOSE == 3
   frame.setDefaultCloseOperation(3);
   frame.setTitle("TableModelDemo");
   frame.getContentPane().add(applet, BorderLayout.CENTER);
   applet.init();
   applet.start();
   frame.setSize(500, 220);
   Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
   frame.setLocation(
       (d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
   frame.setVisible(true);
 }
  public void start() {
    menu.setMnemonic('f');
    item.setMnemonic('i');
    menu.add(item);
    bar.add(menu);

    frame.add(text);
    frame.setJMenuBar(bar);
    frame.pack();

    frame.setLocation(800, 0);
    frame.setVisible(true);

    test();
  }
Exemplo n.º 12
0
  public static void main(String[] args) {

    JFrame frame = new JFrame("Network Tables");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationRelativeTo(null);
    Display display = new Display();
    frame.getContentPane().add(display);

    frame.setLocation(0, 0);
    frame.setSize(new Dimension(2000, 700));

    frame.revalidate();
    frame.repaint();
    frame.setVisible(true);
  }
Exemplo n.º 13
0
  LoginForm() {
    setDefaultLookAndFeelDecorated(true);
    f = new JFrame("LoginForm");
    f.setSize(750, 330);
    f.setLocation(200, 200);
    f.setResizable(false);
    JPanel p = new JPanel();
    f.getContentPane().add(p);
    p.setBackground(Color.white);
    icon = new ImageIcon("img.jpg");
    image = new JLabel(icon);
    image.setSize(100, 100);
    l2 = new JLabel("�");
    t1 = new JTextField(16);
    l3 = new JLabel("Password");
    jp1 = new JPasswordField(16);
    // img = getImage(getDocumentBase(), getParameter("img"));

    b1 = new JButton("Login");
    b2 = new JButton("Reset");
    b3 = new JButton("Cancel");
    l1 = new JLabel("       SANJEEVANI HOSPITAL");
    Font fk = new Font("Algerian", Font.BOLD, 40);
    l1.setFont(fk);
    l1.setForeground(Color.RED);
    l2 = new JLabel("UserName");
    l4 = new JLabel("�                                              ");

    p.add(l1);
    p.add(l4);
    p.add(l2);

    p.add(t1);

    p.add(l3);
    p.add(jp1);

    p.add(b1);
    p.add(b2);
    p.add(b3);
    p.add(image, BorderLayout.SOUTH);
    b1.addActionListener(this);
    b2.addActionListener(this);
    b3.addActionListener(this);

    f.setVisible(true);
  }
Exemplo n.º 14
0
  public TestHTML() {
    int d = (Frame.getFrames().length == 0) ? JFrame.EXIT_ON_CLOSE : JFrame.DISPOSE_ON_CLOSE;

    JPanel pan = new JPanel();
    pan.setLayout(new BorderLayout(GAP, GAP - 4));
    pan.setBorder(new EmptyBorder(GAP, GAP, GAP, GAP));
    pan.setBackground(COL);
    pan.setFont(font);
    lab = new JLabel(MSG); // , SwingConstants.CENTER);
    lab.setName("title");
    lab.setFont(new Font("Serif", 3, 16));
    // lab.setForeground(Color.black);
    pan.add(lab, "North");

    text = new JTextArea("JTextArea\n");
    text.setName("area");
    text.setLineWrap(true);
    text.setFont(font);
    JScrollPane scr1 = new JScrollPane(text);
    scr1.setPreferredSize(new Dimension(300, 500));
    pan.add(scr1, "Center");

    html = new JEditorPane();
    html.setContentType("text/html");
    html.setEditable(false);
    html.addMouseListener(this);
    html.addMouseMotionListener(this);
    JScrollPane scr2 = new JScrollPane(html);
    scr2.setPreferredSize(new Dimension(350, 500));
    pan.add(scr2, "East");

    but = new JButton("Copy text from JTextArea to JEditorPane");
    but.addActionListener(this);
    pan.add(but, "South");

    frm = new JFrame(MSG);
    frm.setContentPane(pan);
    frm.setDefaultCloseOperation(d);
    frm.setLocation(100, 150);
    frm.pack();
    frm.setVisible(true);
  }
Exemplo n.º 15
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();
  }
Exemplo n.º 16
0
 public static void openFrame(Object frame) {
   boolean packFrame = false;
   if (packFrame) {
     ((JFrame) frame).pack();
   } else {
     ((JFrame) frame).validate();
   }
   // Center the window
   Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
   Dimension frameSize = ((JFrame) frame).getSize();
   if (frameSize.height > screenSize.height) {
     frameSize.height = screenSize.height;
   }
   if (frameSize.width > screenSize.width) {
     frameSize.width = screenSize.width;
   }
   ((JFrame) frame)
       .setLocation(
           (screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
   ((JFrame) frame).setVisible(true);
 }
Exemplo n.º 17
0
  public GUI() {
    String[] keys = {"no Quotation found"};
    if (tryDir(".") || tryDir("BLM305") || tryDir("CSE470")) keys = Q.keySet().toArray(keys);
    menu = new JComboBox<String>(keys);
    if (Q.size() > 0) setMessage(0);

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

    pan.add(topPanel(), "North");

    txt.setFont(LARGE);
    txt.setEditable(false);
    txt.setRows(5);
    txt.setColumns(30);
    txt.setWrapStyleWord(true);
    txt.setLineWrap(true);
    txt.setDragEnabled(true);
    pan.add(new JScrollPane(txt), "Center");

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

    pan.setToolTipText("A project realized collectively by the class");
    menu.setToolTipText("Quotation classes");
    who.setToolTipText("author()+year()");
    txt.setToolTipText("text()");
    ref.setToolTipText("reference()");

    frm.setContentPane(pan);
    frm.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frm.setLocation(scaled(120), scaled(90));
    frm.pack();
    frm.setVisible(true);
  }
Exemplo n.º 18
0
  public acceuil() {
    f = new JFrame("Espace Liaison FTTx");
    f.setSize(700, 700);
    c = f.getContentPane();
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    f.setLocation(dim.width / 2 - f.getWidth() / 2, dim.height / 2 - f.getHeight() / 2);
    progressbar1 = new JProgressBar();
    progressbar1.setMinimum(1);
    progressbar1.setMaximum(100);

    ImageIcon icon = new ImageIcon(".\\src\\images\\icon.png");
    ImageIcon iconc = new ImageIcon(".\\src\\images\\iconc.png");

    b1 = new JButton(icon);
    b2 = new JButton(iconc);
    p1 = new JPanel(new BorderLayout());
    p2 = new JPanel(new BorderLayout());
    p3 = new JPanel();
    lhaut = new JLabel(new ImageIcon(".\\src\\images\\telecom.jpg"));

    p1.add(lhaut, BorderLayout.NORTH);
    p2.add(progressbar1, BorderLayout.NORTH);
    p3.add(b2);
    p3.add(b1);
    p2.add(p3, BorderLayout.CENTER);
    p1.add(p2, BorderLayout.CENTER);
    c.add(p1);

    b1.addActionListener(this);
    b2.addActionListener(this);
    b1.setEnabled(false);
    b2.setEnabled(false);
    f.setResizable(false);
    f.setVisible(true);
    f.pack();
    progress();
    b1.setEnabled(true);
    b2.setEnabled(true);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
Exemplo n.º 19
0
  // If the applet is called as an application
  public static void main(String[] args) {

    // Create the frame
    mainFrame = new JFrame("Uintah User Interface");

    // Add a window listener
    mainFrame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });

    // instantiate
    UintahGui uintahGui = new UintahGui();
    uintahGui.init();

    // Add the stuff to the frame
    mainFrame.setLocation(20, 50);
    mainFrame.setContentPane(uintahGui);
    mainFrame.pack();
    mainFrame.setVisible(true);
  }
 public static void toFullScreen(
     JFrame window,
     GraphicsDevice gd,
     boolean tryAppleFullscreen,
     boolean tryExclusiveFullscreen) {
   if (appleEawtAvailable()
       && tryAppleFullscreen
       && appleOSVersion() >= 7
       && // lion and above
       javaVersion() >= 7) { // java 7 and above
     System.out.println("trying to apple fullscreen");
     enableAppleFullscreen(window);
     doAppleFullscreen(window);
   } else if (appleEawtAvailable()
       && // Snow Leopard and below OR apple java 6 and below TODO: test this on SL
       tryExclusiveFullscreen
       && gd.isFullScreenSupported()) {
     if (javaVersion() >= 7) setAutoRequestFocus(window, true);
     window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     window.setUndecorated(true);
     // window.setExtendedState(JFrame.MAXIMIZED_BOTH);
     gd.setFullScreenWindow(window);
     window.toFront();
     Rectangle r = gd.getDefaultConfiguration().getBounds();
     window.setBounds(r);
     // window.pack();
   } else { // Windows and Linux TODO: test this
     window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     window.setUndecorated(true);
     window.setSize(gd.getDisplayMode().getWidth(), gd.getDisplayMode().getHeight());
     window.setLocation(0, 0);
     window.setExtendedState(JFrame.MAXIMIZED_BOTH);
     window.toFront();
   }
   window.pack();
   window.setVisible(true);
 }
Exemplo n.º 21
0
  public CheckerBoard(JLabel status, final JFrame frame) {
    // creates border around the court area, JComponent method
    setBorder(BorderFactory.createLineBorder(Color.BLACK));
    frame.add(this, BorderLayout.CENTER);
    frame.setLocation(300, 0);
    frame.setTitle("Vivek A. Raj's Checker's Game!");
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    doubleJumpSpots = new ArrayList<Tuple<Integer, Integer>>();
    reset();

    // The timer is an object which triggers an action periodically
    // with the given INTERVAL. One registers an ActionListener with
    // this timer, whose actionPerformed() method will be called
    // each time the timer triggers. We define a helper method
    // called tick() that actually does everything that should
    // be done in a single timestep.
    Timer timer =
        new Timer(
            INTERVAL,
            new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                tick();
              }
            });
    timer.start(); // MAKE SURE TO START THE TIMER!

    allowMouse();

    // this key listener allows the square to move as long
    // as an arrow key is pressed, by changing the square's
    // velocity accordingly. (The tick method below actually
    // moves the square.)

    this.status = status;
  }
Exemplo n.º 22
0
 /**
  * _more_
  *
  * @return _more_
  */
 private boolean windowOk() {
   getContents();
   if (contents == null) {
     return false;
   }
   if (shouldMakeDialog()) {
     if (dialog == null) {
       dialog = new JDialog((Frame) null, getWindowTitle(), false);
       LogUtil.registerWindow(dialog);
       GuiUtils.packDialog(dialog, contents);
       dialog.setLocation(100, 100);
       window = dialog;
     }
   } else {
     if (frame == null) {
       frame = new JFrame(getWindowTitle());
       if (menuBar != null) {
         GuiUtils.decorateFrame(frame, menuBar);
       }
       LogUtil.registerWindow(frame);
       frame.getContentPane().add(contents);
       frame.pack();
       Msg.translateTree(frame);
       frame.setLocation(100, 100);
       window = frame;
     }
   }
   if (window != null) {
     window.addWindowListener(
         new WindowAdapter() {
           public void windowClosing(WindowEvent e) {
             windowIsClosing();
           }
         });
   }
   return window != null;
 }
Exemplo n.º 23
0
  private static void constructFrame() {
    final JFrame lFrame = new JFrame((String) viewModel.get("string.title"));
    lFrame.setIconImage((Image) viewModel.get("image.crab"));

    // Install the closing mechanism on the frame when the user
    // wants to close the frame by clicking the X button.
    lFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    lFrame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            final ExitAction lExitAction = (ExitAction) viewModel.get("action.exit");
            if (lExitAction != null) {
              // If there is an exit action defined, we use this action.
              // It will have the same effect as calling the exit menu item.
              lExitAction.actionPerformed(new ActionEvent(lFrame, 0, "exit"));
            } else {
              // If the exit action is not available, we will close the frame anyhow.
              lFrame.dispose();
            }
          }
        });

    // Calculate the middle of the screen.
    final Rectangle lScreenRect =
        GraphicsEnvironment.getLocalGraphicsEnvironment()
            .getDefaultScreenDevice()
            .getDefaultConfiguration()
            .getBounds();
    // Using the 'golden ratio' 1.618 for the width/height ratio.
    final Rectangle lFrameRect =
        new Rectangle(Math.min(647, lScreenRect.width), Math.min(400, lScreenRect.height));
    // Set the window size and location.
    lFrame.setLocation(
        (lScreenRect.width - lFrameRect.width) / 2, (lScreenRect.height - lFrameRect.height) / 2);
    lFrame.setSize(lFrameRect.width, lFrameRect.height);
    viewModel.put("window.frame", lFrame);
  }
Exemplo n.º 24
0
 private void initializeGUI() {
   frame = new JFrame("bug4523758");
   tools = new JToolBar();
   frame.getContentPane().add(tools, BorderLayout.NORTH);
   combo =
       new JComboBox(
           new Object[] {"Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet"});
   combo.addItemListener(
       new ItemListener() {
         public void itemStateChanged(ItemEvent event) {
           itemStateChanged = true;
           synchronized (itemLock) {
             try {
               itemLock.notifyAll();
             } catch (Exception e) {
             }
           }
         }
       });
   tools.add(combo);
   frame.setSize(250, 400);
   frame.setLocation(700, 0);
   frame.setVisible(true);
 }
Exemplo n.º 25
0
  public ODEWizardScalaSci() {
    editingClassName = "Lorenz";
    systemOrder = 3; // the order of ODE system

    copyTemplateButton =
        new JButton("1. Copy and Edit Template", new ImageIcon("/scalaLab.jar/yellow-ball.gif"));
    generateEditingButton = new JButton("2. Generate Java Class", new ImageIcon("./blue-ball.gif"));
    saveJavaClassButton =
        new JButton("3. Save Java Class", new ImageIcon("scalaLab.jar/red-ball.gif"));
    compileJavaClassButton =
        new JButton("4.a. Java Compile - External Compiler", new ImageIcon("blue-ball.gif"));
    compileJavaInternalCompilerButton =
        new JButton("4.b. Java Compile - Internal Compiler", new ImageIcon("blue-ball.gif"));
    generateScriptCodeButton =
        new JButton("Generate scalaSci Script", new ImageIcon("red-ball.gif"));

    ODEWizardFrame = new JFrame("ODE Wizard for scalaSci with Java implementation of. ODEs");

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

    paramPanel = new JPanel(new GridLayout(1, 4));
    availODEMethods.add("ODErke");
    availODEMethods.add("ODEmultistep");
    availODEMethods.add("ODEdiffsys");
    ODEselectMethodLabel = new JLabel("ODE method: ");
    ODEselectMethodComboBox = new JComboBox(availODEMethods);
    ODEselectMethodComboBox.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            ODESolveMethod = ODEselectMethodComboBox.getSelectedIndex();
            updateTemplateText();
            templateTextArea.setText(templateText);
            currentlySelectedLabel.setText(
                "Selected Method: " + (String) availODEMethods.get(ODESolveMethod));
          }
        });

    JLabel javaFileTextLabel = new JLabel("Java File Name: ");
    javaFileTextBox = new JTextField(editingClassName);
    javaFileTextBox.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            editingClassName = javaFileTextBox.getText();
            String updatedStatusText = prepareStatusText();
            statusAreaTop.setText(updatedStatusText);
          }
        });

    JLabel systemOrderLabel = new JLabel("System order: ");
    systemOrderText = new JTextField(String.valueOf(systemOrder));
    systemOrderText.addActionListener(new editSystemOrder());
    JPanel javaFilePanel = new JPanel();
    javaFilePanel.add(javaFileTextLabel);
    javaFilePanel.add(javaFileTextBox);
    JPanel systemOrderPanel = new JPanel();
    systemOrderPanel.add(systemOrderLabel);
    systemOrderPanel.add(systemOrderText);

    paramMethodPanel = new JPanel();
    paramMethodPanel.add(ODEselectMethodLabel);
    paramMethodPanel.add(ODEselectMethodComboBox);
    paramPanel.add(paramMethodPanel);
    paramPanel.add(javaFilePanel);
    paramPanel.add(systemOrderPanel);
    currentlySelectedLabel =
        new JLabel("Selected Method: " + (String) availODEMethods.get(ODESolveMethod));
    paramPanel.add(currentlySelectedLabel);

    statusPanel = new JPanel(new GridLayout(2, 1));
    statusAreaTop = new JTextArea();
    statusAreaTop.setFont(new Font("Arial", Font.BOLD, 16));
    String statusText = prepareStatusText();

    statusAreaTop.setText(statusText);
    statusAreaBottom = new JTextArea();
    statusAreaBottom.setText(
        "Step1:  Copy and edit the template ODE  (implements the famous Lorenz chaotic system),\n"
            + "Then set the name of your Java Class (instead of \"Lorenz\"),  without the extension .java\n"
            + "Also set the proper order (i.e. number of equations and variables) of your system. ");
    statusPanel.add(statusAreaTop);
    statusPanel.add(statusAreaBottom);

    templateTextArea = new JTextArea();
    updateTemplateText();

    templateTextArea.setFont(new Font("Arial", Font.ITALIC, 12));
    templateTextArea.setText(templateText);
    templateScrollPane = new JScrollPane();
    templateViewPort = templateScrollPane.getViewport();
    templateViewPort.add(templateTextArea);

    ODEWizardTextArea = new JTextArea();
    ODEWizardText = "";
    ODEWizardTextArea.setText(ODEWizardText);
    ODEWizardTextArea.setFont(new Font("Arial", Font.BOLD, 12));

    ODEWizardScrollPane = new JScrollPane();
    wizardViewPort = ODEWizardScrollPane.getViewport();
    wizardViewPort.add(ODEWizardTextArea);

    editPanel.add(ODEWizardScrollPane);
    editPanel.add(templateScrollPane);

    // Step 1: copy template of ODE implementation from the
    // templateTextArea to ODEWizardTextArea
    copyTemplateButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            ODEWizardTextArea.setText(templateTextArea.getText());
            generateEditingButton.setEnabled(true);
            statusAreaBottom.setText(
                "Step2:  If you have implemented correctly your ODE, the wizard completes the ready to compile Java class");
          }
        });

    // Step 2: generate Java Class from template
    JPanel buttonPanel = new JPanel();
    generateEditingButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            String editingODE = ODEWizardTextArea.getText();
            String classImplementationString = // "package javaPluggins; \n"+
                "import  numal.*; \n\n"
                    + "public class "
                    + editingClassName
                    + " extends Object \n             implements "
                    + implementingInterfaces[ODESolveMethod]
                    + " \n \n "
                    + "{ \n";

            classImplementationString += (editingODE + "}\n");

            ODEWizardTextArea.setText(classImplementationString);
            saveJavaClassButton.setEnabled(true);
            statusAreaBottom.setText(
                "Step3:  The generated Java source is ready, you can check it, and then proceed to save.");
          }
        });

    // Step 3: save generated Java Class on disk
    saveJavaClassButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            String currentWorkingDirectory = Directory.Current().get().path();
            JFileChooser chooser = new JFileChooser(currentWorkingDirectory);
            chooser.setSelectedFile(new File(editingClassName + ".java"));
            int ret = chooser.showSaveDialog(ODEWizardFrame);

            if (ret != JFileChooser.APPROVE_OPTION) {
              return;
            }
            File f = chooser.getSelectedFile();
            try {
              PrintWriter out = new PrintWriter(f);
              String javaCodeText = ODEWizardTextArea.getText();
              out.write(javaCodeText);
              out.close();
              // update the notion  of the working directory
              String fullPathOfSavedFile = f.getAbsolutePath();
              GlobalValues.workingDir =
                  fullPathOfSavedFile.substring(
                      0, fullPathOfSavedFile.lastIndexOf(File.separatorChar) + 1);

              compileJavaClassButton.setEnabled(true);
              compileJavaInternalCompilerButton.setEnabled(true);
              statusAreaBottom.setText(
                  "Step4:  The Java source file was saved to disk,  \n "
                      + "you can proceed to compile and load the corresponding class file");
            } catch (java.io.FileNotFoundException enf) {
              System.out.println("File " + f.getName() + " not found");
              enf.printStackTrace();
            } catch (Exception eOther) {
              System.out.println("Exception trying to create PrintWriter");
              eOther.printStackTrace();
            }
          }
        });

    // Step 4: Compile the generated Java class
    compileJavaClassButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            String currentWorkingDirectory = GlobalValues.workingDir;
            JFileChooser chooser = new JFileChooser(currentWorkingDirectory);
            int ret = chooser.showOpenDialog(ODEWizardFrame);

            if (ret != JFileChooser.APPROVE_OPTION) {
              return;
            }
            File f = chooser.getSelectedFile();
            String javaFile = null;
            try {
              javaFile = f.getCanonicalPath();
            } catch (IOException ex) {
              System.out.println("I/O Exception in getCanonicalPath");
              ex.printStackTrace();
            }

            //   extract the path specification of the generated Java class that implements the ODE
            // solution method,
            //    in order to update the ScalaSci class path
            String SelectedFileWithPath = f.getAbsolutePath();
            String SelectedFilePathOnly =
                SelectedFileWithPath.substring(
                    0, SelectedFileWithPath.lastIndexOf(File.separatorChar));

            if (GlobalValues.ScalaSciClassPath.length() == 0) GlobalValues.ScalaSciClassPath = ".";
            if (GlobalValues.ScalaSciClassPath.indexOf(SelectedFilePathOnly) == -1) {
              GlobalValues.ScalaSciClassPathComponents.add(0, SelectedFilePathOnly);
              GlobalValues.ScalaSciClassPath =
                  GlobalValues.ScalaSciClassPath + File.pathSeparator + SelectedFilePathOnly;
            }
            // update also the ScalaSciClassPath property
            StringBuilder fileStr = new StringBuilder();
            Enumeration enumDirs = GlobalValues.ScalaSciClassPathComponents.elements();
            while (enumDirs.hasMoreElements()) {
              Object ce = enumDirs.nextElement();
              fileStr.append(File.pathSeparator + (String) ce);
            }
            GlobalValues.settings.setProperty("ScalaSciClassPath", fileStr.toString());

            ClassLoader parentClassLoader = getClass().getClassLoader();
            GlobalValues.extensionClassLoader =
                new ExtensionClassLoader(GlobalValues.ScalaSciClassPath, parentClassLoader);

            // update GUI components to account for the updated ScalaSci classpath
            scalaExec.scalaLab.scalaLab.updateTree();

            boolean compilationSucccess = true;

            String tempFileName = "";
            tempFileName =
                javaFile + ".java"; // public classes and Java files should have the same name

            String[] command = new String[6];
            command[0] = "javac";
            command[1] = "-cp";
            command[2] = GlobalValues.jarFilePath + File.pathSeparator + GlobalValues.homeDir;
            command[3] = "-d"; // where to place output class files
            command[4] = SelectedFilePathOnly; //  the path to save the compiled class files
            command[5] = javaFile; // full filename to compile

            String compileCommandString =
                command[0]
                    + "  "
                    + command[1]
                    + "  "
                    + command[2]
                    + " "
                    + command[3]
                    + " "
                    + command[4]
                    + " "
                    + command[5];

            System.out.println("compileCommand Java= " + compileCommandString);

            try {
              Runtime rt = Runtime.getRuntime();
              Process javaProcess = rt.exec(command);
              // an error message?
              StreamGobbler errorGobbler = new StreamGobbler(javaProcess.getErrorStream(), "ERROR");

              // any output?
              StreamGobbler outputGobbler =
                  new StreamGobbler(javaProcess.getInputStream(), "OUTPUT");

              // kick them off
              errorGobbler.start();
              outputGobbler.start();

              // any error???
              javaProcess.waitFor();
              int rv = javaProcess.exitValue();
              String commandString = command[0] + "  " + command[1] + "  " + command[2];
              if (rv == 0) {
                System.out.println("Process:  " + commandString + "  exited successfully ");
                generateScriptCodeButton.setEnabled(true);
                statusAreaBottom.setText(
                    "Step5:  You can proceed now to create a draft script that utilizes your Java-based  ODE integrator");
              } else
                System.out.println(
                    "Process:  " + commandString + "  exited with error, error value = " + rv);

            } catch (IOException exio) {
              System.out.println("IOException trying to executing " + command);
              exio.printStackTrace();

            } catch (InterruptedException ie) {
              System.out.println("Interrupted Exception  trying to executing " + command);
              ie.printStackTrace();
            }
          }
        });

    // Compile with the internal compiler
    compileJavaInternalCompilerButton.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            String currentWorkingDirectory = GlobalValues.workingDir;
            JFileChooser chooser = new JFileChooser(currentWorkingDirectory);
            int ret = chooser.showOpenDialog(ODEWizardFrame);

            if (ret != JFileChooser.APPROVE_OPTION) {
              return;
            }
            File f = chooser.getSelectedFile();
            String javaFile = null;
            try {
              javaFile = f.getCanonicalPath();
            } catch (IOException ex) {
              System.out.println("I/O Exception in getCanonicalPath");
              ex.printStackTrace();
            }

            //   extract the path specification of the generated Java class that implements the ODE
            // solution method,
            //    in order to update the ScalaSci class path
            String SelectedFileWithPath = f.getAbsolutePath();
            String SelectedFilePathOnly =
                SelectedFileWithPath.substring(
                    0, SelectedFileWithPath.lastIndexOf(File.separatorChar));

            if (GlobalValues.ScalaSciClassPath.length() == 0) GlobalValues.ScalaSciClassPath = ".";
            if (GlobalValues.ScalaSciClassPath.indexOf(SelectedFilePathOnly) == -1) {
              GlobalValues.ScalaSciClassPathComponents.add(0, SelectedFilePathOnly);
              GlobalValues.ScalaSciClassPath =
                  GlobalValues.ScalaSciClassPath + File.pathSeparator + SelectedFilePathOnly;
            }
            // update also the ScalaSciClassPath property
            StringBuilder fileStr = new StringBuilder();
            Enumeration enumDirs = GlobalValues.ScalaSciClassPathComponents.elements();
            while (enumDirs.hasMoreElements()) {
              Object ce = enumDirs.nextElement();
              fileStr.append(File.pathSeparator + (String) ce);
            }
            GlobalValues.settings.setProperty("ScalaSciClassPath", fileStr.toString());

            ClassLoader parentClassLoader = getClass().getClassLoader();
            GlobalValues.extensionClassLoader =
                new ExtensionClassLoader(GlobalValues.ScalaSciClassPath, parentClassLoader);

            // update GUI components to account for the updated ScalaSci classpath
            scalaExec.scalaLab.scalaLab.updateTree();

            String[] command = new String[11];
            String toolboxes = "";
            for (int k = 0; k < GlobalValues.ScalaSciClassPathComponents.size(); k++)
              toolboxes =
                  toolboxes
                      + File.pathSeparator
                      + GlobalValues.ScalaSciClassPathComponents.elementAt(k);

            // compile the temporary file
            command[0] = "java";
            command[1] = "-classpath";
            command[2] =
                "."
                    + File.pathSeparator
                    + GlobalValues.jarFilePath
                    + File.pathSeparator
                    + toolboxes
                    + File.pathSeparator
                    + SelectedFilePathOnly;
            command[3] = "com.sun.tools.javac.Main"; // the name of the Java  compiler class
            command[4] = "-classpath";
            command[5] = command[2];
            command[6] = "-sourcepath";
            command[7] = command[2];
            command[8] = "-d"; // where to place output class files
            command[9] = SelectedFilePathOnly;
            command[10] = SelectedFileWithPath;
            String compileCommandString =
                command[0]
                    + "  "
                    + command[1]
                    + "  "
                    + command[2]
                    + " "
                    + command[3]
                    + " "
                    + command[4]
                    + " "
                    + command[5]
                    + " "
                    + command[6]
                    + " "
                    + command[7]
                    + " "
                    + command[8]
                    + " "
                    + command[9]
                    + " "
                    + command[10];

            System.out.println("compileCommand Java= " + compileCommandString);

            try {
              Runtime rt = Runtime.getRuntime();
              Process javaProcess = rt.exec(command);
              // an error message?
              StreamGobbler errorGobbler = new StreamGobbler(javaProcess.getErrorStream(), "ERROR");

              // any output?
              StreamGobbler outputGobbler =
                  new StreamGobbler(javaProcess.getInputStream(), "OUTPUT");

              // kick them off
              errorGobbler.start();
              outputGobbler.start();

              // any error???
              javaProcess.waitFor();
              int rv = javaProcess.exitValue();
              if (rv == 0) {
                System.out.println("Process:  exited successfully ");

                JavaCompile javaCompileObj = null;
                try {
                  javaCompileObj = new JavaCompile();
                } catch (Exception ex) {
                  JOptionPane.showMessageDialog(
                      null,
                      "Unable to compile. Please check if your system's PATH variable includes the path to your javac compiler",
                      "Cannot compile - Check PATH",
                      JOptionPane.INFORMATION_MESSAGE);
                  ex.printStackTrace();
                }
                generateScriptCodeButton.setEnabled(true);
                statusAreaBottom.setText(
                    "Step5:  You can proceed now to create a draft ScalaSci-Script that utilizes your Java-based  ODE integrator");

              } else System.out.println("Process:  exited with error, error value = " + rv);

            } catch (IOException exio) {
              System.out.println("IOException trying to executing " + command);
              exio.printStackTrace();

            } catch (InterruptedException ie) {
              System.out.println("Interrupted Exception  trying to executing " + command);
              ie.printStackTrace();
            }
          }
        });

    // Step 5: Generate Script Code
    generateScriptCodeButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            new scriptCodeGenerationFrame("ODE Script code", editingClassName, systemOrder);
          }
        });

    buttonPanel.add(copyTemplateButton); // Step 1
    buttonPanel.setEnabled(true);
    buttonPanel.add(generateEditingButton); // Step 2
    generateEditingButton.setEnabled(false);
    buttonPanel.add(saveJavaClassButton); // Step 3
    saveJavaClassButton.setEnabled(false);
    buttonPanel.add(compileJavaClassButton); // Step 4
    buttonPanel.add(compileJavaInternalCompilerButton);
    compileJavaClassButton.setEnabled(false);
    compileJavaInternalCompilerButton.setEnabled(false);
    buttonPanel.add(generateScriptCodeButton); // Step 5
    generateScriptCodeButton.setEnabled(false);

    ODEWizardFrame.add(buttonPanel, BorderLayout.NORTH);
    ODEWizardFrame.add(editPanel, BorderLayout.CENTER);
    JPanel bottomPanel = new JPanel(new GridLayout(2, 1));

    bottomPanel.add(paramPanel);
    bottomPanel.add(statusPanel);
    ODEWizardFrame.add(bottomPanel, BorderLayout.SOUTH);
    ODEWizardFrame.setLocation(100, 100);
    ODEWizardFrame.setSize(1400, 800);
    ODEWizardFrame.setVisible(true);
  }
Exemplo n.º 26
0
  public void initUI() {
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
      JPopupMenu.setDefaultLightWeightPopupEnabled(false);
      frame = new JFrame("Vestige-x Developers Client");
      frame.setIconImage(
          Toolkit.getDefaultToolkit().getImage(signlink.findcachedir() + "Cursor.png"));
      frame.setLayout(new BorderLayout());
      frame.setResizable(false);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      JPanel gamePanel = new JPanel();
      gamePanel.setLayout(new BorderLayout());
      gamePanel.add(this);
      Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
      int w = 765;
      int h = 503;
      int x = (dim.width - w) / 2;
      int y = (dim.height - h) / 2;
      frame.setLocation(x, y);
      gamePanel.setPreferredSize(new Dimension(765, 503));
      JMenu fileMenu = new JMenu("  File  ");
      JMenu toolMenu = new JMenu("  Tools  ");
      JMenu infoMenu = new JMenu("  Info  ");
      JMenu toggleMenu = new JMenu("  Toggles  ");
      JMenu profileMenu = new JMenu("  Links  ");
      JButton shotMenu = new JButton("Take Screenshot");
      shotMenu.setActionCommand("Screenshot");
      shotMenu.addActionListener(this);
      String[] mainButtons = new String[] {"View Images", "Exit"};
      String[] toolButtons = new String[] {"World Map"};
      String[] infoButtons = new String[] {"Client Information", "Support"};
      String[] toggleButtons = new String[] {"Toggle 10x Damage", "Untoggle 10x Damage"};
      String[] profileButtons =
          new String[] {"Donate", "Vote", "-", "Highscores", "Guides", "YouTube", "Forums"};

      for (String name : mainButtons) {
        JMenuItem menuItem = new JMenuItem(name);
        if (name.equalsIgnoreCase("-")) {
          fileMenu.addSeparator();
        } else {
          menuItem.addActionListener(this);
          fileMenu.add(menuItem);
        }
      }
      for (String name : toolButtons) {
        JMenuItem menuItem = new JMenuItem(name);
        if (name.equalsIgnoreCase("-")) toolMenu.addSeparator();
        else {
          menuItem.addActionListener(this);
          toolMenu.add(menuItem);
        }
      }

      for (String name : infoButtons) {
        JMenuItem menuItem = new JMenuItem(name);
        if (name.equalsIgnoreCase("-")) infoMenu.addSeparator();
        else {
          menuItem.addActionListener(this);
          infoMenu.add(menuItem);
        }
      }
      for (String name : toggleButtons) {
        JMenuItem menuItem = new JMenuItem(name);
        if (name.equalsIgnoreCase("-")) toggleMenu.addSeparator();
        else {
          menuItem.addActionListener(this);
          toggleMenu.add(menuItem);
        }
      }
      for (String name : profileButtons) {
        JMenuItem menuItem = new JMenuItem(name);
        if (name.equalsIgnoreCase("-")) toggleMenu.addSeparator();
        else {
          menuItem.addActionListener(this);
          profileMenu.add(menuItem);
        }
      }
      JMenuBar menuBar = new JMenuBar();
      JMenuBar jmenubar = new JMenuBar();

      frame.add(jmenubar);
      menuBar.add(fileMenu);
      menuBar.add(toolMenu);
      menuBar.add(infoMenu);
      // menuBar.add(toggleMenu);
      menuBar.add(profileMenu);
      menuBar.add(shotMenu);
      frame.getContentPane().add(menuBar, BorderLayout.NORTH);
      frame.getContentPane().add(gamePanel, BorderLayout.CENTER);
      frame.pack();

      frame.setVisible(true); // can see the client
      frame.setResizable(false); // resizeable frame
      init();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 27
0
  /**
   * Inizialize frame components
   *
   * @throws CMSException
   * @throws FileNotFoundException
   * @throws IOException
   * @throws GeneralSecurityException
   */
  private void initComponents()
      throws CMSException, FileNotFoundException, IOException, GeneralSecurityException {

    // *********************************

    panel4 = new JPanel();
    label2 = new JLabel();
    textPane1 = new JTextPane();
    panel5 = new JPanel();
    textArea1 = new JTextArea();
    textArea2 = new JTextArea();

    progressBar = new JProgressBar();

    textPane2 = new JTextPane();
    textField1 = new JTextField();
    button1 = new JButton();
    panel6 = new JPanel();
    button2 = new JButton();
    button3 = new JButton();
    button4 = new JButton();
    GridBagConstraints gbc;
    // ======== this ========
    Container contentPane = getContentPane();
    contentPane.setLayout(new GridBagLayout());
    ((GridBagLayout) contentPane.getLayout()).columnWidths = new int[] {165, 0, 0};
    ((GridBagLayout) contentPane.getLayout()).rowHeights = new int[] {105, 50, 0};
    ((GridBagLayout) contentPane.getLayout()).columnWeights = new double[] {0.0, 1.0, 1.0E-4};
    ((GridBagLayout) contentPane.getLayout()).rowWeights = new double[] {1.0, 0.0, 1.0E-4};

    // ======== panel4 ========
    {
      panel4.setBackground(Color.white);
      panel4.setLayout(new GridBagLayout());
      ((GridBagLayout) panel4.getLayout()).columnWidths = new int[] {160, 0};
      ((GridBagLayout) panel4.getLayout()).rowHeights = new int[] {0, 0, 0};
      ((GridBagLayout) panel4.getLayout()).columnWeights = new double[] {0.0, 1.0E-4};
      ((GridBagLayout) panel4.getLayout()).rowWeights = new double[] {1.0, 1.0, 1.0E-4};

      // ---- label2 ----
      label2.setIcon(
          new ImageIcon(
              "images" + System.getProperty("file.separator") + "logo-freesigner-piccolo.png"));
      gbc = new GridBagConstraints();
      gbc.gridx = 0;
      gbc.gridy = 0;
      gbc.fill = GridBagConstraints.HORIZONTAL;
      gbc.insets.bottom = 5;
      panel4.add(label2, gbc);

      // ---- textPane1 ----
      textPane1.setFont(new Font("Verdana", Font.BOLD, 12));
      textPane1.setText("Lettura\ncertificati\nda token");
      textPane1.setEditable(false);
      gbc = new GridBagConstraints();
      gbc.gridx = 0;
      gbc.gridy = 1;
      gbc.anchor = GridBagConstraints.NORTHWEST;
      panel4.add(textPane1, gbc);
    }
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.insets.bottom = 5;
    gbc.insets.right = 5;
    contentPane.add(panel4, gbc);

    // ======== panel5 ========
    {
      panel5.setBackground(Color.white);
      panel5.setLayout(new GridBagLayout());
      ((GridBagLayout) panel5.getLayout()).columnWidths = new int[] {0, 205, 0, 0};
      ((GridBagLayout) panel5.getLayout()).rowHeights = new int[] {100, 0, 30, 30, 0};
      ((GridBagLayout) panel5.getLayout()).columnWeights = new double[] {1.0, 0.0, 1.0, 1.0E-4};
      ((GridBagLayout) panel5.getLayout()).rowWeights = new double[] {0.0, 0.0, 1.0, 1.0, 1.0E-4};

      // ---- textArea1 ----
      textArea1.setFont(new Font("Verdana", Font.BOLD, 14));
      textArea1.setText("Lettura certificati da token");
      textArea1.setEditable(false);
      gbc = new GridBagConstraints();
      gbc.gridx = 0;
      gbc.gridy = 0;
      gbc.gridwidth = 3;
      gbc.fill = GridBagConstraints.VERTICAL;
      gbc.insets.bottom = 5;
      panel5.add(textArea1, gbc);

      // ---- textArea2 ----
      textArea2.setFont(new Font("Verdana", Font.PLAIN, 12));
      textArea2.setText("Ricerca certificati...\n");
      textArea2.setEditable(false);
      textArea2.setColumns(30);
      gbc = new GridBagConstraints();
      gbc.gridx = 0;
      gbc.gridy = 1;
      gbc.gridwidth = 3;
      gbc.fill = GridBagConstraints.BOTH;
      panel5.add(textArea2, gbc);
      progressBar.setValue(0);
      progressBar.setMaximum(1);
      progressBar.setStringPainted(true);
      progressBar.setBounds(0, 0, 300, 150);

      gbc = new GridBagConstraints();
      gbc.gridx = 0;
      gbc.gridy = 2;
      gbc.fill = GridBagConstraints.HORIZONTAL;
      gbc.insets.bottom = 5;
      gbc.insets.right = 5;
      gbc.gridwidth = 3;
      panel5.add(progressBar, gbc);
    }
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.insets.bottom = 5;
    contentPane.add(panel5, gbc);

    // ======== panel6 ========
    {
      panel6.setBackground(Color.white);
      panel6.setLayout(new GridBagLayout());
      ((GridBagLayout) panel6.getLayout()).columnWidths = new int[] {0, 0, 0, 0};
      ((GridBagLayout) panel6.getLayout()).rowHeights = new int[] {0, 0};
      ((GridBagLayout) panel6.getLayout()).columnWeights = new double[] {1.0, 1.0, 1.0, 1.0E-4};
      ((GridBagLayout) panel6.getLayout()).rowWeights = new double[] {1.0, 1.0E-4};

      // ---- button2 ----
      button2.setText("Indietro");
      gbc = new GridBagConstraints();
      gbc.gridx = 0;
      gbc.gridy = 0;
      gbc.insets.right = 5;
      button2.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {

              frame.hide();

              FreeSignerSignApplet nuovo = new FreeSignerSignApplet();
            }
          });

      // panel6.add(button2, gbc);

      // ---- button4 ----
      button4.setText("Annulla");
      gbc = new GridBagConstraints();
      gbc.gridx = 2;
      gbc.gridy = 0;
      // panel6.add(button4, gbc);
    }
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 1;
    gbc.fill = GridBagConstraints.BOTH;
    contentPane.add(panel6, gbc);
    contentPane.setBackground(Color.white);
    frame = new JFrame();
    frame.setContentPane(contentPane);
    frame.setTitle("Freesigner");
    frame.setSize(300, 150);
    frame.setResizable(false);
    frame.pack();
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setLocation((d.width - frame.getWidth()) / 2, (d.height - frame.getHeight()) / 2);

    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });
    timer =
        new Timer(
            10,
            new ActionListener() {

              public void actionPerformed(ActionEvent evt) {
                frame.show();
                if (task.getMessage() != null) {
                  String s = new String();
                  s = task.getMessage();
                  s = s.substring(0, Math.min(60, s.length()));

                  textArea2.setText(s + " ");
                  progressBar.setValue(task.getStatus());
                }
                if (task.isDone()) {
                  timer.stop();

                  // Finalizzo la cryptoki, onde evitare
                  // successivi errori PKCS11 "cryptoki alreadi initialized"

                  if ((task != null)) task.libFinalize();

                  ArrayList slotInfos = task.getSlotInfos();
                  if ((slotInfos == null) || slotInfos.isEmpty()) {

                    frame.show();

                    JOptionPane.showMessageDialog(
                        frame,
                        "Controllare la presenza sul sistema\n"
                            + "della libreria PKCS11 impostata.",
                        "Nessun lettore rilevato",
                        JOptionPane.WARNING_MESSAGE);

                    frame.hide();

                  } else {
                    String st = task.getCRLerror();

                    if (st.length() > 0) {
                      timer.stop();

                      JOptionPane.showMessageDialog(
                          frame,
                          "C'è stato un errore nella verifica CRL.\n" + st,
                          "Errore verifica CRL",
                          JOptionPane.ERROR_MESSAGE);
                      frame.hide();
                      FreeSignerSignApplet nuovo = new FreeSignerSignApplet();
                    }
                    if (task.getDifferentCerts() == 0) {
                      if (task.getCIr() != null) {
                        JOptionPane.showMessageDialog(
                            frame,
                            "La carta "
                                + task.getCardDescription()
                                + " nel lettore "
                                + conf.getReader()
                                + " non contiene certificati",
                            "Attenzione",
                            JOptionPane.WARNING_MESSAGE);

                      } else
                        JOptionPane.showMessageDialog(
                            frame, task.getMessage(), "Errore:", JOptionPane.ERROR_MESSAGE);
                    }

                    frame.hide();

                    // confFrame.createTreeAndTokenNodes(task.getSlotInfos());

                  }
                }
              }
            });
  }
Exemplo n.º 28
0
  public ShowResults(SharkPanel _sp, String _files[], double _scores[], int _nrpairs[]) {
    sp = _sp;
    files = _files;
    scores = _scores;
    nrpairs = _nrpairs;
    LogFile lf = new LogFile("SearchResults_");
    DefaultListModel listModel = new DefaultListModel();
    for (int i = 0; i < files.length; i++) {
      GetImageFile gif = new GetImageFile(files[i]);
      Integer ii = new Integer(_nrpairs[i]);
      int tmpval = (int) (1000.0 * _scores[i]);
      Double dd = new Double((double) tmpval / 1000.0);
      String tmp = gif.getImageString();
      String s =
          tmp.substring(tmp.lastIndexOf('\\') + 1, tmp.length())
              + "\t"
              + ii.toString()
              + "\t"
              + dd.toString();
      String ddval = dd.toString();
      while (ddval.length() < 5) ddval += "0";
      if (i < 9)
        listModel.addElement(
            "  "
                + (i + 1)
                + ".  "
                + ddval
                + "   "
                + tmp.substring(tmp.lastIndexOf('\\') + 1, tmp.length()));
      else
        listModel.addElement(
            (i + 1)
                + ".  "
                + ddval
                + "   "
                + tmp.substring(tmp.lastIndexOf('\\') + 1, tmp.length()));
      lf.write(s);
    }
    lf.close();

    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    list = new JList(listModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setDragEnabled(false);
    list.addMouseListener(new MouseClickListener());

    JScrollPane listView = new JScrollPane(list);
    listView.setPreferredSize(new Dimension(250, 250));

    showButton = new JButton("Visual comparison");
    showButton.addActionListener(this);
    showButton.setMnemonic('V');
    showButton.setEnabled(false);

    JButton closeButton = new JButton("Close");
    closeButton.addActionListener(this);
    closeButton.setMnemonic('C');

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
    panel.add(listView, BorderLayout.CENTER);
    panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    JPanel panel2 = new JPanel();
    panel2.setLayout(new BoxLayout(panel2, BoxLayout.X_AXIS));
    panel2.add(showButton);
    panel2.add(Box.createRigidArea(new Dimension(10, 1)));
    panel2.add(closeButton);

    add(panel);
    add(Box.createRigidArea(new Dimension(1, 10)));
    add(panel2);

    if (frame != null) frame.dispose();
    frame = new JFrame("I3S: Search results");
    frame.setContentPane(this);
    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            frame.dispose();
            frame = null;
          }
        });
    frame.setSize(new Dimension(400, 300));
    frame.setLocation(200, 200);

    ImageIcon imageIcon = new ImageIcon(this.getClass().getResource("/Simages/icon.gif"));
    frame.setIconImage(imageIcon.getImage());

    frame.pack();
    frame.setVisible(true);
  }
Exemplo n.º 29
0
  // --------------------------------initGUI------------------------------------
  public void initGUI() {
    bDeployed = bOpponentDeployed = false;
    listAT = new LinkedList();

    frame.setJMenuBar(new GameMenuBar(this));
    panParty = new PartyPanel(200, 480);
    panStatus = new JPanel(null);
    oMap = new Map(600, 350);
    panChat = new ChatPanel(600, 200);

    Container contentPane = frame.getContentPane();

    panParty.setOpaque(true);
    panStatus.setOpaque(true);
    panChat.setOpaque(true);

    panStatus.setPreferredSize(new Dimension(200, 70));

    contentPane.add(panStatus);
    contentPane.add(panParty);
    contentPane.add(oMap);
    contentPane.add(panChat);

    SpringLayout oLayout = new SpringLayout();
    contentPane.setLayout(oLayout);

    oLayout.putConstraint(SpringLayout.WEST, panParty, 0, SpringLayout.WEST, contentPane);
    oLayout.putConstraint(SpringLayout.NORTH, panParty, 0, SpringLayout.NORTH, contentPane);
    oLayout.putConstraint(SpringLayout.WEST, panStatus, 0, SpringLayout.WEST, contentPane);
    oLayout.putConstraint(SpringLayout.SOUTH, panStatus, 0, SpringLayout.SOUTH, contentPane);
    oLayout.putConstraint(SpringLayout.EAST, oMap, 0, SpringLayout.EAST, contentPane);
    oLayout.putConstraint(SpringLayout.NORTH, oMap, 0, SpringLayout.NORTH, contentPane);
    oLayout.putConstraint(SpringLayout.WEST, panChat, 0, SpringLayout.EAST, panStatus);
    oLayout.putConstraint(SpringLayout.NORTH, panChat, 0, SpringLayout.SOUTH, oMap);
    oLayout.putConstraint(SpringLayout.EAST, contentPane, 0, SpringLayout.EAST, panChat);
    oLayout.putConstraint(SpringLayout.SOUTH, contentPane, 0, SpringLayout.SOUTH, panChat);

    panChat.validate();
    panChat.setVisible(true);

    Insets oInsets = panStatus.getInsets();
    int nX = oInsets.left + 5;
    int nY = oInsets.top + 5;

    lblStatus1 = new JLabel("Not Connected...");
    lblStatus2 = new JLabel("No Party Formed...");
    lblStatus3 = new JLabel();

    Dimension oSize = lblStatus1.getPreferredSize();

    lblStatus1.setBounds(nX, nY, 180, oSize.height);
    nY += oSize.height + 7;
    lblStatus2.setBounds(nX, nY, 180, oSize.height);
    nY += oSize.height + 7;
    lblStatus3.setBounds(nX, nY, 180, oSize.height);

    panStatus.add(lblStatus1);
    panStatus.add(lblStatus2);
    panStatus.add(lblStatus3);

    frame.pack();
    frame.setResizable(false);
    frame.setLocation(
        ((scrBounds.x + scrBounds.width - frame.getWidth()) / 2),
        ((scrBounds.y + scrBounds.height - frame.getHeight()) / 2));

    oMap.addKeyListener(oMap);
    oMap.setButtonEvents(this);
  }
Exemplo n.º 30
0
  /** @param parentUI an instance of MainUI class */
  public ConsumerUI(MainUI parentUI) {
    super("SmartCal Vending Machine - Consumer Operations");
    super.setLocation(200, 10);
    this.parentUI = parentUI;

    VendingMachine machine = parentUI.getVendingMachine(); // Get an instance of Vending Machine
    machine.addObserver(
        this); // Register ConsumerUI as an observer to receive VendingMachine updates

    Container container1 = getContentPane();
    container1.setLayout(new BoxLayout(container1, BoxLayout.Y_AXIS));

    // itemPanel = Food Stock Panel
    itemPanel = new JPanel(new GridLayout(0, 4));
    itemPanel.setBorder(BorderFactory.createTitledBorder("Food Stock"));

    itemLabelArray = (JLabel[]) Array.newInstance(JLabel.class, 15);
    codeLabelArray = (JLabel[]) Array.newInstance(JLabel.class, 15);
    priceLabelArray = (JLabel[]) Array.newInstance(JLabel.class, 15);
    quantityLabelArray = (JLabel[]) Array.newInstance(JLabel.class, 15);

    for (int i = 0; i < 15; i++) { // Maximum No. of Food Item Slots is 15
      itemLabelArray[i] = new JLabel();
      codeLabelArray[i] = new JLabel();
      priceLabelArray[i] = new JLabel();
      quantityLabelArray[i] = new JLabel();

      itemPanel.add(itemLabelArray[i]);
      itemPanel.add(codeLabelArray[i]);
      itemPanel.add(priceLabelArray[i]);
      itemPanel.add(quantityLabelArray[i]);
    }

    itemList = machine.getFoodStocks(); // Get the list of Food Items from the Vending Machine &
    Enumeration e = itemList.elements(); // Store it in the Enumeration

    for (int i = 0;
        e.hasMoreElements();
        i++) { // Store the Items from Enumeration to the ConsumerUI Variables
      VendingMachine.FoodStock stock = (VendingMachine.FoodStock) e.nextElement();
      FoodItem item = stock.item;

      itemLabelArray[i].setText(item.getDescription());

      Integer code = item.getItemCode();
      String str = code.toString();
      codeLabelArray[i].setText("Item Code: " + str);

      Double price = item.getPrice();
      String str1 = price.toString();
      priceLabelArray[i].setText("Price: " + str1);

      Integer quant = machine.GetQuantity(code);
      String str2 = quant.toString();
      quantityLabelArray[i].setText("Quantity: " + str2);
    }

    container1.add(itemPanel);

    // displayPanel
    displayPanel = new JPanel(new FlowLayout());
    displayLabel = new JLabel(display);
    displayPanel.add(displayLabel);
    displayPanel.setBorder(BorderFactory.createTitledBorder("Display Screen"));

    container1.add(displayPanel);

    // actionPanel1 = Consumer Operations Panel
    actionPanel1 = new JPanel(new GridLayout(0, 1));
    actionPanel1.setBorder(BorderFactory.createTitledBorder("Consumer Operations"));

    // actionPanel1 = subPanel1 + subPanel2  + subPanel3

    // subPanel1
    subPanel1 = new JPanel(new FlowLayout());
    buyItem = new JRadioButton("Buy a Food Item");
    acceptLabel = new JLabel(accept);
    codeText = new JTextField(10);

    subPanel1.add(buyItem);
    subPanel1.add(acceptLabel);
    subPanel1.add(codeText);

    actionPanel1.add(subPanel1);

    // subPanel2
    subPanel2 = new JPanel(new FlowLayout());
    displayNutri = new JRadioButton("Display Nutritional Info");
    acceptLabel1 = new JLabel(accept);
    codeText1 = new JTextField(10);
    ok3 = new JButton("Display"); // for enter itemCode

    subPanel2.add(displayNutri);
    subPanel2.add(acceptLabel1);
    subPanel2.add(codeText1);
    subPanel2.add(ok3);

    actionPanel1.add(subPanel2);

    // subPanel3
    subPanel3 = new JPanel(new FlowLayout());
    querySuggest = new JRadioButton("Query Suggestion of Food Items");
    calorieLabel = new JLabel("Maximum Calorie Limit");
    calorieText = new JTextField(10);
    ok4 = new JButton("Display");

    subPanel3.add(querySuggest);
    subPanel3.add(calorieLabel);
    subPanel3.add(calorieText);
    subPanel3.add(ok4);

    actionPanel1.add(subPanel3);

    container1.add(actionPanel1);

    // actionPanel2 - H/W Slots = actionPanel2 + dispatchPanel
    actionPanel2 = new JPanel(new FlowLayout());
    actionPanel2.setBorder(BorderFactory.createTitledBorder("Hardware Slots"));
    enterLabel = new JLabel(enterAmount);
    amountText = new JTextField(10);
    buy = new JButton("BUY");
    cancel = new JButton("Cancel");
    changeLabel = new JLabel(change);
    changeText = new JTextField(10);
    ok1 = new JButton("Collect Change");

    actionPanel2.add(enterLabel);
    actionPanel2.add(amountText);
    actionPanel2.add(buy);
    actionPanel2.add(cancel);
    actionPanel2.add(changeLabel);
    actionPanel2.add(changeText);
    actionPanel2.add(ok1);

    // Dispatch Panel
    dispatchPanel = new JPanel(new FlowLayout());
    dispatcherLabel = new JLabel(dispatcher);
    ok2 = new JButton("Collect Item");

    dispatchPanel.add(dispatcherLabel);
    dispatchPanel.add(ok2);

    actionPanel2.add(dispatchPanel);

    container1.add(actionPanel2);

    // Exit Panel
    exitPanel = new JPanel(new FlowLayout());
    exit = new JButton("Back to Main Menu");
    exitPanel.add(exit);

    container1.add(exitPanel);

    // Registering the components to the Event Handlers
    // Register Buy button to Event Handler
    BuyHandler BHandler = new BuyHandler();
    buy.addActionListener(BHandler);

    // Register button of cancel to Event Handler
    CancelHandler CHandler = new CancelHandler();
    cancel.addActionListener(CHandler);

    // Register RadioButton of 'Buy Item' to Event Handler
    BuyRadioHandler BRHandler = new BuyRadioHandler();
    buyItem.addActionListener(BRHandler);

    // Register RadioButton of 'Display Nutritional Info' to Event Handler
    NutriRadioHandler NutriHandler = new NutriRadioHandler();
    displayNutri.addActionListener(NutriHandler);

    // Register RadioButton of 'Query Suggestion' to Event Handler
    QueryRadioHandler QueryHandler = new QueryRadioHandler();
    querySuggest.addActionListener(QueryHandler);

    // Register Button for 'Display Nutritional Info' to Event Handler
    DisplayNutriHandler DNHandler = new DisplayNutriHandler();
    ok3.addActionListener(DNHandler);

    // Register Button for 'Query Suggestion' to Event Handler
    DisplayNutriHandler DNHandler1 = new DisplayNutriHandler();
    ok4.addActionListener(DNHandler1);

    // Register Button for 'Back to Main Menu' to Event Handler
    MainMenuHandler1 MMHandler1 = new MainMenuHandler1();
    exit.addActionListener(MMHandler1);

    // Register Button for 'Collect Change' to Event Handler
    CollectChangeHandler CCHandler = new CollectChangeHandler();
    ok1.addActionListener(CCHandler);

    // Register Button for 'Collect Food Item' to Event Handler
    CollectItemHandler CIHandler = new CollectItemHandler();
    ok2.addActionListener(CIHandler);
  }