Example #1
0
  public void JudgeWhoIsWinner() // 判断胜负
      {
    String winner = "";

    if (white == 0) {
      JOptionPane.showMessageDialog(null, "黑方胜!" + black + ":" + white);
      //			JOptionPane.showMessageDialog(null, "游戏结束!用时" + time + "秒");
      submit.setEnabled(false);
      winner = "黑";
    }
    if (black == 0) {
      JOptionPane.showMessageDialog(null, "白方胜!" + white + ":" + black);
      //			JOptionPane.showMessageDialog(null, "游戏结束!用时" + time + "秒");
      submit.setEnabled(false);
      winner = "白";
    }
    if (black + white == 64) {
      if (white > black) {
        JOptionPane.showMessageDialog(null, "白方胜!" + white + ":" + black);
        //				JOptionPane.showMessageDialog(null, "游戏结束!用时" + time + "秒");
        submit.setEnabled(false);
        winner = "白";
      } else if (black > white) {
        JOptionPane.showMessageDialog(null, "黑方胜!" + black + ":" + white);
        //				JOptionPane.showMessageDialog(null, "游戏结束!用时" + time + "秒");
        submit.setEnabled(false);
        winner = "白";
      } else if (black == white) {
        JOptionPane.showMessageDialog(null, "和局!");
        //				JOptionPane.showMessageDialog(null, "游戏结束!用时" + time + "秒");
        winner = "";
      }
    }
  }
  public static int rollbackGUIConfigurationTransaction(String sConfigurationFileName) {

    String sConfigurationLockFile;
    File fFile;

    sConfigurationLockFile = new String(sConfigurationFileName + ".lck");

    try {
      fFile = new File(URLDecoder.decode(sConfigurationLockFile, "UTF-8"));
    } catch (IOException e) {
      JOptionPane.showMessageDialog(
          null, "URLDecoder.decode failed", "ConfigurationTransaction", JOptionPane.ERROR_MESSAGE);

      return 1;
    }

    if (fFile.delete() == false) {
      JOptionPane.showMessageDialog(
          null,
          "fFile.delete on " + sConfigurationLockFile + " failed",
          "ConfigurationTransaction",
          JOptionPane.ERROR_MESSAGE);

      return 3;
    }

    return 0;
  }
 @Override
 public void run() {
   try {
     receive();
   } catch (IOException ioException) {
     JOptionPane.showMessageDialog(null, "Problems with a server");
   } catch (InterruptedException interruptedException) {
     JOptionPane.showMessageDialog(null, "Interrupted exception thrown");
   } catch (ParserConfigurationException parserException) {
     parserException.printStackTrace();
   } catch (SAXException saxException) {
     saxException.printStackTrace();
   }
 }
Example #4
0
  public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_ESCAPE && gamerunner.running) {

      Graphics gr = this.getGraphics();
      gr.setFont(new Font("TimesRoman", Font.PLAIN, 40));
      gr.drawString("PAUSE", (int) this.getWidth() / 2, this.getHeight() / 2);
      if (!online) {
        gamerunner.running = false;
      }
      if (soundan) {} // end of if
      Menu menu = new Menu(this);
      // volume.setValue(vol);
    } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
      gamerunner.running = true;
      if (soundan) {} // end of if
    } // end of if-else
    else if (e.getKeyCode() == KeyEvent.VK_R && !online) {
      restartGame();
    } else if (e.getKeyCode() == KeyEvent.VK_F11) {
      dispose();
      setUndecorated(true);
      String[] arguments = {"fullscreen"};
      new JavaGame(arguments);
    } else if (e.getKeyCode() == KeyEvent.VK_ENTER && online) {
      String message =
          JOptionPane.showInputDialog(null, "Chat", "Nachricht", JOptionPane.PLAIN_MESSAGE);
      try {
        if (!message.isEmpty()) {
          client.sendNewChatMessage(player[client.id].name, message);
        }
      } catch (IOException e1) {
        e1.printStackTrace();
      }
    }
  }
