Example #1
0
 public MainPanel() {
   super(new BorderLayout());
   BufferedImage bi = null;
   try {
     bi = ImageIO.read(getClass().getResource("test.jpg"));
   } catch (IOException ioe) {
     ioe.printStackTrace();
   }
   bufferedImage = bi;
   List<AbstractAction> list =
       Arrays.asList(
           new AbstractAction("NONE") {
             @Override
             public void actionPerformed(ActionEvent e) {
               mode = Flip.NONE;
               repaint();
             }
           },
           new AbstractAction("VERTICAL") {
             @Override
             public void actionPerformed(ActionEvent e) {
               mode = Flip.VERTICAL;
               repaint();
             }
           },
           new AbstractAction("HORIZONTAL") {
             @Override
             public void actionPerformed(ActionEvent e) {
               mode = Flip.HORIZONTAL;
               repaint();
             }
           });
   Box box = Box.createHorizontalBox();
   box.add(Box.createHorizontalGlue());
   box.add(new JLabel("Flip: "));
   for (AbstractAction a : list) {
     JRadioButton rb = new JRadioButton(a);
     if (bg.getButtonCount() == 0) {
       rb.setSelected(true);
     }
     box.add(rb);
     bg.add(rb);
     box.add(Box.createHorizontalStrut(5));
   }
   add(p);
   add(box, BorderLayout.SOUTH);
   setOpaque(false);
   setPreferredSize(new Dimension(320, 240));
 }
