@Override
 public void paintComponent(Graphics g) {
   if (selected) {
     g.setColor(selColor);
     g.fillRoundRect(0, 0, getWidth(), getHeight(), getWidth() / 10, getHeight() / 10);
     label.setForeground(Color.YELLOW);
   } else label.setForeground(Color.WHITE);
   super.paintComponent(g);
 }
Esempio n. 2
0
 void addTextField(JPanel panel, String key, String label) {
   JLabel lab = new JLabel(label);
   lab.setAlignmentX(LEFT_ALIGNMENT);
   panel.add(lab);
   JTextField field = new JTextField();
   field.setText(sketch.configFile.get(key));
   field.setMaximumSize(new Dimension(Integer.MAX_VALUE, field.getPreferredSize().height));
   fields.put(key, field);
   panel.add(field);
 }
    public SidebarOption(String labelTxt, String rsc) {
      label = new JLabel(labelTxt);
      label.setForeground(Color.WHITE);
      label.setFont(font);
      add(label);
      setOpaque(false);
      setMaximumSize(new Dimension(1000, label.getPreferredSize().height + 5));

      this.rsc = ClassLoader.getSystemClassLoader().getResource(rsc);
    }
Esempio n. 4
0
  /** PaintComponent to draw everything. */
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    setBackground(Color.WHITE);
    // If using images, use cool dragon background
    if (useImages) g.drawImage(background, 0, 0, 310, 300, null);

    // Use light gray to not overpower the background image
    g.setColor(Color.LIGHT_GRAY);
    for (int y = 1; y < ROWS; ++y)
      g.fillRoundRect(0, cellSize * y - 4, (cellSize * COLS) - 1, 8, 8, 8);
    for (int x = 1; x < COLS; ++x)
      g.fillRoundRect(cellSize * x - 4, 0, 8, (cellSize * ROWS) - 1, 8, 8);

    // Use graphics2d for when not using the images
    Graphics2D g2d = (Graphics2D) g;
    g2d.setStroke(new BasicStroke(4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    for (int y = 0; y < ROWS; ++y) {
      for (int x = 0; x < COLS; ++x) {
        int x1 = x * cellSize + 16;
        int y1 = y * cellSize + 16;
        if (board[y][x] == Symbol.X) {
          // use image if set to true, otherwise use g2d
          // for thicker, better looking X's and O's
          if (useImages) g.drawImage(imageX, x1, y1, 75, 75, null);
          else {
            g2d.setColor(PURPLE);
            int x2 = (x + 1) * cellSize - 16;
            int y2 = (y + 1) * cellSize - 16;
            g2d.drawLine(x1, y1, x2, y2);
            g2d.drawLine(x2, y1, x1, y2);
          }
        } else if (board[y][x] == Symbol.O) {
          if (useImages) g.drawImage(imageO, x1, y1, 75, 75, null);
          else {
            g2d.setColor(Color.BLUE);
            g2d.drawOval(x1, y1, 70, 70);
          }
        }
      } // end for
    }

    // Set status bar based on gamestate.  If CONTINUE, show whose turn it is
    if (gameStatus == GameStatus.CONTINUE) {
      statusBar.setForeground(Color.BLACK);
      if (currentPlayer == Symbol.X) statusBar.setText("X's Turn");
      else statusBar.setText("O's Turn");
    } else if (gameStatus == GameStatus.DRAW) {
      statusBar.setForeground(Color.RED);
      statusBar.setText("Draw! Click to play again!");
    } else if (gameStatus == GameStatus.X_WIN) {
      statusBar.setForeground(Color.RED);
      statusBar.setText("X has won! Click to play again!");
    } else if (gameStatus == GameStatus.O_WIN) {
      statusBar.setForeground(Color.RED);
      statusBar.setText("O has won! Click to play again!");
    }
  }
Esempio n. 5
0
 void addTextArea(JPanel panel, String key, String label) {
   JLabel lab = new JLabel(label);
   lab.setAlignmentX(LEFT_ALIGNMENT);
   panel.add(lab);
   JTextArea field = new JTextArea();
   field.setText(sketch.configFile.get(key));
   field.setLineWrap(true);
   field.setWrapStyleWord(true);
   fields.put(key, field);
   JScrollPane scroll = new JScrollPane(field);
   scroll.setAlignmentX(0.0f);
   panel.add(scroll);
 }
Esempio n. 6
0
  /** ************** Display result of processed Image *********** */
  void imageResultDisplay(int width, int height, int pix[]) {

    img_temp = createImage(new MemoryImageSource(width, height, pix, 0, width));
    ImageIcon imgIcon = new ImageIcon();
    imgIcon.setImage(img_temp);
    lbl_res.setIcon(imgIcon);
  }
Esempio n. 7
0
  /** ****************** Display Gray Scale version of image opened *************** */
  void grayImageDisplay(int width, int height, int pix[]) {

    img_temp = createImage(new MemoryImageSource(width, height, pix, 0, width));
    ImageIcon imgI = new ImageIcon();
    imgI.setImage(img_temp);
    lbl_gray.setIcon(imgI);
  }
 void connectionFailed() {
   login.setEnabled(true);
   logout.setEnabled(false);
   // whoIsIn.setEnabled(false);
   chatStatus.setText("Please login first");
   chatField.setText("");
   // reset port number and host name as a construction time
   tfPort.setText("" + defaultPort);
   tfServer.setText(defaultHost);
   // let the user change them
   tfServer.setEditable(false);
   tfPort.setEditable(false);
   // don't react to a <CR> after the username
   chatField.removeActionListener(this);
   connected = false;
 }
  public void validAuthenticate() {
    chatStatus.setText("Enter your message below");
    connected = true;

    // disable login button
    login.setEnabled(false);
    // enable the 2 buttons
    logout.setEnabled(true);
    // whoIsIn.setEnabled(true);
    // disable the Server and Port JTextField
    tfServer.setEditable(false);
    tfPort.setEditable(false);
    // Action listener for when the user enter a message
    chatField.addActionListener(this);

    switchCards("Menu");
  }
  public void actionPerformed(ActionEvent e) {
    Object o = e.getSource();

    for (JRadioButton u : ub) {
      if (o == u) {
        mapTM.setUnitType(u.getText());
        System.out.println("Set unit type - " + u.getText());
        return;
      }
    }

    if (o == timer) {

      /*
      mmLabel.setText("Main Menu ("+(cdTime--)+")");

      if(cdTime == 0){
      	timer.stop();
      	gsButton.setText("Game Start");
      	mmLabel.setText("Main Menu");

      	ArrayList<Building> bArr = new ArrayList<Building>();

      	String temp = "Elixir Collector-24,8-960|Elixir Collector-31,8-960|Gold Mine-17,10-960|Elixir Collector-25,21-960|Elixir Collector-11,22-960";
      	String[] bs = temp.split("\\|");
      	for(String b : bs){
      		String[] bParts = b.split("-");
      		String[] cParts = bParts[1].split(",");
      		int x = Integer.parseInt(cParts[0].trim());
      		int y = Integer.parseInt(cParts[1].trim());

      		Building tb = new Building(bParts[0], new Coordinate(x,y));
      		tb.setHp(Integer.parseInt(bParts[2].trim()));

      		bArr.add(tb);
      	}



      	mapTM.setBuildings(bArr);
      	switchCards("TM");
      }
      */

      return;
    }

    if (o == gsButton) {

      if (timer.isRunning()) {
        // timer.stop();
        gsButton.setText("Game Start");
        mmLabel.setText("Main Menu");
        // sends the leave command
        client.sendUDP("leave~" + unameUDP);
        return;
      }
      // sends the joinlobby command
      client.sendUDP("joinlobby~" + unameUDP);
      // gsButton.setText("Game Stop");
      String serverResp = client.receiveUDP();

      if (serverResp.trim().equals("false")) {

        // place false handler here

      } else {

        String[] enemies = serverResp.trim().split(",");
        ArrayList<Building> bArr = new ArrayList<Building>();
        String mapConfig = getBaseConfig(enemies[0]);
        String[] bs = mapConfig.split("\\|");
        for (String b : bs) {

          String[] bParts = b.split("-");
          String[] cParts = bParts[1].split(",");
          int x = Integer.parseInt(cParts[0].trim());
          int y = Integer.parseInt(cParts[1].trim());

          Building tb = new Building(bParts[0], new Coordinate(x, y));
          tb.setHp(Integer.parseInt(bParts[2].trim()));
          bArr.add(tb);
        }

        mapTM.setBuildings(bArr);
        switchCards("TM");
      }

      // System.out.println(serverResp);
      // cdTime = 10;
      // timer.start();
      return;
    }

    if (o == logout) {
      client.sendMessage(new ChatMessage(ChatMessage.LOGOUT, ""));
      chatArea.setText("");

      switchCards("Login");
      return;
    }

    if (o == cmButton) {
      String baseConfig = getBaseConfig();
      System.out.println("base config: " + baseConfig);

      for (int i = 0; i < mapSize; i++) {
        for (int j = 0; j < mapSize; j++) {
          tiles[i][j].setValue("");
        }
      }

      if (!baseConfig.equals("")) {

        String[] bs = baseConfig.split("\\|");
        for (String b : bs) {
          String[] bParts = b.split("-");
          String[] cParts = bParts[1].split(",");
          int x = Integer.parseInt(cParts[0].trim());
          int y = Integer.parseInt(cParts[1].trim());

          int index = 0;
          for (int i = 0; i < bb.size(); i++) {
            if (bb.get(i).getText().split("-")[0].trim().equals(bParts[0])) {
              index = i;
              break;
            }
          }
          insertBuilding(y, x, index);
        }
      }

      switchCards("CM");

      return;
    }

    if (o == tmButton) {

      ArrayList<Building> bArr = new ArrayList<Building>();

      for (int i = 0; i < 40; i++) {
        for (int j = 0; j < 40; j++) {
          if (tiles[i][j].getValue().equals("") || tiles[i][j].getValue().contains("-")) {
            continue;
          }
          // weird part here
          bArr.add(new Building(tiles[i][j].getValue(), new Coordinate(j, i)));
        }
      }

      mapTM.setBuildings(bArr);

      switchCards("TM");
      return;
    }

    // if it the who is in button
    if (o == whoIsIn) {
      client.sendMessage(new ChatMessage(ChatMessage.WHOISIN, ""));
      return;
    }

    if (o == cmBack) {
      ArrayList<Building> bArr = new ArrayList<Building>();
      for (int i = 0; i < 40; i++) {
        for (int j = 0; j < 40; j++) {
          if (tiles[i][j].getValue().equals("") || tiles[i][j].getValue().contains("-")) {
            continue;
          }
          // weird part here
          bArr.add(new Building(tiles[i][j].getValue(), new Coordinate(j, i)));
        }
      }

      String temp = "mapdata~" + unameUDP + "~";
      int tileCount = 40;
      int dim = 600;
      int tileDim = (int) (dim / tileCount);
      int counter = 0;
      for (Building b : bArr) {
        int x, y, hp;
        x = b.getPos().getX() / tileDim;
        y = b.getPos().getY() / tileDim;
        hp = b.getHp();
        temp += b.getName() + "-" + x + "," + y + "-" + hp + "|";
        counter += 1;
      }
      if (counter > 0) {
        temp = temp.substring(0, temp.length() - 1); // removes the last '|'
      } else {
        temp += "none";
      }

      client.sendUDP(temp); // allows saving of the current state of the map into the user's account

      switchCards("Menu");

      return;
    }
    if (o == tmBack) {
      switchCards("Menu");

      return;
    }

    for (int i = 0; i < 40; i++) {
      for (int j = 0; j < 40; j++) {
        if (o == tiles[i][j]) {
          for (int k = 0; k < bb.size(); k++) {
            if (bb.get(k).isSelected()) {
              if (bb.get(k).getText().equals("Remove Building")) {
                removeBuilding(i, j);
                return;
              }

              insertBuilding(i, j, k);
              // JOptionPane.showMessageDialog(null, bb.get(k).getText());
              return;
            }
          }

          // JOptionPane.showMessageDialog(null, "i-"+i+" j-"+j);
          return;
        }
      }
    }

    // ok it is coming from the JTextField
    if (connected) {
      // just have to send the message
      client.sendMessage(new ChatMessage(ChatMessage.MESSAGE, chatField.getText()));
      chatField.setText("");
      return;
    }

    if (o == login) {
      // ok it is a connection request
      String username = usernameField.getText().trim();
      String password = passwordField.getText().trim();
      // empty username ignore it
      if (username.length() == 0) return;
      // empty serverAddress ignore it
      String server = tfServer.getText().trim();
      if (server.length() == 0) return;
      // empty or invalid port numer, ignore it
      String portNumber = tfPort.getText().trim();
      if (portNumber.length() == 0) return;
      int port = 0;
      try {
        port = Integer.parseInt(portNumber);
      } catch (Exception en) {
        return; // nothing I can do if port number is not valid
      }

      // try creating a new Client with GUI
      client = new Client(server, port, username, password, this);
      // test if we can start the Client
      if (!client.start()) return;

      unameUDP = username;

      switchCards("Menu");
      // fetching of the base_config string from the database

      chatField.setText("");
      chatArea.setText("");
    }
  }
Esempio n. 11
0
  private void makeMenuScreen() {
    menu = new JPanel();
    menu.setBackground(Color.BLACK);
    menu.setLayout(null);
    menu.setBounds(0, 0, width, height);

    try {
      BufferedImage menuIMG =
          ImageIO.read(this.getClass().getResource("/Resources/MenuBackground.png"));
      // BufferedImage menuIMG = ImageIO.read(new
      // File("M:/ComputerProgrammingJava/InsaneMouse_03/src/Resources/MenuBackground.png"));
      menuIMGL =
          new JLabel(
              new ImageIcon(
                  menuIMG.getScaledInstance(
                      (int) (width * 0.8), (int) (height * 0.8), Image.SCALE_SMOOTH)));
      menuIMGL.setBounds(0, 0, width, height);
    } catch (Exception e) {
    }

    highscoreL = new JLabel(String.valueOf(highscore));
    highscoreL.setBackground(Color.darkGray);
    highscoreL.setBounds((width / 2) + 100, (height / 2) + 70, 500, 100);
    highscoreL.setForeground(Color.white);

    easy = new JButton("Easy");
    hard = new JButton("Hard");

    easy.addActionListener(this);
    hard.addActionListener(this);

    easy.setBounds((width / 2) - 60, (height / 2) - 50, 120, 20);
    hard.setBounds((width / 2) - 60, height / 2 - 10, 120, 20);

    onePlayerRB = new JRadioButton("One Player");
    twoPlayerRB = new JRadioButton("Two Player");
    mouseRB = new JRadioButton("Mouse (Player 1)");
    keyboardRB = new JRadioButton("Keyboard (Player 1)");
    keyboardSpeedS1 = new JSlider(JSlider.HORIZONTAL, 10, 300, 50);
    keyboardSpeedS2 = new JSlider(JSlider.HORIZONTAL, 10, 300, 50);
    musicCB = new JCheckBox("Music");

    onePlayerRB.setBackground(null);
    twoPlayerRB.setBackground(null);
    mouseRB.setBackground(null);
    keyboardRB.setBackground(null);
    keyboardSpeedS1.setBackground(null);
    keyboardSpeedS2.setBackground(null);
    musicCB.setBackground(null);

    onePlayerRB.setForeground(Color.WHITE);
    twoPlayerRB.setForeground(Color.WHITE);
    mouseRB.setForeground(Color.WHITE);
    keyboardRB.setForeground(Color.WHITE);
    keyboardSpeedS1.setForeground(Color.WHITE);
    keyboardSpeedS2.setForeground(Color.WHITE);
    musicCB.setForeground(Color.WHITE);

    ButtonGroup playerChoice = new ButtonGroup();
    playerChoice.add(onePlayerRB);
    playerChoice.add(twoPlayerRB);
    onePlayerRB.setSelected(true);

    ButtonGroup peripheralChoice = new ButtonGroup();
    peripheralChoice.add(mouseRB);
    peripheralChoice.add(keyboardRB);
    mouseRB.setSelected(true);

    musicCB.setSelected(true);

    onePlayerRB.setBounds((width / 2) + 100, (height / 2) - 50, 100, 20);
    twoPlayerRB.setBounds((width / 2) + 100, (height / 2) - 30, 100, 20);
    mouseRB.setBounds((width / 2) + 100, (height / 2), 200, 20);
    keyboardRB.setBounds((width / 2) + 100, (height / 2) + 20, 200, 20);
    keyboardSpeedS1.setBounds(width / 2 - 120, height / 2 + 100, 200, 50);
    keyboardSpeedS2.setBounds(width / 2 - 120, height / 2 + 183, 200, 50);
    musicCB.setBounds((width / 2) + 100, (height / 2) + 50, 100, 20);

    keyboardSpeedL1 = new JLabel("Keyboard Speed (Player One)");
    keyboardSpeedL1.setForeground(Color.WHITE);
    keyboardSpeedL1.setBounds(width / 2 - 113, height / 2 + 67, 200, 50);

    keyboardSpeedL2 = new JLabel("Keyboard Speed (Player Two)");
    keyboardSpeedL2.setForeground(Color.WHITE);
    keyboardSpeedL2.setBounds(width / 2 - 113, height / 2 + 150, 200, 50);

    howTo = new JButton("How To Play");
    howTo.addActionListener(this);
    howTo.setBounds((width / 2) - 60, height / 2 + 30, 120, 20);

    try {
      BufferedImage howToIMG = ImageIO.read(this.getClass().getResource("/Resources/HowTo.png"));
      // BufferedImage howToIMG = ImageIO.read(new
      // File("M:/ComputerProgrammingJava/InsaneMouse_03/src/Resources/HowTo.png"));
      howToIMGL = new JLabel(new ImageIcon(howToIMG));
      howToIMGL.setBounds(
          width / 2 - howToIMG.getWidth() / 2,
          height / 2 - howToIMG.getHeight() / 2,
          howToIMG.getWidth(),
          howToIMG.getHeight());
    } catch (Exception e) {
    }

    howToBack = new JButton("X");
    howToBack.setBounds(
        (int) (width / 2 + width * 0.25) - 50, (int) (height / 2 - height * 0.25), 50, 50);
    howToBack.setBackground(Color.BLACK);
    howToBack.setForeground(Color.WHITE);
    howToBack.addActionListener(this);

    menu.add(easy);
    menu.add(hard);
    menu.add(howTo);
    menu.add(highscoreL);
    menu.add(onePlayerRB);
    menu.add(twoPlayerRB);
    menu.add(mouseRB);
    menu.add(keyboardRB);
    menu.add(keyboardSpeedL1);
    menu.add(keyboardSpeedL2);
    menu.add(keyboardSpeedS1);
    menu.add(keyboardSpeedS2);
    menu.add(musicCB);
    menu.add(menuIMGL);

    back = new JButton("Back");
    back.setBounds(width / 2 - 40, height / 2, 100, 20);
    back.addActionListener(this);
    back.setVisible(false);
    this.add(back);
  }
Esempio n. 12
0
 public void showLoginFailed() {
   loginTitle.setForeground(Color.red);
   loginTitle.setText("Cont nerecunoscut");
 }
Esempio n. 13
0
  /** *********** Initialization of every component and variable being used ************* */
  IPToolKit() {

    cp = new Container();
    cp.setLayout(new BorderLayout());
    Main_pnl = new JPanel();
    jmb = new JMenuBar();
    m_File = new JMenu("File");
    m_Arith = new JMenu("Arithmetic");
    m_Filter = new JMenu("Filters");
    m_Open = new JMenuItem("Open");
    m_Save = new JMenuItem("Save");
    m_Exit = new JMenuItem("Exit");
    m_Add = new JMenu("Add");
    m_Sub = new JMenu("Subtract");
    m_Mul = new JMenu("Multiply");
    m_Div = new JMenu("Divide");
    edge = new JMenu("Edge Detection");
    mpre = new JMenu("Prewits");
    msob = new JMenu("Sobel");
    lbl_img = new JLabel("");
    lbl_gray = new JLabel("");
    lbl_res = new JLabel("");
    jfc = new JFileChooser();
    panel_image = new JPanel();
    panel_gray = new JPanel();
    panel_result = new JPanel();
    scrollPane = new JScrollPane();
    mAddConst = new JMenu("Constant");
    mSubConst = new JMenu("Constant");
    mMulConst = new JMenu("Constant");
    mDivConst = new JMenu("Constant");
    mAddSat = new JMenuItem("Saturation");
    mAddWrap = new JMenuItem("Wrap Around");
    mSubSat = new JMenuItem("Saturation");
    mSubWrap = new JMenuItem("Wrap Around");
    mMulSat = new JMenuItem("Saturation");
    mMulWrap = new JMenuItem("Wrap Around");
    mDivSat = new JMenuItem("Saturation");
    mDivWrap = new JMenuItem("Wrap Around");
    mAddImg = new JMenuItem("Image");
    mSubImg = new JMenuItem("Image");
    mMulImg = new JMenuItem("Image");
    mDivImg = new JMenuItem("Image");
    mlowPass = new JMenuItem("Low Pass");
    mhighPass = new JMenuItem("High Pass");
    mhighBoost = new JMenuItem("High Boost");
    median = new JMenuItem("Median");
    mBright = new JMenuItem("Brightness");
    mContrast = new JMenuItem("Contrast Stretch");
    mThreshold = new JMenuItem(" Threshold ");
    m_Enhance = new JMenu("Enhancement");
    mInvert = new JMenuItem("Negative");
    mpre_hor = new JMenuItem("Prewits Horizontal");
    mpre_ver = new JMenuItem("Prewits Vertical");
    mpre_both = new JMenuItem("Prewits Both");
    msob_hor = new JMenuItem("Sobel Horizontal");
    msob_ver = new JMenuItem("Sobel Vertical");
    msob_both = new JMenuItem("Sobel Both");
    ;
    mrob = new JMenuItem("Roberts");
    mean = new JMenuItem("Mean");
    mlap = new JMenuItem("Laplacian");
    other = new JMenu("Other");
    hist = new JMenuItem("Histogram Equalization");
    conect = new JMenuItem("Connected Component");
    mBlend = new JMenuItem("Blending");
    vsb = new JScrollBar(JScrollBar.VERTICAL);
    hsb = new JScrollBar(JScrollBar.HORIZONTAL);
    //	jsp = new JScrollPane();

    setJMenuBar(jmb);
    add(cp);

    //	setBackground(new Color(255,255,255));

    panel_image.setBackground(new Color(255, 0, 0));
    panel_gray.setBackground(new Color(0, 255, 0));
    panel_result.setBackground(new Color(0, 0, 255));

    jmb.add(m_File);
    jmb.add(m_Arith);
    jmb.add(m_Enhance);
    jmb.add(m_Filter);
    jmb.add(edge);
    jmb.add(other);

    cp.add(Main_pnl);

    Main_pnl.setLayout(new GridLayout(1, 3, 10, 10));

    Main_pnl.add(panel_image);
    Main_pnl.add(panel_gray);
    Main_pnl.add(panel_result);

    m_File.add(m_Open);
    m_File.add(m_Save);
    m_File.add(m_Exit);

    m_Arith.add(m_Add);
    m_Add.add(mAddImg);
    m_Add.add(mAddConst);
    mAddConst.add(mAddSat);
    mAddConst.add(mAddWrap);

    m_Arith.add(m_Sub);
    m_Sub.add(mSubImg);
    m_Sub.add(mSubConst);
    mSubConst.add(mSubSat);
    mSubConst.add(mSubWrap);

    m_Arith.add(m_Mul);
    m_Mul.add(mMulImg);
    m_Mul.add(mMulConst);
    mMulConst.add(mMulSat);
    mMulConst.add(mMulWrap);

    m_Arith.add(m_Div);
    m_Div.add(mDivImg);
    m_Div.add(mDivConst);
    mDivConst.add(mDivSat);
    mDivConst.add(mDivWrap);

    m_Filter.add(mlowPass);
    m_Filter.add(mhighPass);
    m_Filter.add(mhighBoost);
    m_Filter.add(median);
    m_Filter.add(mean);

    edge.add(mpre);
    edge.add(msob);
    mpre.add(mpre_hor);
    mpre.add(mpre_ver);
    mpre.add(mpre_both);
    msob.add(msob_hor);
    msob.add(msob_ver);
    msob.add(msob_both);
    edge.add(mrob);
    edge.add(mlap);

    m_Enhance.add(mBright);
    m_Enhance.add(mContrast);
    m_Enhance.add(mThreshold);
    m_Enhance.add(mInvert);
    m_Enhance.add(mBlend);

    other.add(hist);
    other.add(conect);

    m_Open.addActionListener(this);
    m_Save.addActionListener(this);
    m_Exit.addActionListener(this);

    mAddImg.addActionListener(this);
    mSubImg.addActionListener(this);
    mMulImg.addActionListener(this);
    mDivImg.addActionListener(this);

    mAddSat.addActionListener(this);
    mAddWrap.addActionListener(this);
    mSubSat.addActionListener(this);
    mSubWrap.addActionListener(this);
    mMulSat.addActionListener(this);
    mMulWrap.addActionListener(this);
    mDivSat.addActionListener(this);
    mDivWrap.addActionListener(this);

    mlowPass.addActionListener(this);
    mhighPass.addActionListener(this);
    mhighBoost.addActionListener(this);
    median.addActionListener(this);

    mBright.addActionListener(this);
    mContrast.addActionListener(this);
    mThreshold.addActionListener(this);
    mInvert.addActionListener(this);
    mBlend.addActionListener(this);

    mpre_hor.addActionListener(this);
    mpre_ver.addActionListener(this);
    mpre_both.addActionListener(this);
    msob_hor.addActionListener(this);
    msob_ver.addActionListener(this);
    msob_both.addActionListener(this);
    mrob.addActionListener(this);
    mean.addActionListener(this);
    mlap.addActionListener(this);

    hist.addActionListener(this);
    conect.addActionListener(this);

    lbl_gray.addMouseListener(this);

    panel_image.add(lbl_img);
    panel_gray.add(lbl_gray);
    panel_result.add(lbl_res);

    cp.add(vsb, BorderLayout.EAST);
    cp.add(hsb, BorderLayout.SOUTH);
    //	cp1 = getContentPane();

    cp = getContentPane();
    setSize(600, 400);
    setVisible(true);
  }
Esempio n. 14
0
  private void _displayImgInFrame() {

    final JFrame frame = new JFrame("Google Static Map");
    GUIUtils.setAppIcon(frame, "71.png");
    // frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    JLabel imgLbl = new JLabel(new ImageIcon(_img));
    imgLbl.setToolTipText(
        MessageFormat.format(
            "<html>Image downloaded from URI<br>size: w={0}, h={1}</html>",
            _img.getWidth(), _img.getHeight()));

    GUIUtils.centerOnScreen(frame);
    frame.setVisible(true);
    frame.setContentPane(imgLbl);
    frame.pack();
    frame.setResizable(false);

    imgLbl.addMouseListener(
        new MouseListener() {
          public void mouseClicked(MouseEvent e) {}

          public void mousePressed(MouseEvent e) {

            System.out.println("Mouse Listener:  Mouse Clicked!");
            mapIsUp = 1;
            sentX = 0.00;
            clickX = e.getX(); // Latitude
            clickY = e.getY(); // Longitude
            if ((clickX < (_img.getWidth() / 2))
                && (clickY < (_img.getHeight() / 2))) { // 1st quadrant positive values
              sentX =
                  Double.parseDouble(ttfLati.getText())
                      + (((-1 * (_img.getWidth() / 2)) + clickX) * pixelX); // Add to latitude
              sentY =
                  Double.parseDouble(ttfLongi.getText())
                      + (((_img.getHeight() / 2) - clickY) * pixelY); // Add to Longitude
              System.out.println("Top left");
            } else if ((clickX > (_img.getWidth() / 2))
                && (clickY > (_img.getHeight() / 2))) { // 2nd quadrant negative values
              sentX =
                  Double.parseDouble(ttfLati.getText())
                      + (((-1 * (_img.getHeight() / 2)) + clickX) * pixelX);
              sentY =
                  Double.parseDouble(ttfLongi.getText())
                      + (((_img.getHeight() / 2) - clickY) * pixelY);
              System.out.println("Bottom Right");
            } else if ((clickX < (_img.getWidth() / 2))
                && (clickY > (_img.getHeight() / 2))) { // 3rd quadrant 1 positive 1 negative
              sentX =
                  Double.parseDouble(ttfLati.getText())
                      + (((-1 * (_img.getWidth() / 2)) + clickX) * pixelX);
              sentY =
                  Double.parseDouble(ttfLongi.getText())
                      + (((_img.getHeight() / 2) - clickY) * pixelY);
              System.out.println("Bottom Left");
            } else { // 3rd quadrant 1 positive 1 negative
              sentX =
                  Double.parseDouble(ttfLati.getText())
                      + (((-1 * (_img.getHeight() / 2)) + clickX) * pixelX);
              sentY =
                  Double.parseDouble(ttfLongi.getText())
                      + (((_img.getHeight() / 2) - clickY) * pixelY);
              System.out.println("Top Right");
            }

            BigDecimal toCoordsX = new BigDecimal(sentX);
            BigDecimal toCoordsY = new BigDecimal(sentY);

            sentX =
                (toCoordsX.setScale(6, BigDecimal.ROUND_HALF_UP))
                    .doubleValue(); // allows values of up to 6 decimal places
            sentY = (toCoordsY.setScale(6, BigDecimal.ROUND_HALF_UP)).doubleValue();
            getCoords = sentX + " " + sentY;
            ttfLati.setText(Double.toString(sentX));
            ttfLongi.setText(Double.toString(sentY));

            System.out.println("... saving Coordinates");
            saveLocation(
                getCoords); // pass getCoords through saveLocation. this string is appended to the
                            // savedLocations file.
            System.out.println("... savedCoordinates");

            // Update the Locations ComboBox with new additions
            ttfSave.removeAllItems(); // re-populate the ComboBox
            System.out.println("removed items");

            getSavedLocations(); // run through file to get all locations
            for (int i = 0; i < loc.size(); i++) ttfSave.addItem(loc.get(i));
            System.out.println("update combobox");
            mapIsUp = 0;
            frame.dispose(); // closes window
            startTaskAction(); // pops up a new window
          }

          public void saveLocation(String xy) {
            BufferedWriter f = null; // created a bufferedWriter object

            try {
              f =
                  new BufferedWriter(
                      new FileWriter(
                          "savedLocations.txt",
                          true)); // evaluated true if file has not been created yet
              f.write(xy); // append passed coordinates and append to file if exists
              f.newLine();
              f.flush();
            } catch (IOException ioe) {
              ioe.printStackTrace();
            } finally { // close the file
              if (f != null) {

                try {
                  f.close();
                } catch (IOException e) { // any error, catch exception
                  System.err.println("Error: " + e.getMessage());
                }
              }
            }
          }

          public void mouseReleased(MouseEvent e) {}

          public void mouseEntered(MouseEvent e) {}

          public void mouseExited(MouseEvent e) {}
        });
  }
Esempio n. 15
0
  /** Constructor to set everything up */
  public TicTac() {
    // Set defaults before settings are changed via menus
    // (defaults are vs AI, play as X, with graphics on)
    multiPlayers = false;
    temp = false;
    currentPlayer = Symbol.X;
    ai = Symbol.O;
    difficulty = Difficulty.IMPOSSIBLE;

    frame = new JFrame("Tic Tac Toe");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    // Set preferred size so game fills window nicely
    this.setPreferredSize(new Dimension(cellSize * ROWS, cellSize * COLS));
    frame.add(this);

    // Load images
    try {
      sword = ImageIO.read(new File("swordsBlue.png"));
      saber = ImageIO.read(new File("saber2.png"));
      skull = ImageIO.read(new File("skull.png"));
      ring = ImageIO.read(new File("ring.png"));
      smiley = ImageIO.read(new File("smiley.png"));
      hydra = ImageIO.read(new File("hydra.png"));
      finalfantasy = ImageIO.read(new File("finalfantasy.jpg"));
      dragon = ImageIO.read(new File("dargon.jpg"));
      night = ImageIO.read(new File("night.jpg"));
    } catch (IOException e) {
      System.out.println("Could not open image files, turning images off!");
      useImages = false;
    }

    imageX = saber;
    imageO = ring;
    background = dragon;

    // Create menu bars.  Each one item will need a listener
    menuBar = new JMenuBar();
    JMenu menu = new JMenu("Mode");
    JMenu menu2 = new JMenu("Side");
    JMenu menu3 = new JMenu("Graphics");
    JMenu menu4 = new JMenu("Other");
    JMenu menu5 = new JMenu("Difficulty");
    JMenu xImageMenu = new JMenu("Image for X");
    JMenu oImageMenu = new JMenu("Image for O");
    JMenu backgroundMenu = new JMenu("Set Background");
    menuBar.add(menu);
    menuBar.add(menu2);
    menuBar.add(menu5);
    menuBar.add(menu3);
    menuBar.add(menu4);

    // Create checkbox menu items for choices
    final JCheckBoxMenuItem item = new JCheckBoxMenuItem("2 Player");
    final JCheckBoxMenuItem item2 = new JCheckBoxMenuItem("VS Computer");
    final JCheckBoxMenuItem item3 = new JCheckBoxMenuItem("Play as X");
    final JCheckBoxMenuItem item4 = new JCheckBoxMenuItem("Play as O");
    final JCheckBoxMenuItem item5 = new JCheckBoxMenuItem("On");
    final JCheckBoxMenuItem item6 = new JCheckBoxMenuItem("Off");
    JMenuItem item7 = new JMenuItem("Restart");
    JMenuItem item8 = new JMenuItem("Exit");
    final JCheckBoxMenuItem item9 = new JCheckBoxMenuItem("Easy");
    final JCheckBoxMenuItem item10 = new JCheckBoxMenuItem("Hard");
    final JCheckBoxMenuItem item11 = new JCheckBoxMenuItem("Impossible");
    final JCheckBoxMenuItem itemSword = new JCheckBoxMenuItem("Sword");
    final JCheckBoxMenuItem itemSaber = new JCheckBoxMenuItem("Sabers");
    final JCheckBoxMenuItem itemSkull = new JCheckBoxMenuItem("Skull");
    final JCheckBoxMenuItem itemRing = new JCheckBoxMenuItem("One Ring");
    final JCheckBoxMenuItem itemSmiley = new JCheckBoxMenuItem("Red Smiley");
    final JCheckBoxMenuItem itemHydra = new JCheckBoxMenuItem("Hydra");
    final JCheckBoxMenuItem itemDragon = new JCheckBoxMenuItem("Dragon");
    final JCheckBoxMenuItem itemFinalFantasy = new JCheckBoxMenuItem("Final Fantasy 7");
    final JCheckBoxMenuItem itemNight = new JCheckBoxMenuItem("Nighttime");

    // Set the initial checkboxes to true (for play vs ai, as X, with graphics on)
    item2.setSelected(true);
    item3.setSelected(true);
    item5.setSelected(true);
    item11.setSelected(true);
    itemSaber.setSelected(true);
    itemRing.setSelected(true);
    itemDragon.setSelected(true);

    // Play against friend
    item.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            item.setSelected(true);
            item2.setSelected(false);
            multiPlayers = true;
            repaint();
          }
        });
    menu.add(item);

    // Checkbox for Selecting to play against AI
    item2.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            item2.setSelected(true);
            item.setSelected(false);
            if (currentPlayer == Symbol.X) ai = Symbol.O;
            else ai = Symbol.X;
            item3.setSelected(true);
            item4.setSelected(false);
            multiPlayers = false;
          }
        });
    menu.add(item2);

    // Play as X
    item3.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            // use temp variable to move after assigning symbols
            if (item4.getState() && !multiPlayers) temp = true;
            item3.setSelected(true);
            item4.setSelected(false);
            currentPlayer = Symbol.X;
            ai = Symbol.O;
            if (temp) aiMove();
            repaint();
            temp = false;
          }
        });
    menu2.add(item3);

    // Play as O
    item4.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (item3.getState() && !multiPlayers) temp = true;
            item4.setSelected(true);
            item3.setSelected(false);
            currentPlayer = Symbol.O;
            ai = Symbol.X;
            if (temp) aiMove();
            repaint();
            temp = false;
          }
        });
    menu2.add(item4);

    // Turn Graphics on
    item5.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            item5.setSelected(true);
            item6.setSelected(false);
            useImages = true;
            repaint();
          }
        });
    menu3.add(item5);

    // Turn Graphics off
    item6.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            item5.setSelected(false);
            item6.setSelected(true);
            useImages = false;
            repaint();
          }
        });
    menu3.add(item6);
    menu3.addSeparator();
    menu3.add(xImageMenu);
    menu3.add(oImageMenu);
    menu3.add(backgroundMenu);

    // Choose Saber for X
    itemSaber.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            itemSword.setSelected(false);
            itemSaber.setSelected(true);
            itemSkull.setSelected(false);
            imageX = saber;
            repaint();
          }
        });
    xImageMenu.add(itemSaber);

    // Choose Sword for X
    itemSword.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            itemSword.setSelected(true);
            itemSaber.setSelected(false);
            itemSkull.setSelected(false);
            imageX = sword;
            repaint();
          }
        });
    xImageMenu.add(itemSword);

    // Choose Skull for X
    itemSkull.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            itemSword.setSelected(false);
            itemSaber.setSelected(false);
            itemSkull.setSelected(true);
            imageX = skull;
            repaint();
          }
        });
    xImageMenu.add(itemSkull);

    // Choose ring for O
    itemRing.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            itemRing.setSelected(true);
            itemSmiley.setSelected(false);
            itemHydra.setSelected(false);
            imageO = ring;
            repaint();
          }
        });
    oImageMenu.add(itemRing);

    // Choose red smiley for O
    itemSmiley.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            itemRing.setSelected(false);
            itemSmiley.setSelected(true);
            itemHydra.setSelected(false);
            imageO = smiley;
            repaint();
          }
        });
    oImageMenu.add(itemSmiley);

    // Choose hydra for O
    itemHydra.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            itemRing.setSelected(false);
            itemSmiley.setSelected(false);
            itemHydra.setSelected(true);
            imageO = hydra;
            repaint();
          }
        });
    oImageMenu.add(itemHydra);

    // Set dragon as background
    itemDragon.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            itemDragon.setSelected(true);
            itemFinalFantasy.setSelected(false);
            itemNight.setSelected(false);
            background = dragon;
            repaint();
          }
        });
    backgroundMenu.add(itemDragon);

    // Set final fantasy 7 as background
    itemFinalFantasy.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            itemDragon.setSelected(false);
            itemFinalFantasy.setSelected(true);
            itemNight.setSelected(false);
            background = finalfantasy;
            repaint();
          }
        });
    backgroundMenu.add(itemFinalFantasy);

    // Set night as background
    itemNight.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            itemDragon.setSelected(false);
            itemFinalFantasy.setSelected(false);
            itemNight.setSelected(true);
            background = night;
            repaint();
          }
        });
    backgroundMenu.add(itemNight);

    // Reset game
    item7.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            initialize();
          }
        });
    menu4.add(item7);

    // Exit game
    item8.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            System.exit(0);
          }
        });
    menu4.add(item8);

    // Difficulty easy
    item9.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            difficulty = Difficulty.EASY;
            item9.setSelected(true);
            item10.setSelected(false);
            item11.setSelected(false);
          }
        });
    menu5.add(item9);

    // Difficulty hard
    item10.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            difficulty = Difficulty.HARD;
            item10.setSelected(true);
            item9.setSelected(false);
            item11.setSelected(false);
          }
        });
    menu5.add(item10);

    // Difficulty impossible
    item11.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            difficulty = Difficulty.IMPOSSIBLE;
            item11.setSelected(true);
            item9.setSelected(false);
            item10.setSelected(false);
          }
        });
    menu5.add(item11);

    // Add Whole menu bar to frame
    frame.setJMenuBar(menuBar);

    // Create statusBar (updates will take place in paintComponent)
    statusBar = new JLabel("  ");
    statusBar.setFont(new Font(Font.DIALOG_INPUT, Font.BOLD, 15));
    statusBar.setBorder(BorderFactory.createEmptyBorder(2, 5, 4, 5));
    // Use container variable to set layout and pack everything nicely
    Container cp = frame.getContentPane();
    cp.setLayout(new BorderLayout());
    cp.add(this, BorderLayout.CENTER);
    cp.add(statusBar, BorderLayout.SOUTH);
    frame.pack();

    board = new Symbol[ROWS][COLS];
    initialize();

    // Add the mouse listener.  Use MouseAdapter rather than implement it
    this.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            int currentCol = e.getX() / cellSize;
            int currentRow = e.getY() / cellSize;

            if (gameStatus == GameStatus.CONTINUE) {
              // If valid click, and spot is empty, make the move.  Then check
              // to see if game is won. If not, and facing AI, ai moves.
              // Otherwise switch X and O
              if (currentRow >= 0
                  && currentRow < ROWS
                  && currentCol >= 0
                  && currentCol < COLS
                  && board[currentRow][currentCol] == Symbol.EMPTY) {
                board[currentRow][currentCol] = currentPlayer;
                checkState(currentPlayer);

                if (multiPlayers) currentPlayer = (currentPlayer == Symbol.X) ? Symbol.O : Symbol.X;

                if (gameStatus == GameStatus.CONTINUE && !multiPlayers) aiMove();
              }
            } else {
              // Game is over, so re-initialize everything
              initialize();
            }
            repaint();
          }
        });
  }