Example #5
0
    @Override
    public void actionPerformed(ActionEvent e) {
      Frame frame = getFrame();
      JFileChooser chooser = new JFileChooser();
      int ret = chooser.showOpenDialog(frame);

      if (ret != JFileChooser.APPROVE_OPTION) {
        return;
      }

      File f = chooser.getSelectedFile();
      if (f.isFile() && f.canRead()) {
        Document oldDoc = getEditor().getDocument();
        if (oldDoc != null) {
          oldDoc.removeUndoableEditListener(undoHandler);
        }
        if (elementTreePanel != null) {
          elementTreePanel.setEditor(null);
        }
        getEditor().setDocument(new PlainDocument());
        frame.setTitle(f.getName());
        Thread loader = new FileLoader(f, editor.getDocument());
        loader.start();
      } else {
        JOptionPane.showMessageDialog(
            getFrame(),
            "Could not open file: " + f,
            "Error opening file",
            JOptionPane.ERROR_MESSAGE);
      }
    }
Example #6
0
  /** execute method之后,取返回的inputstream */
  private static ByteArrayInputStream execute4InputStream(HttpClient client) throws Exception {
    int statusCode = client.getResponseCode();
    if (statusCode != HttpURLConnection.HTTP_OK) {
      throw new EnvException("Method failed: " + statusCode);
    }
    InputStream in = client.getResponseStream();
    if (in == null) {
      return null;
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
      Utils.copyBinaryTo(in, out);

      // 看一下传过来的byte[]是不是DesignProcessor.INVALID,如果是的话,就抛Exception
      byte[] bytes = out.toByteArray();
      // carl:格式一致传中文
      String message = new String(bytes, EncodeConstants.ENCODING_UTF_8);
      if (ComparatorUtils.equals(message, RemoteDeziConstants.NO_SUCH_RESOURCE)) {
        return null;
      } else if (ComparatorUtils.equals(message, RemoteDeziConstants.INVALID_USER)) {
        throw new EnvException(RemoteDeziConstants.INVALID_USER);
      } else if (ComparatorUtils.equals(message, RemoteDeziConstants.FILE_LOCKED)) {
        JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer_file-is-locked"));
        return null;
      } else if (message.startsWith(RemoteDeziConstants.RUNTIME_ERROR_PREFIX)) {
      }
      return new ByteArrayInputStream(bytes);
    } finally {
      in.close();
      out.close();
      client.release();
    }
  }
Example #7
0
 public int showConfirmFileOverwriteDialog(File outFile) {
   return JOptionPane.showConfirmDialog(
       this.getFrame(),
       "Replace existing file\n" + outFile.getName() + "?",
       "Overwrite Existing File?",
       JOptionPane.YES_NO_CANCEL_OPTION);
 }
    /** handle the action event */
    protected void handleToDefaultFolderAction() throws Exception {
      if (!defaultFolderSpecified()) {
        String message =
            "A default folder has not been specified.  Would you like to specify one now?\n";
        if (_subfolderName != null) {
          message +=
              "Note that you will be specifying the parent folder of " + _subfolderName + ".\n";
          message += _subfolderName + " under the selected folder will hold your files.";
        }
        final int confirm =
            JOptionPane.showConfirmDialog(
                _view, message, "Specify Default Folder", JOptionPane.YES_NO_OPTION);

        try {
          switch (confirm) {
            case JOptionPane.YES_OPTION:
              if (!showDefaultFolderSelector()) return;
              break;
            default:
              return;
          }
        } catch (Exception exception) {
          exception.printStackTrace();
        }
      }

      applyDefaultFolder(_activeFileChooser);
    }
Example #9
0
 /** close_notification */
 public synchronized void close_notification() throws RemoteException {
   JOptionPane.showMessageDialog(
       null,
       "Le serveur est injoignable pour le moment",
       "Erreur distante",
       JOptionPane.INFORMATION_MESSAGE);
   srv_state = false;
   C.initialiser();
 }
