Example #1
0
 public static void Initialize() {
   spConversation.setVisible(false);
   spUsersOnline.setVisible(false);
   messageField.setVisible(false);
   disconnect.setVisible(false);
   send.setVisible(false);
   userNameLabel.setVisible(true);
   userNameBox.setVisible(true);
   connectButton.setVisible(true);
 }
Example #2
0
  public static void connect() {
    final int port = 1337;
    final String host = "chat.linkura.se";

    userName = userNameBox.getText().trim();
    int count = 0;
    for (int i = 0; i < userName.length(); i++) {
      if (userName.charAt(i) == ' ') {
        count++;
      }
    }

    if (count != 0) {
      error.setText("Du får inte ha mellanslag i användarnamnet!");
    } else if (userName.isEmpty()) {
      error.setText("Skriv ett användarnamn!");
    } else if (!userName.matches("[a-öA-Ö0-9]+")) {
      error.setText("Användarnamnet får bara innhålla siffror och bokstäver!");
    } else if (userName.length() > 15) {
      error.setText("Ditt användarnamn får max vara 15 tecken!");
    } else {
      try {
        Socket socket = new Socket(host, port);
        testThread = new TestThread(socket);
        Thread x = new Thread(testThread);
        x.start();

        PrintWriter out = new PrintWriter(socket.getOutputStream());

        out.println("NICK " + userName);
        out.flush();

        userNameLabel.setVisible(false);
        userNameBox.setVisible(false);
        connectButton.setVisible(false);
        messageField.setVisible(true);
        messageField.requestFocus();
        send.setVisible(true);
        spConversation.setVisible(true);
        spUsersOnline.setVisible(true);
        disconnect.setVisible(true);

      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
Example #3
0
 // Updates the Buttons and what is visible and what isn't
 private void updateGui() {
   updateDisplay();
   if (!itemSelected) {
     for (int i = 0; i < pockets.length; i++) {
       pockets[i].setVisible(true);
       pages[i].setVisible(true);
     }
     for (JButton aDisplay : display) {
       aDisplay.setVisible(true);
     }
     information.setVisible(true);
     closeButton.setVisible(true);
     moneyDisplay.setVisible(true);
     buySellButton.setVisible(true);
     buyButton.setVisible(false);
     amountField.setVisible(false);
     amountDisplay.setVisible(false);
     totalAmount.setVisible(false);
     buyButton.setVisible(false);
     sellButton.setVisible(false);
     moneyDisplay.setText("Money: $" + Inventory.money);
     updatePageButtons();
   } else {
     if (state == State.BUY) {
       buyButton.setVisible(true);
       sellButton.setVisible(false);
     } else {
       buyButton.setVisible(false);
       sellButton.setVisible(true);
     }
     amountDisplay.setVisible(true);
     totalAmount.setVisible(true);
     buySellButton.setVisible(false);
     for (int i = 1; i < display.length; i++) {
       display[i].setVisible(false);
     }
     amountField.setVisible(true);
     for (int i = 0; i < pockets.length; i++) {
       pockets[i].setVisible(false);
       pages[i].setVisible(false);
     }
     moneyDisplay.setText("Money: $" + Inventory.money);
   }
 }
  private void setupTypeInfo(Type.Continuous t) {
    UPBDetailPanel.setVisible(false);
    LWBDetailPanel.setVisible(false);

    yesUPB.setEnabled(false);
    noUPB.setEnabled(false);
    unspecifiedUPB.setEnabled(false);
    if (t.UPB < Double.MAX_VALUE) {
      yesUPB.setSelected(true);
      specifyUPB.setVisible(true);
      UPBDetailPanel.setVisible(true);
      if (t.UPB < Double.MAX_VALUE - Double.MIN_VALUE) {
        specifyUPB.setEnabled(false);
        specifyUPB.setSelected(true);
        UPBLabel.setVisible(true);
        UPBLabel.setEnabled(false);
        UPBLabel.setText("" + t.UPB);
      } else {
        specifyUPB.setEnabled(true);
        specifyUPB.setSelected(false);
        UPBLabel.setVisible(false);
        UPBLabel.setEnabled(true);
      }
    } else {
      unspecifiedUPB.setEnabled(true);
      specifyUPB.setVisible(false);
      UPBLabel.setVisible(false);
    }

    yesLWB.setEnabled(false);
    noLWB.setEnabled(false);
    unspecifiedLWB.setEnabled(false);
    if (t.LWB > -Double.MAX_VALUE) {
      yesLWB.setSelected(true);
      specifyLWB.setVisible(true);
      LWBDetailPanel.setVisible(true);
      if (t.LWB > -Double.MAX_VALUE + Double.MIN_VALUE) {
        specifyLWB.setEnabled(false);
        specifyLWB.setSelected(true);
        LWBLabel.setVisible(true);
        LWBLabel.setEnabled(false);
        LWBLabel.setText("" + t.LWB);
      } else {
        specifyLWB.setEnabled(true);
        specifyLWB.setSelected(false);
        LWBLabel.setVisible(false);
        LWBLabel.setEnabled(true);
      }
    } else {
      unspecifiedLWB.setEnabled(true);
      specifyLWB.setVisible(false);
      LWBLabel.setVisible(false);
    }

    if (t.ckIsCyclic) {
      yesCyclic.setEnabled(false);
      noCyclic.setEnabled(false);
      unspecifiedCyclic.setEnabled(false);
      if (t.isCyclic) {
        yesCyclic.setSelected(true);
      } else {
        noCyclic.setSelected(true);
      }
    } else {
      unspecifiedCyclic.setSelected(true);
      yesCyclic.setEnabled(true);
      noCyclic.setEnabled(true);
      unspecifiedCyclic.setEnabled(true);
    }

    excUPBButton.setEnabled(true);
    incUPBButton.setEnabled(true);
    incUPBButton.setSelected(true);

    excLWBButton.setEnabled(true);
    incLWBButton.setEnabled(true);
    incLWBButton.setSelected(true);
  }
Example #5
0
  // Sets up the window
  private void setUpGui() {
    this.setTitle("Mart");
    this.setSize(300, 550);
    this.setResizable(false);
    this.setLayout(null);
    URL iconU = Mart.class.getResource("icon.png");
    Image icon = Toolkit.getDefaultToolkit().getImage(iconU);
    this.setIconImage(icon);
    this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    this.setVisible(false);
    this.setLocationRelativeTo(null);

    Container cp = this.getContentPane();

    int x = 16;
    int y = 35;
    for (int i = 0; i < pockets.length; i++) {
      String messager = "";
      switch (i) {
        case 0:
          messager = "Items";
          break;
        case 1:
          messager = "Medicine";
          break;
        case 2:
          messager = "Pokeballs";
          break;
        case 3:
          messager = "TMs/HMs";
          break;
        case 4:
          messager = "Battle Items";
          break;
        case 5:
          messager = "Key Items";
          break;
      }
      pockets[i] = new JButton(messager);
      pockets[i].setBounds(x, y, 120, 20);
      pockets[i].addActionListener(this);
      pockets[i].setVisible(false);
      cp.add(pockets[i]);
      x += 140;
      if (x > this.getWidth() - 120) {
        x = 16;
        y += 30;
      }
    }

    amountDisplay = new JLabel("Amount: ");
    amountDisplay.setHorizontalAlignment(JLabel.LEFT);
    amountDisplay.setBounds(36, 150, 130, 20);
    amountDisplay.setVisible(false);
    cp.add(amountDisplay);

    totalAmount = new JLabel("Enter Amount");
    totalAmount.setHorizontalAlignment(JLabel.CENTER);
    totalAmount.setBounds(16, 180, 260, 20);
    totalAmount.setVisible(false);
    cp.add(totalAmount);

    amountField = new JTextField();
    amountField.setHorizontalAlignment(JLabel.CENTER);
    amountField.setBounds(96, 150, 180, 20);
    amountField.setVisible(false);
    amountField.addActionListener(this);
    cp.add(amountField);

    buyButton = new JButton("Buy Amount");
    buyButton.addActionListener(this);
    buyButton.setBounds(16, 210, 260, 20);
    buyButton.setVisible(false);
    buyButton.setEnabled(false);
    cp.add(buyButton);

    sellButton = new JButton("Sell Amount");
    sellButton.addActionListener(this);
    sellButton.setBounds(16, 210, 260, 20);
    sellButton.setVisible(false);
    sellButton.setEnabled(false);
    cp.add(sellButton);

    buySellButton = new JButton("Buying");
    buySellButton.setVisible(false);
    buySellButton.addActionListener(this);
    buySellButton.setBounds(16, 5, 260, 20);
    cp.add(buySellButton);

    y = 125;
    for (int i = 0; i < display.length; i++) {
      display[i] = new JButton();
      display[i].setHorizontalAlignment(JLabel.LEFT);
      display[i].addActionListener(this);
      display[i].setBounds(15, y, 260, 20);
      display[i].setVisible(false);
      y += 25;
      cp.add(display[i]);
    }

    x = 16;
    y = this.getHeight() - 120;
    for (int i = 0; i < pages.length; i++) {
      pages[i] = new JButton("Page " + (i + 1));
      pages[i].setBounds(x, y, 80, 20);
      pages[i].addActionListener(this);
      pages[i].setVisible(false);
      cp.add(pages[i]);
      x += 90;
      if (x > this.getWidth() - 20) {
        x = 16;
        y += 30;
      }
    }

    x = 16;
    y = this.getHeight() - 180;
    moneyDisplay = new JLabel("Money: $" + Inventory.money);
    moneyDisplay.setVisible(false);
    moneyDisplay.setHorizontalAlignment(JLabel.CENTER);
    moneyDisplay.setBounds(x, y, 260, 20);
    cp.add(moneyDisplay);

    information = new JButton("Information");
    information.setBounds(16, this.getHeight() - 150, 260, 20);
    information.addActionListener(this);
    information.setVisible(false);
    cp.add(information);

    closeButton = new JButton("Close Window");
    closeButton.setBounds(16, this.getHeight() - 60, 260, 20);
    closeButton.addActionListener(this);
    closeButton.setVisible(false);
    cp.add(closeButton);

    visible = false;
  }