Esempio n. 16
0
  public void actionPerformed(ActionEvent e) {
    String arg = (String) e.getActionCommand();

    /** ******************** Open an Image **************** */
    if (e.getSource() == m_Open) {
      int returnVal = jfc.showOpenDialog(IPToolKit.this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        file = jfc.getSelectedFile();
        String path = file.getAbsolutePath();
        //	image = Toolkit.getDefaultToolkit().getImage(path);

        try {
          try {
            inImage = new FileImageInputStream(file);
            len = (int) inImage.length();
            byteArray = new byte[len];
            // System.out.println(len);
            inImage.read(byteArray, 0, len);
            image = Toolkit.getDefaultToolkit().createImage(byteArray);
            MediaTracker t = new MediaTracker(this);
            t.addImage(image, 0);

            try {
              t.waitForID(0);
            } catch (Exception eeee) {
              System.out.println(eeee);
            }

            w = image.getWidth(null);
            h = image.getHeight(null);

            // System.out.println(w+"\t"+h);

          } catch (Exception fnfe) {
            JOptionPane.showMessageDialog(this, "File: Not Found");
          }
        } catch (Exception ice) {

          JOptionPane.showMessageDialog(this, "File I/O Error");
        }
      }
      if (image != null) {

        pix_temp = new int[h * w];
        ImageIcon icon = new ImageIcon(image);
        lbl_img.setIcon(icon);
        setVisible(true);
      }

      pix_temp = pixel_grab(image, w, h);
      pix_temp = pix_pack(pix_temp, w, h);
      grayImageDisplay(w, h, pix_temp);
    }

    /** ****************** Add one image to another ************** */
    if (e.getSource() == mAddImg) {
      OpenImage2();
      pix_temp1 = new int[w * h];
      pix_res = new int[w * h];

      pix_temp1 = pixel_grab(image1, w1, h1);
      pix_temp1 = pix_pack(pix_temp1, w1, h1);

      for (int s = 0; s < w * h; s++) {

        pix_res[s] = pix_temp[s] + pix_temp1[s];
      }
      ;

      pix_temp1 = saturate(pix_temp1, w, h);
      imageResultDisplay(w, h, pix_res);
    }

    /**
     * *********************** Add Constant value and then use Satuartion technique ***************
     */
    if (e.getSource() == mAddSat) {
      String add_value;
      Image img_add = image;
      pixel_add = new int[w * h];

      pixel_result = pixel_grab(img_add, w, h);

      add_value = JOptionPane.showInputDialog("Enter Value you wish to add to the image");
      int number = Integer.parseInt(add_value);
      for (int r = 0; r < w * h; r++) {
        pixel_add[r] = number + pixel_result[r];
      }
      pixel_add = saturate(pixel_add, w, h);
      pixel_add = pix_pack(pixel_add, w, h);
      imageResultDisplay(w, h, pixel_add);
    }

    /** ************ Add constant by Wrap Around technique ********** */
    if (e.getSource() == mAddWrap) {
      String add_value;
      Image img_add = image;
      pixel_add = new int[w * h];

      pixel_result = pixel_grab(img_add, w, h);

      add_value = JOptionPane.showInputDialog("Enter Value you wish to add to the image");
      int number = Integer.parseInt(add_value);
      for (int r = 0; r < w * h; r++) {
        pixel_add[r] = number + pixel_result[r];
      }
      pixel_add = WrapAround(pixel_add, w, h);
      pixel_add = pix_pack(pixel_add, w, h);
      imageResultDisplay(w, h, pixel_add);
    }

    /** ****************** Subtract one image from another ************** */
    if (e.getSource() == mSubImg) {
      OpenImage2();
      pix_temp1 = new int[w * h];
      pix_res = new int[w * h];

      pix_temp1 = pixel_grab(image1, w1, h1);
      pix_temp1 = pix_pack(pix_temp1, w1, h1);

      for (int s = 0; s < w * h; s++) {
        pix_res[s] = pix_temp[s] - pix_temp1[s];
      }

      pix_temp1 = saturate(pix_temp1, w1, h1);
      imageResultDisplay(w1, h1, pix_res);
    }

    /**
     * *********************** Subtract Constant value and then use Satuartion technique
     * ***************
     */
    if (e.getSource() == mSubSat) {
      String sub_value;
      Image img_add = image;
      pixel_sub = new int[w * h];

      pixel_result = pixel_grab(img_add, w, h);

      sub_value = JOptionPane.showInputDialog("Enter Value you wish to subtract from the image");
      int number = Integer.parseInt(sub_value);

      for (int r = 0; r < w * h; r++) {
        pixel_sub[r] = pixel_result[r] - number;
      }

      pixel_sub = saturate(pixel_sub, w, h);
      pixel_sub = pix_pack(pixel_sub, w, h);
      imageResultDisplay(w, h, pixel_sub);
    }

    /** ************ Subtract constant by Wrap Around technique ********** */
    if (e.getSource() == mSubWrap) {
      String sub_value;
      Image img_add = image;
      pixel_sub = new int[w * h];

      pixel_result = pixel_grab(img_add, w, h);

      sub_value = JOptionPane.showInputDialog("Enter Value you wish to add to the image");
      int number = Integer.parseInt(sub_value);

      for (int r = 0; r < w * h; r++) {
        pixel_sub[r] = pixel_result[r] - number;
      }
      pixel_sub = WrapAround(pixel_sub, w, h);
      pixel_sub = pix_pack(pixel_sub, w, h);
      imageResultDisplay(w, h, pixel_sub);
    }

    /** ****************** Multiply one image with another ************** */
    if (e.getSource() == mMulImg) {
      OpenImage2();
      pix_temp1 = new int[w * h];
      pix_res = new int[w * h];

      pix_temp1 = pixel_grab(image1, w1, h1);
      pix_temp1 = pix_pack(pix_temp1, w1, h1);

      for (int s = 0; s < w * h; s++) {
        pix_res[s] = pix_temp[s] * pix_temp1[s];
      }

      pix_temp1 = saturate(pix_temp1, w1, h1);
      imageResultDisplay(w1, h1, pix_res);
    }

    /**
     * *********************** Multiply Constant value and then use Satuartion technique
     * ***************
     */
    if (e.getSource() == mMulSat) {
      String mul_value;
      Image img_mul = image;
      pixel_mul = new int[w * h];

      pixel_result = pixel_grab(img_mul, w, h);

      mul_value = JOptionPane.showInputDialog("Enter Value you wish to multiply to the image");
      int number = Integer.parseInt(mul_value);

      for (int r = 0; r < w * h; r++) {
        pixel_mul[r] = pixel_result[r] * number;
      }

      pixel_mul = saturate(pixel_mul, w, h);
      pixel_mul = pix_pack(pixel_mul, w, h);
      imageResultDisplay(w, h, pixel_mul);
    }

    /** ************ Multiply constant by Wrap Around technique ********** */
    if (e.getSource() == mMulWrap) {
      String mul_value;
      Image img_mul = image;
      pixel_mul = new int[w * h];

      pixel_result = pixel_grab(img_mul, w, h);

      mul_value = JOptionPane.showInputDialog("Enter Value you wish to multiply to the image");
      int number = Integer.parseInt(mul_value);
      for (int r = 0; r < w * h; r++) {
        pixel_mul[r] = pixel_result[r] * number;
      }
      pixel_mul = WrapAround(pixel_mul, w, h);
      pixel_mul = pix_pack(pixel_mul, w, h);
      imageResultDisplay(w, h, pixel_mul);
    }

    /** ****************** Divide one image by another ************** */
    if (e.getSource() == mDivImg) {

      OpenImage2();
      pix_temp1 = new int[w * h];
      pix_res = new int[w * h];

      pix_temp1 = pixel_grab(image1, w1, h1);
      pix_temp1 = pix_pack(pix_temp1, w1, h1);

      for (int s = 0; s < w * h; s++) {
        pix_res[s] = pix_temp1[s] / pix_temp[s];
      }

      // pix_temp1 = saturate(pix_temp1,w1,h1);
      pix_temp1 = WrapAround(pix_temp1, w, h);
      imageResultDisplay(w1, h1, pix_res);
    }

    /**
     * *********************** Divide by Constant value and then use Saturation technique
     * ***************
     */
    if (e.getSource() == mDivSat) {
      String div_value;
      Image img_add = image;
      pixel_div = new int[w * h];

      pixel_result = pixel_grab(img_add, w, h);

      div_value = JOptionPane.showInputDialog("Enter value to divide the image by");
      int number = Integer.parseInt(div_value);

      for (int r = 0; r < w * h; r++) {
        pixel_div[r] = pixel_result[r] / number;
      }

      pixel_div = saturate(pixel_div, w, h);
      pixel_div = pix_pack(pixel_div, w, h);
      imageResultDisplay(w, h, pixel_div);
    }

    /** ************ Divide constant by Wrap Around technique ********** */
    if (e.getSource() == mDivWrap) {
      String div_value;
      Image img_add = image;
      pixel_div = new int[w * h];

      pixel_result = pixel_grab(img_add, w, h);

      div_value = JOptionPane.showInputDialog("Enter value to divide image by");
      int number = Integer.parseInt(div_value);
      for (int r = 0; r < w * h; r++) {

        pixel_div[r] = pixel_result[r] / number;
      }
      pixel_div = WrapAround(pixel_div, w, h);
      pixel_div = pix_pack(pixel_div, w, h);
      imageResultDisplay(w, h, pixel_div);
    }

    /** ******************** Thresholding ************* */
    if (e.getSource() == mThreshold) {
      String thresh_value;
      Image img_add = image;

      pixel_result = pixel_grab(img_add, w, h);

      thresh_value = JOptionPane.showInputDialog("Enter value to threshold the image");
      int number = Integer.parseInt(thresh_value);

      for (int r = 0; r < w * h; r++) {
        if (pixel_result[r] >= number) pixel_result[r] = 255;
        else if (pixel_result[r] <= number) pixel_result[r] = 0;
      }

      pixel_result = pix_pack(pixel_result, w, h);
      imageResultDisplay(w, h, pixel_result);
    }

    if (e.getSource() == m_Save) {
      FileImageOutputStream src_img;

      int returnVal = jfc.showSaveDialog(IPToolKit.this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        File fileR = jfc.getSelectedFile();
        String fileToSave = file.getAbsolutePath();

        if (!fileToSave.toLowerCase().endsWith(".jpg")) {
          fileR = new File(fileToSave + ".jpg");
        }

        try {
          src_img = new FileImageOutputStream(fileR);
          buf_img = getImageFromArray(pixel_result, w, h);
          ImageIO.write(buf_img, "jpg", src_img);

        } catch (IOException ex8) {
          System.out.println(ex8);
        }
      }

      //	}

    }

    /** ***************************** Increase brightness **************** */
    if (e.getSource() == mBright) {
      String bright_value;
      Image img_add = image;

      pixel_result = pixel_grab(img_add, w, h);

      bright_value = JOptionPane.showInputDialog("Enter value to increase brightness");
      int number = Integer.parseInt(bright_value);

      for (int r = 0; r < w * h; r++) {
        pixel_result[r] = pixel_result[r] + number;
      }

      pixel_result = saturate(pixel_result, w, h);
      pixel_result = pix_pack(pixel_result, w, h);
      imageResultDisplay(w, h, pixel_result);
    }

    /** ****************** Contrast Strtching *************** */
    if (e.getSource() == mContrast) {
      String cont_value1, cont_value2;
      Image img_add = image;
      pixel_cont = new int[w * h];

      pixel_result = pixel_grab(img_add, w, h);

      cont_value1 = JOptionPane.showInputDialog("Enter lower limit for contrast stretch");
      int number = Integer.parseInt(cont_value1);
      cont_value2 = JOptionPane.showInputDialog("Enter higher limit for contrast stretch");
      int number1 = Integer.parseInt(cont_value2);

      for (int r = 0; r < w * h; r++) {
        if (pixel_result[r] <= number1) {

          pixel_cont[r] = pixel_result[r] - 50;
          if (pixel_cont[r] < 0) pixel_cont[r] = 0;
        } else if (pixel_result[r] >= number) {
          pixel_cont[r] = pixel_result[r] + 50;

          if (pixel_cont[r] > 255) pixel_cont[r] = 255;

        } else pixel_cont[r] = pixel_result[r];
      }

      pixel_cont = saturate(pixel_cont, w, h);
      pixel_cont = pix_pack(pixel_cont, w, h);
      imageResultDisplay(w, h, pixel_cont);
    }

    /** ******************* Low Pass Filter ****************** */
    if (e.getSource() == mlowPass) {
      int mask[][] = {{1, 1, 1}, {1, 1, 1}, {1, 1, 1}};

      pixel_result = pixel_grab(image, w, h);

      int pix_tempLow[][] = new int[h][w];

      pix_tempLow = OneD_ArrayToTwoD_Array(w, h, pixel_result);

      pix_tempLow = MaskOperation(w, h, pix_tempLow, mask);
      int pix_temp1D[] = new int[(w) * (h)];

      pix_temp1D = TwoD_ArrayToOneD_Array(w, h, pix_tempLow);

      pix_temp1D = restrict(pix_temp1D);
      pix_temp1D = pix_pack(pix_temp1D, w - 2, h - 2);
      imageResultDisplay(w - 2, h - 2, pix_temp1D);
    }

    /** ********************* High Pass Filter *************** */
    if (e.getSource() == mhighPass) {
      int mask[][] = {{-1, -1, -1}, {-1, 8, -1}, {-1, -1, -1}};

      pixel_result = pixel_grab(image, w, h);

      int pix_tempLow[][] = new int[h][w];

      pix_tempLow = OneD_ArrayToTwoD_Array(w, h, pixel_result);

      pix_tempLow = MaskOperation(w, h, pix_tempLow, mask);
      int pix_temp1D[] = new int[(w) * (h)];

      pix_temp1D = TwoD_ArrayToOneD_Array(w, h, pix_tempLow);

      pix_temp1D = saturate(pix_temp1D, w - 2, h - 2);
      pix_temp1D = restrict(pix_temp1D);
      pix_temp1D = pix_pack(pix_temp1D, w - 2, h - 2);
      imageResultDisplay(w - 2, h - 2, pix_temp1D);
    }

    /** *************************** High Boost Filter **************** */
    if (e.getSource() == mhighBoost) {
      int mask[][] = {{-1, -1, -1}, {-1, 9, -1}, {-1, -1, -1}};

      pixel_result = pixel_grab(image, w, h);

      int pix_tempLow[][] = new int[h][w];

      pix_tempLow = OneD_ArrayToTwoD_Array(w, h, pixel_result);

      pix_tempLow = MaskOperation(w, h, pix_tempLow, mask);
      int pix_temp1D[] = new int[(w) * (h)];

      pix_temp1D = TwoD_ArrayToOneD_Array(w, h, pix_tempLow);
      pix_temp1D = saturate(pix_temp1D, w - 2, h - 2);
      pix_temp1D = restrict(pix_temp1D);
      pix_temp1D = pix_pack(pix_temp1D, w - 2, h - 2);
      imageResultDisplay(w - 2, h - 2, pix_temp1D);
    }

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

      for (int i = 0; i < w * h; i++) {
        System.out.println(pixel_result[i]);
      }

      FileImageOutputStream src_img;

      int returnVal = jfc.showSaveDialog(IPToolKit.this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        File fileR = jfc.getSelectedFile();
        String fileToSave = file.getAbsolutePath();

        if (!fileToSave.toLowerCase().endsWith(".jpg")) {
          fileR = new File(fileToSave + ".jpg");
        }

        try {
          src_img = new FileImageOutputStream(fileR);
          buf_img = getImageFromArray(pixel_result, w, h);
          ImageIO.write(buf_img, "jpg", src_img);

        } catch (IOException ex8) {
          System.out.println(ex8);
        }
      }
    }

    /** ********************* Invert and image ************ */
    if (e.getSource() == mInvert) {

      Image img_Invert = image;
      pixel_result = new int[w * h];

      pixel_result = pixel_grab(img_Invert, w, h);

      for (int r = 0; r < w * h; r++) {
        pixel_result[r] = 255 - pixel_result[r];
      }

      //	pixel_div = saturate(pixel_div,w,h);
      pixel_result = pix_pack(pixel_result, w, h);
      imageResultDisplay(w, h, pixel_result);
    }
    /** *************************** Median Filter **************** */
    if (arg.equals("Median")) {
      int[] pix_grabed = new int[w * h];
      int[][] p2d = new int[h][w];
      int[][] pp2d = new int[h][w];
      int pix_pcked[] = new int[w * h];
      int pres[] = new int[h * w];

      pix_grabed = pixel_grab(image, w, h);
      p2d = OneD_ArrayToTwoD_Array(w, h, pix_grabed);
      pp2d = median_filter(p2d);
      pres = TwoD_ArrayToOneD_Array(w, h, pp2d);
      pix_pcked = pix_pack(pres, w - 2, h - 2);
      imageResultDisplay(w - 2, h - 2, pix_pcked);
    }

    /** ********************** Prewits Horizontal Edge Detection ******************* */
    if (arg.equals("Prewits Horizontal")) {

      int[] pix_grabed = new int[w * h];
      int[][] p2d = new int[h][w];
      int[][] pp2d = new int[h][w];
      int pix_pcked[] = new int[w * h];
      int pres[] = new int[h * w];

      int mask[][] = {{-1, -1, -1}, {0, 0, 0}, {1, 1, 1}};

      pix_grabed = pixel_grab(image, w, h);
      p2d = OneD_ArrayToTwoD_Array(w, h, pix_grabed);
      pp2d = MaskOperation(w, h, p2d, mask);

      pres = TwoD_ArrayToOneD_Array(w, h, pp2d);
      pres = saturate(pres, w - 2, h - 2);
      pres = restrict(pres);
      pix_pcked = pix_pack(pres, w - 2, h - 2);
      imageResultDisplay(w - 2, h - 2, pix_pcked);
    }

    /** ********************** Prewits Vertical Edge Detection ******************* */
    if (arg.equals("Prewits Vertical")) {

      int[] pix_grabed = new int[w * h];
      int[][] p2d = new int[h][w];
      int[][] pp2d = new int[h][w];
      int pix_pcked[] = new int[w * h];
      int pres[] = new int[h * w];

      int mask[][] = {{-1, 0, 1}, {-1, 0, 1}, {-1, 0, 1}};

      pix_grabed = pixel_grab(image, w, h);
      p2d = OneD_ArrayToTwoD_Array(w, h, pix_grabed);
      pp2d = MaskOperation(w, h, p2d, mask);

      pres = TwoD_ArrayToOneD_Array(w, h, pp2d);
      pres = saturate(pres, w - 2, h - 2);
      pres = restrict(pres);
      pix_pcked = pix_pack(pres, w - 2, h - 2);
      imageResultDisplay(w - 2, h - 2, pix_pcked);
    }

    /** ********************** Prewits Edge Detection ******************* */
    if (arg.equals("Prewits Both")) {

      int[] pix_grabed = new int[w * h];
      int[][] p2d = new int[h][w];
      int[][] pp2d = new int[h][w];
      int pix_pcked[] = new int[w * h];
      int pres1[] = new int[h * w];
      int pres2[] = new int[h * w];
      int pres[] = new int[h * w];
      int mask1[][] = {{-1, -1, -1}, {0, 0, 0}, {1, 1, 1}};

      pix_grabed = pixel_grab(image, w, h);

      p2d = OneD_ArrayToTwoD_Array(w, h, pix_grabed);
      pp2d = MaskOperation(w, h, p2d, mask1);
      pres1 = TwoD_ArrayToOneD_Array(w, h, pp2d);
      pres1 = saturate(pres1, w - 2, h - 2);
      pres1 = restrict(pres1);
      int mask2[][] = {{-1, 0, 1}, {-1, 0, 1}, {-1, 0, 1}};
      p2d = OneD_ArrayToTwoD_Array(w, h, pix_grabed);
      pp2d = MaskOperation(w, h, p2d, mask2);
      pres2 = TwoD_ArrayToOneD_Array(w, h, pp2d);
      pres2 = saturate(pres2, w - 2, h - 2);
      pres2 = restrict(pres2);
      for (int i = 0; i < ((h - 2) * (w - 2)); i++) {
        pres[i] = pres1[i] + pres2[i];
      }

      pix_pcked = pix_pack(pres, w - 2, h - 2);
      imageResultDisplay(w - 2, h - 2, pix_pcked);
    }

    /** ********************** Sobel Horizontal Edge Detection ******************* */
    if (arg.equals("Sobel Horizontal")) {

      int[] pix_grabed = new int[w * h];
      int[][] p2d = new int[h][w];
      int[][] pp2d = new int[h][w];
      int pix_pcked[] = new int[w * h];
      int pres[] = new int[h * w];

      int mask[][] = {{-1, -2, -1}, {0, 0, 0}, {1, 2, 1}};

      pix_grabed = pixel_grab(image, w, h);
      p2d = OneD_ArrayToTwoD_Array(w, h, pix_grabed);
      pp2d = MaskOperation(w, h, p2d, mask);
      pres = TwoD_ArrayToOneD_Array(w, h, pp2d);
      pres = saturate(pres, w - 2, h - 2);
      pres = restrict(pres);
      pix_pcked = pix_pack(pres, w - 2, h - 2);
      imageResultDisplay(w - 2, h - 2, pix_pcked);
    }

    /** ********************** Sobel Vertical Edge Detection ******************* */
    if (arg.equals("Sobel Vertical")) {

      int[] pix_grabed = new int[w * h];
      int[][] p2d = new int[h][w];
      int[][] pp2d = new int[h][w];
      int pix_pcked[] = new int[w * h];
      int pres[] = new int[h * w];

      int mask[][] = {{-1, 0, 1}, {-2, 0, 2}, {-1, 0, 1}};

      pix_grabed = pixel_grab(image, w, h);
      p2d = OneD_ArrayToTwoD_Array(w, h, pix_grabed);
      pp2d = MaskOperation(w, h, p2d, mask);

      pres = TwoD_ArrayToOneD_Array(w, h, pp2d);
      pres = saturate(pres, w - 2, h - 2);
      pres = restrict(pres);
      pix_pcked = pix_pack(pres, w - 2, h - 2);
      imageResultDisplay(w - 2, h - 2, pix_pcked);
    }

    /** ********************** Sobel Edge Detection ******************* */
    if (arg.equals("Sobel Both")) {

      int[] pix_grabed = new int[w * h];
      int[][] p2d = new int[h][w];
      int[][] pp2d = new int[h][w];
      int pix_pcked[] = new int[w * h];
      int pres1[] = new int[h * w];
      int pres2[] = new int[h * w];
      int pres[] = new int[h * w];

      int mask1[][] = {{-1, -2, -1}, {0, 0, 0}, {1, 2, 1}};

      pix_grabed = pixel_grab(image, w, h);

      p2d = OneD_ArrayToTwoD_Array(w, h, pix_grabed);
      pp2d = MaskOperation(w, h, p2d, mask1);
      pres1 = TwoD_ArrayToOneD_Array(w, h, pp2d);
      pres1 = saturate(pres1, w - 2, h - 2);
      pres1 = restrict(pres1);
      int mask2[][] = {{-1, 0, 1}, {-2, 0, 2}, {-1, 0, 1}};
      p2d = OneD_ArrayToTwoD_Array(w, h, pix_grabed);
      pp2d = MaskOperation(w, h, p2d, mask2);
      pres2 = TwoD_ArrayToOneD_Array(w, h, pp2d);
      pres2 = saturate(pres2, w - 2, h - 2);
      pres2 = restrict(pres2);
      for (int i = 0; i < ((h - 2) * (w - 2)); i++) {
        pres[i] = pres1[i] + pres2[i];
      }

      pix_pcked = pix_pack(pres, w - 2, h - 2);
      imageResultDisplay(w - 2, h - 2, pix_pcked);
    }

    /** ********************** Roberts Edge Detection ******************* */
    if (arg.equals("Roberts")) {

      int[] pix_grabed = new int[w * h];
      int[][] p2d = new int[h][w];
      int[][] pp2d = new int[h][w];
      int pix_pcked[] = new int[w * h];
      int pres[] = new int[h * w];

      int mask[][] = {{1, 0}, {0, -1}};
      pix_grabed = pixel_grab(image, w, h);
      p2d = OneD_ArrayToTwoD_Array(w, h, pix_grabed);

      for (int i = 1; i < h - 1; i++) {
        for (int j = 1; j < w - 1; j++) {
          pp2d[i][j] =
              ((mask[0][0] * p2d[i - 1][j - 1] + mask[1][0] * p2d[i + 1][j - 1])
                      + (mask[0][1] * p2d[i - 1][j + 1] + mask[1][1] * p2d[i + 1][j + 1]))
                  / 2;
        }
      }

      pres = TwoD_ArrayToOneD_Array(w, h, pp2d);
      pres = saturate(pres, w - 2, h - 2);
      pix_pcked = pix_pack(pres, w - 2, h - 2);
      imageResultDisplay(w - 2, h - 2, pix_pcked);
    }

    /** ********************** Mean Filter ******************* */
    if (arg.equals("Mean")) {
      int[] pix_grabed = new int[w * h];
      int[][] p2d = new int[h][w];
      int[][] pp2d = new int[h][w];
      int pix_pcked[] = new int[w * h];
      int pres[] = new int[h * w];

      pix_grabed = pixel_grab(image, w, h);
      p2d = OneD_ArrayToTwoD_Array(w, h, pix_grabed);
      pp2d = mean_filt(p2d);
      pres = TwoD_ArrayToOneD_Array(w, h, pp2d);
      pix_pcked = pix_pack(pres, w - 2, h - 2);
      imageResultDisplay(w - 2, h - 2, pix_pcked);
    }

    /** ********************** Laplacian Edge Detector ******************* */
    if (arg.equals("Laplacian")) {
      int[] pix_grabed = new int[w * h];
      int[][] p2d = new int[h][w];
      int[][] pp2d = new int[h][w];
      int pix_pcked[] = new int[w * h];
      int pres[] = new int[h * w];

      int mask[][] = {{0, -2, 0}, {-2, 8, -2}, {0, -2, 0}};

      pix_grabed = pixel_grab(image, w, h);
      p2d = OneD_ArrayToTwoD_Array(w, h, pix_grabed);
      pp2d = MaskOperation(w, h, p2d, mask);

      pres = TwoD_ArrayToOneD_Array(w, h, pp2d);
      pres = saturate(pres, w - 2, h - 2);
      pres = restrict(pres);
      pix_pcked = pix_pack(pres, w - 2, h - 2);
      imageResultDisplay(w - 2, h - 2, pix_pcked);
    }

    /** ********************** Histogram Equalization ******************* */
    if (arg.equals("Histogram Equalization")) {
      int[] pix_grabed = new int[h * w];
      int pres[] = new int[h * w];
      int cnt_pix[] = new int[256];
      int pixx[] = new int[h * w];
      int pix_pcked[] = new int[h * w];
      int pix_res[] = new int[h * w];
      int len = h * w;
      int res = 0;

      pix_grabed = pixel_grab(image, w, h);

      for (int i = 0; i < h * w; i++) {
        pixx[i] = pix_grabed[i];
      }

      for (int i = 0; i < 256; i++) {

        cnt_pix[i] = 0;
      }

      for (int i = 0; i < len; i++) {

        int ind = pixx[i];
        cnt_pix[ind]++;
      }

      for (int i = 0; i < w * h; i++) {
        float a = 0;

        for (int j = 0; j < (pixx[i] + 1); j++) {
          float b = (float) cnt_pix[j];

          float c = (float) (h * w);

          a = a + (b / c);
        }

        res = (int) (a * 255);
        if (res > 255) res = 255;

        pix_res[i] = (0xff000000 | (res << 16) | (res << 8) | res);
      }

      pix_pcked = pix_pack(pix_res, w, h);
      imageResultDisplay(w, h, pix_pcked);
    }

    if (arg.equals("Connected Component")) {
      int pix_grabed[] = new int[h * w];
      int p2d[][] = new int[h][w];
      conect_input = new int[h][w];
      conect_output = new int[h][w];

      int x1 = x_cor;
      int y1 = y_cor;

      pix_grabed = pixel_grab(image, w, h);
      p2d = OneD_ArrayToTwoD_Array(w, h, pix_grabed);
      s = 0;
      t = 0;
      obj_size = 0;
      intensity = p2d[y1][x1];

      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          conect_input[i][j] = p2d[i][j];
          conect_output[i][j] = 0;
        }
      }

      connect(y1, x1);
      int pixx[] = new int[h * w];
      int pp[] = new int[h * w];

      pixx = TwoD_ArrayToOneD_Array(w, h, conect_output);
      pixx = saturate(pixx, w - 2, h - 2);
      pp = pix_pack(pixx, w - 2, h - 2);
      imageResultDisplay(w - 2, h - 2, pp);
    }

    /** ********************** Blending ******************* */
    if (arg.equals("Blending")) {

      int size;
      int hei, wid;
      if (h1 > h) hei = h1;
      else hei = h;

      if (w1 > w) wid = w1;
      else wid = w;

      size = hei * wid;
      int pix_img1[] = new int[size];
      int pix_img2[] = new int[size];
      int pix_res[] = new int[size];
      int pixx[] = new int[h1 * w1];
      double x = 0.5;
      pix_img1 = pixel_grab(image, w, h);
      OpenImage2();
      pix_img2 = pixel_grab(image1, w1, h1);

      //	 grayImageDisplay(w1,h1,pixx)

      for (int i = 0; i < size; i++) {
        pix_res[i] = (int) ((x * pix_img1[i]) + ((1 - x) * (pix_img2[i])));
      }
      int pix_pcked[] = new int[size];

      pix_pcked = pix_pack(pix_res, wid, hei);
      imageResultDisplay(wid, hei, pix_pcked);
    }

    /** ****************** Quit OR Exit **************** */
    if (arg.equals("Exit")) {
      System.exit(0);
    }
  }