Example #10
0
 public static void main(String[] args) {
   boolean sender = false;
   File fi = null;
   try {
     if (args.length == 0) {
       int ret =
           JOptionPane.showConfirmDialog(
               null,
               "Are you the sender? (no = reciever)",
               "Send/Recieve",
               JOptionPane.YES_NO_OPTION);
       JFileChooser chooser = new JFileChooser();
       if (ret == JOptionPane.YES_OPTION) {
         chooser.showOpenDialog(null);
         sender = true;
       } else {
         chooser.showSaveDialog(null);
         sender = false;
       }
       fi = chooser.getSelectedFile();
     } else {
       if (args[0].equalsIgnoreCase("-s")) {
         sender = true;
       } else if (args[0].equalsIgnoreCase("-r")) {
         sender = false;
       }
       fi = new File(args[1]);
     }
   } catch (Exception e) {
     e.printStackTrace();
     exit();
   }
   if (sender && !fi.exists()) {
     System.err.println("Cannot send, file doesn't exist");
     exit();
   }
   try {
     if (sender) {
       ServerSocket ss = new ServerSocket(DEFAULT_PORT);
       Socket sck = ss.accept();
       byte[] hsh = SecureUtils.hash(fi);
       System.out.println(SecureUtils.hexify(hsh));
       sendFile(sck, fi, hsh);
       sck.close();
     } else {
       Socket sck = new Socket("localhost", DEFAULT_PORT);
       byte[] hsh = recvFile(sck, fi);
       System.out.println(SecureUtils.hexify(hsh));
       sck.close();
     }
   } catch (NoSuchAlgorithmException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
 private void actionAdd() {
   URL verifiedUrl = verifyUrl(addTextField.getText());
   if (verifiedUrl != null) {
     tableModel.addDownload(new DownloadFile(verifiedUrl));
     addTextField.setText("");
   } else {
     JOptionPane.showMessageDialog(
         this, "Invalid Download URL", "Error", JOptionPane.ERROR_MESSAGE);
   }
 }
Example #12
0
 public int showOptionDialog(
     Object message,
     String title,
     int optionType,
     int messageType,
     Icon icon,
     Object[] options,
     Object initialValue) {
   return JOptionPane.showOptionDialog(
       this.getFrame(), message, title, optionType, messageType, icon, options, initialValue);
 }
 // constructor
 public GameClient_(JFrame oldWindow, MultiPlayerMenuWindow multiPlayerMenu) {
   m_MultiPlayerMenu = multiPlayerMenu;
   m_OldWindow = oldWindow;
   try {
     m_IP = InetAddress.getLocalHost().getHostAddress();
     JOptionPane.showMessageDialog(oldWindow, "Server's IP: " + m_IP);
   } catch (UnknownHostException e) {
     System.err.println(e);
   }
   m_Port = 8000;
 }
Example #14
0
 void lookupByXPath(String xpath) {
   NodeList nl = DOMInfoExtractor.locateNodes(document, xpath);
   System.out.println("lookupByXPath: " + xpath);
   if (nl == null) {
     JOptionPane.showMessageDialog(this, "error xpath: " + xpath);
   }
   System.out.println("find " + nl.getLength() + " items");
   FoundItem[] fis = new FoundItem[nl.getLength()];
   for (int i = 0; i < nl.getLength(); i++) {
     fis[i] = getFoundItem(nl.item(i), null);
   }
   foundList.setListData(fis);
 }
  public void displayPage(JEditorPane pane, String text) {
    try {
      File helpFile = new File((String) locations.get(text));
      String loc = "file:" + helpFile.getAbsolutePath();
      URL page = new URL(loc);

      pane.setPage(page);

    } catch (IOException ioe) {
      JOptionPane.showMessageDialog(null, "Help Topic Unavailable");
      pane.getParent().repaint();
    }
  }
Example #16
0
  public static void finalresult(String check) {
    if (check.equals("tie")) {
      try {
        func(socket, "tie");
      } catch (IOException e) {
        System.out.println("exception has been raised");
      }
      JOptionPane.showMessageDialog(null, "It is a tie between the two");
      System.exit(0);
    } else {
      if (check.equals("winserver")) {
        try {
          func(socket, "winserver");
        } catch (IOException e) {
          System.out.println("exception has been raised");
        }
        JOptionPane.showMessageDialog(null, "The Server Has Won The Game");
        System.exit(0);
        // JOptionPane.showMessageDialog(network.this,"The server has won the
        // game","result",JOptionPane.INFORMATION_MESSAGE);
      } else {
        if (check.equals("winclient")) {
          try {
            func(socket, "winclient");
          } catch (IOException e) {
            System.out.println("exception has been raised");
          }

          JOptionPane.showMessageDialog(null, "the client has won the game");
          System.exit(0);
          // JOptionPane.showMessageDialog(network.this,"The server has won the
          // game","result",JOptionPane.INFORMATION_MESSAGE);
        }
      }
    }
  }
Example #17
0
  public void CheckAtTheEnd() // 当无子可落时判断胜负
      {
    ShowChessNumber();
    gameStart = false;

    for (int i = 0; i < 8; i++) for (int j = 0; j < 8; j++) cell[i][j].taken = true;

    String winner = "";

    if (white > black) {
      controlThread = false;
      JOptionPane.showMessageDialog(null, "白方胜!" + white + ":" + black);
      winner = "白";
    } else if (white < black) {
      controlThread = false;
      JOptionPane.showMessageDialog(null, "黑方胜!" + black + ":" + white);
      winner = "黑";
    } else if (white == black) {
      controlThread = false;
      JOptionPane.showMessageDialog(null, "和局!");
      winner = "";
    }
    //	JOptionPane.showMessageDialog(null, "游戏结束!用时" + time + "秒");
  }
 public boolean establishConnection() {
   try {
     clientSocket = new Socket(hostName, portNr);
     responseFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
     requestToServer = new PrintWriter(clientSocket.getOutputStream(), true);
     requestToServer.println("requestGameData");
     return true;
   } catch (Exception e) {
     JOptionPane.showMessageDialog(
         new JFrame(),
         "Host or port do not exist.",
         "Connection error",
         JOptionPane.ERROR_MESSAGE);
     return false;
   }
 }
Example #19
0
 /** start_notification */
 public synchronized void start_notification() throws RemoteException {
   JOptionPane.showMessageDialog(
       null,
       "Le serveur est connecté de nouveau",
       "Notification du client",
       JOptionPane.INFORMATION_MESSAGE);
   srv_state = true;
   try {
     for (int i = 0; i < J.getnbrcon(); i++) {
       if (J.list_con()[i].compareTo(C.get_nom()) != 0) {
         C.ajout(J.list_con()[i]);
       }
     }
   } catch (RemoteException ex) {
   }
 }
Example #20
0
  public void setBrowserLocation(String locale, boolean cacheLocation) {
    // push old location if one exists AND its specified behavior
    if (cacheLocation && location != null) {
      locationStack.push(location);
      toolBar.getBackButton().setEnabled(true);
    }

    location = locale;
    try {
      browserPane.setPage(location);
    } catch (IOException ioex) {
      String message = "Error loading from location:\n" + ioex.getMessage();
      JOptionPane.showMessageDialog(this, message, "Browser Error", JOptionPane.ERROR_MESSAGE);
      return;
    }
  }
Example #21
0
  public void restartApplication() {

    try {

      final String javaBin =
          System.getProperty("java.home") + File.separator + "bin" + File.separator + "javaw";
      final File currentJar =
          new File(network.class.getProtectionDomain().getCodeSource().getLocation().toURI());

      System.out.println("javaBin " + javaBin);
      System.out.println("currentJar " + currentJar);
      System.out.println("currentJar.getPath() " + currentJar.getPath());

      /* is it a jar file? */
      // if(!currentJar.getName().endsWith(".jar")){return;}

      try {

        // xmining = 0;
        // systemx.shutdown();

      } catch (Exception e) {
        e.printStackTrace();
      }

      /* Build command: java -jar application.jar */
      final ArrayList<String> command = new ArrayList<String>();
      command.add(javaBin);
      command.add("-jar");
      command.add("-Xms256m");
      command.add("-Xmx1024m");
      command.add(currentJar.getPath());

      final ProcessBuilder builder = new ProcessBuilder(command);
      builder.start();

      // try{Thread.sleep(10000);} catch (InterruptedException e){}

      // close and exit
      SystemTray.getSystemTray().remove(network.icon);
      System.exit(0);

    } // try
    catch (Exception e) {
      JOptionPane.showMessageDialog(null, e.getCause());
    }
  } // ******************************
Example #22
0
  public void run() {
    Socket socket = null;
    try {
      host = InetAddress.getLocalHost().getHostAddress();
      l.setText("Adres servera : " + host);
      serverSocket = new ServerSocket(port);
      JOptionPane.showMessageDialog(null, "Serwer dzia³a na adresie " + host);
      while (true) {
        socket = serverSocket.accept();
        if (socket != null) {
          sList.add(new ServerThread(socket, clientList, this));
        }
      }
    } catch (Exception e) {

    }
  }
Example #23
0
 protected boolean informUserError(String msg) // this is just for SPPmon
     {
   if (!ExpCoordinator.isSPPMon()) return false;
   final String opt0 = "Try Again";
   final String opt1 = "Cancel";
   JLabel lbl = new JLabel(msg);
   TextFieldwLabel tfaddress = new TextFieldwLabel(30, "daemon addr:");
   tfaddress.setText(host);
   TextFieldwLabel tfport = new TextFieldwLabel(30, "daemon port:");
   tfport.setText(String.valueOf(port));
   Object[] params = {lbl, tfaddress, tfport};
   Object[] options = {opt0, opt1};
   int rtn =
       JOptionPane.showOptionDialog(
           ExpCoordinator.getMainWindow(),
           params,
           "Connection Error",
           JOptionPane.YES_NO_OPTION,
           JOptionPane.WARNING_MESSAGE,
           null,
           options,
           options[0]);
   if (rtn == JOptionPane.NO_OPTION) {
     connectionFailed();
     return false;
   } else {
     String tmp_host = host;
     boolean change = false;
     if (tfaddress.getText().length() > 0) tmp_host = tfaddress.getText();
     int tmp_port = port;
     if (tfport.getText().length() > 0) tmp_port = Integer.parseInt(tfport.getText());
     if (!tmp_host.equals(host)) {
       host = new String(tmp_host);
       change = true;
     }
     if (port != tmp_port) {
       port = tmp_port;
       change = true;
     }
     if (change) fireEvent(new ConnectionEvent(this, ConnectionEvent.ADDRESS_CHANGED));
     state = ConnectionEvent.CONNECTION_CLOSED;
     return (connect());
   }
 }
Example #24
0
 void reloadJTree(String url) {
   System.out.println("reload " + url);
   Document dom;
   try {
     URL uurl = new URL(url);
     HTMLWrapper hw = new HTMLWrapper(url);
     dom = hw.getDOM();
   } catch (IOException e) {
     e.printStackTrace();
     try {
       dom = HTML2DOM.getDOM(new FileInputStream(url));
     } catch (IOException ie) {
       JOptionPane.showMessageDialog(this, "can't get document of the url: " + url);
       ie.printStackTrace();
       return;
     }
   }
   document = dom;
   jtree.setRootNode(dom);
 }
Example #25
0
 // If this is a new installation, ask the user for a
 // port for the server; otherwise, return the negative
 // of the configured port. If the user selects an illegal
 // port, return zero.
 private int getPort() {
   // Note: directory points to the parent of the CTP directory.
   File ctp = new File(directory, "CTP");
   if (suppressFirstPathElement) ctp = ctp.getParentFile();
   File config = new File(ctp, "config.xml");
   if (!config.exists()) {
     // No config file - must be a new installation.
     // Figure out whether this is Windows or something else.
     String os = System.getProperty("os.name").toLowerCase();
     int defPort = ((os.contains("windows") && !programName.equals("ISN")) ? 80 : 1080);
     int userPort = 0;
     while (userPort == 0) {
       String port =
           JOptionPane.showInputDialog(
               null,
               "This is a new "
                   + programName
                   + " installation.\n\n"
                   + "Select a port number for the web server.\n\n",
               Integer.toString(defPort));
       try {
         userPort = Integer.parseInt(port.trim());
       } catch (Exception ex) {
         userPort = -1;
       }
       if ((userPort < 80) || (userPort > 32767)) userPort = 0;
     }
     return userPort;
   } else {
     try {
       Document doc = getDocument(config);
       Element root = doc.getDocumentElement();
       Element server = getFirstNamedChild(root, "Server");
       String port = server.getAttribute("port");
       return -Integer.parseInt(port);
     } catch (Exception ex) {
     }
   }
   return 0;
 }
Example #26
0
  public void mouseClicked(MouseEvent e) {
    /*can = false;
    boolean f = true;
    for (int i = 0; i < 8; i++)
    {
    	for (int j = 0; j < 8; j++)
    	if (cell[i][j] == e.getSource())
    	{
    		int judege = Clicked(cell[i][j]);
    		f = false;
    		break;
    	}
    	if (!f) break;
    }*/

    boolean flage = CheckAll();
    if (flage) {
      can = false;
      if (kind.equals("" + turn)) {
        ChessBoard cel = (ChessBoard) (e.getSource());
        int judge = Clicked(cel);
        if (judge == 1) {
          try {
            System.out.println("发送前:" + cell[3][5].taken);
            out66.writeObject("落子" + turn);
            out66.flush();
            out66.writeObject(stateList.get(stateList.size() - 1));
            out66.flush();
            out66.writeObject(takenList.get(takenList.size() - 1));
            out66.flush();
          } catch (IOException e1) {
            e1.printStackTrace();
          }
        }
      } else {
        JOptionPane.showMessageDialog(null, "请确定您的身份,您此时不能落子");
      }
    } else CheckAtTheEnd();
  }
  /**
   * run will be exicuted when the thread is called, and will connect to the server and start
   * communicating with it.
   */
  public void run() {
    WaitForConnection wfc = new WaitForConnection("Waiting For Connection");
    m_OldWindow.setEnabled(false);
    try {
      m_Socket = new Socket(m_IP, m_Port);

      // System.out.println("Connecting to ChatService...");
      m_ChatSocket = new Socket(m_IP, m_Port);
      // System.out.println("\nConnected to ChatService...");

      wfc.updateMessage("Waiting For Other Players");

      // System.out.println("Getting OutputStream Stream From server...");
      toServer = new ObjectOutputStream(m_Socket.getOutputStream());
      toChatServer = new ObjectOutputStream(m_ChatSocket.getOutputStream());
      toChatServer.flush();

      // System.out.println("Getting Input Stream From server...");
      fromServer = new ObjectInputStream(m_Socket.getInputStream());
      fromChatServer = new ObjectInputStream(m_ChatSocket.getInputStream());

      m_ChatService = new ChatService();
      m_ChatServiceThread = new Thread(m_ChatService);
      m_ChatServiceThread.start();

      m_MultiPlayerMenu.startGame();
      wfc.dispose();
      m_OldWindow.dispose();
    } catch (java.net.ConnectException e) {
      wfc.dispose();
      MenuWindow menu = new MenuWindow(new JFrame(""));
      JOptionPane.showMessageDialog(menu.getMainFrame(), "Error Connection refused");
      m_OldWindow.setEnabled(true);
    } catch (IOException ex) {
      System.err.print(ex);
    }
  }
Example #28
0
  public void RegretChess() {
    for (int i = 0; i < 8; i++)
      for (int j = 0; j < 8; j++)
        if (cell[i][j].changed == true) {
          cell[i][j].ChangeBack();
        }
    turn = TakeTurn();
    try {
      stateList.remove(stateList.size() - 1);
      takenList.remove(takenList.size() - 1);

      char[][] states = stateList.get(stateList.size() - 1);
      boolean[][] takens = takenList.get(takenList.size() - 1);
      for (int i = 0; i < 8; i++)
        for (int j = 0; j < 8; j++) {
          cell[i][j].state = states[i][j];
          cell[i][j].taken = takens[i][j];
          cell[i][j].repaint();
        }

      for (int i = 0; i < 8; i++)
        for (int j = 0; j < 8; j++)
          if (cell[i][j].taken == false) {
            CheckPlace(cell[i][j]);
            if (canPut) {
              cell[i][j].ChangeBackground();
              canPut = false;
            }
          }

    } catch (ArrayIndexOutOfBoundsException e1) {
      JOptionPane.showMessageDialog(null, "无法悔棋");
    }
    if (stateList.size() == 0) {
      RememberState();
    }
  }
Example #29
0
  // implemented for HyperlinkListener
  public void hyperlinkUpdate(HyperlinkEvent e) {
    if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
      JEditorPane ep = (JEditorPane) (e.getSource());

      // handle frame events properly
      if (e instanceof HTMLFrameHyperlinkEvent) {
        HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) e;
        HTMLDocument doc = (HTMLDocument) (ep.getDocument());
        doc.processHTMLFrameHyperlinkEvent(evt);
      } else // handle normal links
      {
        try {
          URL currentLoc = new URL(location);
          URL newLoc = new URL(currentLoc, e.getDescription());

          setBrowserLocation(newLoc.toString());
        } catch (MalformedURLException malUrl) {
          JOptionPane.showMessageDialog(
              this, "Malformed URL", "Browser Error", JOptionPane.ERROR_MESSAGE);
          return;
        }
      }
    }
  }