Example #2
0
  public MainPanel() {
    super(new BorderLayout());
    ActionListener al =
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            JComponent c = (JComponent) e.getSource();
            if (ra.equals(c)) {
              label.setIcon(iia);
            } else if (rb.equals(c)) {
              label.setIcon(iib);
            } else {
              label.setIcon(new ImageIcon(createImage(source)));
            }
          }
        };
    JPanel p = new JPanel();
    ButtonGroup bg = new ButtonGroup();
    for (JRadioButton r : Arrays.asList(ra, rb, rr)) {
      r.addActionListener(al);
      bg.add(r);
      p.add(r);
    }
    ra.setSelected(true);
    add(label);
    add(p, BorderLayout.SOUTH);

    int w = iia.getIconWidth();
    int h = iia.getIconHeight();
    int[] pixelsA = getData(iia, w, h);
    int[] pixelsB = getData(iib, w, h);
    source = new MemoryImageSource(w, h, pixelsA, 0, w);
    for (int i = 0; i < pixelsA.length; i++) {
      if (pixelsA[i] == pixelsB[i]) {
        pixelsA[i] = pixelsA[i] & 0x44FFFFFF;
      }
    }

    setPreferredSize(new Dimension(320, 240));
  }
  // Constructor connection receiving a socket number
  public ClientGUI(String host, int port, int udpPort) {

    super("Clash of Clans");
    defaultPort = port;
    defaultUDPPort = udpPort;
    defaultHost = host;

    // the server name and the port number
    JPanel serverAndPort = new JPanel(new GridLayout(1, 5, 1, 3));
    tfServer = new JTextField(host);
    tfPort = new JTextField("" + port);
    tfPort.setHorizontalAlignment(SwingConstants.RIGHT);

    // CHAT COMPONENTS
    chatStatus = new JLabel("Please login first", SwingConstants.LEFT);
    chatField = new JTextField(18);
    chatField.setBackground(Color.WHITE);

    JPanel chatControls = new JPanel();
    chatControls.add(chatStatus);
    chatControls.add(chatField);
    chatControls.setBounds(0, 0, 200, 50);

    chatArea = new JTextArea("Welcome to the Chat room\n", 80, 80);
    chatArea.setEditable(false);
    JScrollPane jsp = new JScrollPane(chatArea);
    jsp.setBounds(0, 50, 200, 550);

    JPanel chatPanel = new JPanel(null);
    chatPanel.setSize(1000, 600);
    chatPanel.add(chatControls);
    chatPanel.add(jsp);

    // LOGIN COMPONENTS
    mainLogin = new MainPanel();
    mainLogin.add(new JLabel("Main Login"));

    usernameField = new JTextField("user", 15);
    passwordField = new JTextField("password", 15);
    login = new CButton("Login");
    login.addActionListener(this);

    sideLogin = new SidePanel(new FlowLayout(FlowLayout.LEFT));
    sideLogin.add(usernameField);
    sideLogin.add(passwordField);
    sideLogin.add(login);

    // MAIN MENU COMPONENTS
    mainMenu = new MainPanel();
    mmLabel = new JLabel("Main Menu");
    timer = new javax.swing.Timer(1000, this);
    mainMenu.add(mmLabel);

    sideMenu = new SidePanel(new FlowLayout(FlowLayout.LEFT));
    cmButton = new CButton("Customize Map");
    tmButton = new CButton("Troop Movement");
    gsButton = new CButton("Game Start");
    logout = new CButton("Logout");
    cmButton.addActionListener(this);
    tmButton.addActionListener(this);
    gsButton.addActionListener(this);
    logout.addActionListener(this);
    sideMenu.add(cmButton);
    // sideMenu.add(tmButton);
    sideMenu.add(gsButton);
    sideMenu.add(logout);

    // CM COMPONENTS
    mainCM = new MainPanel(new GridLayout(mapSize, mapSize));
    tiles = new Tile[mapSize][mapSize];
    int tileSize = mainCM.getWidth() / mapSize;
    for (int i = 0; i < mapSize; i++) {
      tiles[i] = new Tile[mapSize];
      for (int j = 0; j < mapSize; j++) {
        tiles[i][j] = new Tile(i, j);
        tiles[i][j].setPreferredSize(new Dimension(tileSize, tileSize));
        tiles[i][j].setSize(tileSize, tileSize);
        tiles[i][j].addActionListener(this);

        if ((i + j) % 2 == 0) tiles[i][j].setBackground(new Color(102, 255, 51));
        else tiles[i][j].setBackground(new Color(51, 204, 51));

        mainCM.add(tiles[i][j]);
      }
    }

    sideCM = new SidePanel(new FlowLayout(FlowLayout.LEFT));
    cmBack = new CButton("Main Menu");
    cmBack.setSize(150, 30);
    cmBack.setPreferredSize(new Dimension(150, 30));
    cmBack.addActionListener(this);
    sideCM.add(cmBack);

    // TM COMPONENTS
    mainTM = new MainPanel(null);
    mapTM = new Map(600);
    mapTM.setPreferredSize(new Dimension(600, 600));
    mapTM.setSize(600, 600);
    mapTM.setBounds(0, 0, 600, 600);
    mainTM.add(mapTM);

    sideTM = new SidePanel(new FlowLayout(FlowLayout.LEFT));
    tmBack = new CButton("Main Menu");
    tmBack.setSize(150, 30);
    tmBack.setPreferredSize(new Dimension(150, 30));
    tmBack.addActionListener(this);
    sideTM.add(tmBack);

    JRadioButton button;
    ButtonGroup group;

    ub = new ArrayList<JRadioButton>();
    group = new ButtonGroup();

    button = new JRadioButton("Barbarian");
    button.addActionListener(this);
    ub.add(button);
    sideTM.add(button);
    group.add(button);

    button = new JRadioButton("Archer");
    button.addActionListener(this);
    ub.add(button);
    sideTM.add(button);
    group.add(button);

    createBuildings();
    bb = new ArrayList<JRadioButton>();

    group = new ButtonGroup();

    JRadioButton removeButton = new JRadioButton("Remove Building");
    bb.add(removeButton);
    sideCM.add(removeButton);
    group.add(removeButton);

    for (int i = 0; i < bList.size(); i++) {
      button = new JRadioButton(bList.get(i).getName() + '-' + bList.get(i).getQuantity());
      bb.add(button);
      sideCM.add(button);
      group.add(button);
    }

    mainPanels = new MainPanel(new CardLayout());
    mainPanels.add(mainLogin, "Login");
    mainPanels.add(mainMenu, "Menu");
    mainPanels.add(mainCM, "CM");
    mainPanels.add(mainTM, "TM");

    sidePanels = new SidePanel(new CardLayout());
    sidePanels.add(sideLogin, "Login");
    sidePanels.add(sideMenu, "Menu");
    sidePanels.add(sideCM, "CM");
    sidePanels.add(sideTM, "TM");

    JPanel mainPanel = new JPanel(null);
    mainPanel.setSize(1000, 600);
    mainPanel.add(sidePanels);
    mainPanel.add(mainPanels);
    mainPanel.add(chatPanel);

    add(mainPanel, BorderLayout.CENTER);

    try {
      setIconImage(ImageIO.read(new File("images/logo.png")));
    } catch (IOException exc) {
      exc.printStackTrace();
    }

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(1000, 600);
    setVisible(true);
    setResizable(false);
    chatField.requestFocus();
  }