Esempio n. 17
0
  public LoginPanel(Image img, ActionListener listener) {
    super(null);
    this.listener = listener;
    if (img == null) {
      InputStream inData = getClass().getResourceAsStream("/resources/background.gif");
      BufferedImage back = null;
      if (inData != null)
        try {
          back = ImageIO.read(inData);
        } catch (IOException e) {
          loger.finest("LoginPanel class can't get the background image");
        }
      this.background = back;
    }

    setLayout(null);
    JPanel logingPanel = new JPanel();
    loginTitle = new JLabel("Autentificare");
    logingPanel.setSize(250, 150);
    logingPanel.setBorder(new javax.swing.border.LineBorder(Color.black, 2));
    logingPanel.setLayout(null);
    loginTitle.setBounds(3, 0, logingPanel.getWidth(), 20);
    logingPanel.add(loginTitle);
    JLabel loginUser = new JLabel("Utilizator");
    loginUser.setBounds(
        80 - loginUser.getPreferredSize().width,
        40,
        loginUser.getPreferredSize().width,
        loginUser.getPreferredSize().height);
    logingPanel.add(loginUser);
    user = new JTextField(10);
    user.setBounds(85, 40, user.getPreferredSize().width, user.getPreferredSize().height);
    // user.setText("test");
    // loginUser.setLabelFor(user);
    logingPanel.add(user);
    JLabel loginPass = new JLabel("Parola");
    loginPass.setBounds(
        80 - loginPass.getPreferredSize().width,
        80,
        loginPass.getPreferredSize().width,
        loginPass.getPreferredSize().height);
    logingPanel.add(loginPass);
    // JTextField pass = new JTextField(10);
    pass = new JPasswordField(10);
    pass.setBounds(85, 80, pass.getPreferredSize().width, pass.getPreferredSize().height);
    pass.addKeyListener(this);
    // pass.setText("test");
    // loginUser.setLabelFor(user);
    logingPanel.add(pass);
    JButton loginButton = new JButton("Start");
    loginButton.setActionCommand("LOGIN");
    loginButton.setBounds(
        60, 110, loginButton.getPreferredSize().width, loginButton.getPreferredSize().height);
    // loginButton.setOpaque(false);
    loginButton.setFocusPainted(false);
    // loginButton.setContentAreaFilled(false);
    // loginButton.setBorderPainted(false);
    loginButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    loginButton.addActionListener(listener);
    logingPanel.add(loginButton);

    add(logingPanel);
  }