Example #30
0
  public static void main(String[] args) throws IOException {
    ServerSocket s = new ServerSocket(PORT);
    System.out.println("Started: " + s);
    frame.setPreferredSize(new Dimension(400, 400));
    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });
    JMenuBar one = new JMenuBar();
    JMenu second = new JMenu("OPTIONS");
    //	JMenuItem third = new JMenuItem("NEW GAME");
    JMenuItem fourth = new JMenuItem("EXIT");
    fourth.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            try {
              exit(evt);
            } catch (IOException e) {
            }
          }
        });
    // second.add(third);
    second.add(fourth);
    one.add(second);
    frame.setJMenuBar(one);
    frame.setLayout(new java.awt.GridLayout(3, 3));
    button = new JButton[10];
    for (int i = 1; i < 10; i++) {
      button[i] = new JButton();
      button[i].setBackground(Color.lightGray);
      button[i].setActionCommand(Integer.toString(i));
      button[i].addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
              print(evt.getActionCommand());
              try {
                func(socket, evt.getActionCommand());
                String check = win();
                finalresult(check);
                if (check != "") {
                  func(socket, check);
                } else {
                  func(socket, evt.getActionCommand());
                }
                ;
              } catch (IOException e) {
              }
            }
          });
      frame.add(button[i]);
    }

    try {
      socket = s.accept();
      frame.pack();
      frame.setVisible(true);
      try {
        System.out.println("Connection accepted: " + socket);
        BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        /*  while(true)
        {
        String str=in.readLine();
        print2(str);
        }*/
        while (true) {
          String str = in.readLine();
          if (str.equals("exit")) {
            System.exit(0);
          }
          if (str.equals("tie")) {
            JOptionPane.showMessageDialog(null, "It is a tie between the two");
            System.exit(0);
          } else {

            if (str.equals("winserver")) {
              System.out.println("server has won");
              JOptionPane.showMessageDialog(null, "the server has won the game");
              System.exit(0);
            } else {
              if (str.equals("winclient")) {
                JOptionPane.showMessageDialog(null, "the client has won the game");
                System.exit(0);
              } else {
                System.out.println(str);
                print2(str);
              }
            }
          }
        }
      } catch (Exception e) {
      } // finally {socket.close();
      // }
    } catch (Exception e) {
    } // finally {s.close();
    // }
  }