Example #4
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);
  }
  public Display(String title) throws IOException {

    super(title);
    setLayout(new GridLayout(1, 3));
    JPanel options = new JPanel(new GridLayout(5, 1));
    JPanel numCircles = new JPanel((new GridLayout(1, 2)));
    addWindowListener(this);
    b = new Button("Load Image");
    c = new Button("filter");
    findCircles = new Button("Find");

    inputCircles = new JTextField("12");
    numCircles.add(inputCircles);
    numCircles.add(findCircles);
    options.add(b);
    options.add(c);
    add(options);

    filterBtn = new JRadioButton("Filtered");
    sobelBtn = new JRadioButton("Sobel");
    nonMaxBtn = new JRadioButton("Non Maximal");
    accumulator = new JRadioButton("Accumulator");
    whichRadius = new JSlider(JSlider.HORIZONTAL, rmin, 125, 14);

    whichRadius.setMajorTickSpacing(10);
    whichRadius.setMinorTickSpacing(1);
    whichRadius.setPaintTicks(true);
    whichRadius.setPaintLabels(true);
    whichRadius.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
    Font font = new Font("Serif", Font.ITALIC, 6);
    whichRadius.setFont(font);

    ButtonGroup rGroup = new ButtonGroup();
    rGroup.add(filterBtn);
    rGroup.add(sobelBtn);
    rGroup.add(nonMaxBtn);
    rGroup.add(accumulator);

    JPanel radioPanel = new JPanel(new GridLayout(0, 1));
    radioPanel.add(filterBtn);
    radioPanel.add(sobelBtn);
    radioPanel.add(nonMaxBtn);
    radioPanel.add(accumulator);

    options.add(radioPanel);
    options.add(numCircles);
    options.add(whichRadius);
    loadImage();
    add(lbl1);
    add(lbl2);
    b.addActionListener(this);
    c.addActionListener(this);

    filterBtn.addActionListener(this);
    sobelBtn.addActionListener(this);
    nonMaxBtn.addActionListener(this);
    findCircles.addActionListener(this);
    accumulator.addActionListener(this);

    whichRadius.addChangeListener(this);
  }
Example #6
0
  public ImageSettings() {
    // Single Image Settings
    slice.add(new JLabel("Single Image Settings:"));
    newSlice();
    ButtonGroup group = new ButtonGroup();
    singleCylindrical = new JRadioButton("Cylindrical projection");
    singleCylindrical.setSelected(true);
    group.add(singleCylindrical);
    slice.add(singleCylindrical);
    newSlice();

    singleEllipse = new JRadioButton("Elliptical projection");
    singleEllipse.setSelected(false);
    group.add(singleEllipse);
    slice.add(singleEllipse);
    newSlice();

    singleSizeLabel = new JLabel("Image height=" + singleSize);
    slice.add(singleSizeLabel);
    singleSizeUp = new JButton("Up");
    singleSizeDown = new JButton("Down");
    singleSizeUp.addActionListener(this);
    singleSizeDown.addActionListener(this);
    slice.add(singleSizeUp);
    slice.add(singleSizeDown);
    newSlice();

    singleSquare = new JRadioButton("Square the image");
    singleSquare.setSelected(true);
    slice.add(singleSquare);
    newSlice();

    singleFaults = new JRadioButton("Show faultlines");
    singleFaults.setSelected(true);
    slice.add(singleFaults);
    newSlice();

    singleAgeDots = new JRadioButton("Show age dots");
    singleAgeDots.setSelected(true);
    slice.add(singleAgeDots);
    newSlice();

    // Sequence Image Settings
    slice.add(new JLabel("Sequence Image Settings:"));
    newSlice();
    ButtonGroup group2 = new ButtonGroup();
    seqCylindrical = new JRadioButton("Cylindrical projection");
    seqCylindrical.setSelected(true);
    group2.add(seqCylindrical);
    slice.add(seqCylindrical);
    newSlice();

    seqEllipse = new JRadioButton("Elliptical projection");
    seqEllipse.setSelected(false);
    group2.add(seqEllipse);
    slice.add(seqEllipse);
    newSlice();

    seqSizeLabel = new JLabel("Image height=" + seqSize);
    slice.add(seqSizeLabel);
    seqSizeUp = new JButton("Up");
    seqSizeDown = new JButton("Down");
    seqSizeUp.addActionListener(this);
    seqSizeDown.addActionListener(this);
    slice.add(seqSizeUp);
    slice.add(seqSizeDown);
    newSlice();

    seqSquare = new JRadioButton("Square the images");
    seqSquare.setSelected(false);
    slice.add(seqSquare);
    newSlice();

    seqFaults = new JRadioButton("Show faultlines");
    seqFaults.setSelected(true);
    slice.add(seqFaults);
    newSlice();

    seqAgeDots = new JRadioButton("Show age dots");
    seqAgeDots.setSelected(true);
    slice.add(seqAgeDots);
    // newSlice();

  }