/** Connect to to a game and then launch the chat lounge. */ void connect() { ConnectDialog cd; cd = new ConnectDialog(frame); cd.setVisible(true); // verify dialog data if ((cd.playerName == null) || (cd.serverAddr == null) || (cd.port == 0)) { return; } // Players should have to enter a non-blank, non-whitespace name. boolean foundValid = false; char[] nameChars = cd.playerName.toCharArray(); for (int loop = 0; !foundValid && (loop < nameChars.length); loop++) { if (!Character.isWhitespace(nameChars[loop])) { foundValid = true; } } if (!foundValid) { JOptionPane.showMessageDialog( frame, Messages.getString("MegaMek.ConnectAlert.message"), Messages.getString("MegaMek.ConnectAlert.title"), JOptionPane.ERROR_MESSAGE); // $NON-NLS-1$ //$NON-NLS-2$ return; } // initialize game client = new Client(cd.playerName, cd.serverAddr, cd.port); ClientGUI gui = new ClientGUI(client, controller); controller.clientgui = gui; frame.setCursor(new Cursor(Cursor.WAIT_CURSOR)); gui.initialize(); frame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); if (!client.connect()) { StringBuffer error = new StringBuffer(); error .append("Error: could not connect to server at ") .append(cd.serverAddr) .append(':') .append(cd.port) .append('.'); JOptionPane.showMessageDialog( frame, error.toString(), Messages.getString("MegaMek.ConnectAlert.title"), JOptionPane.ERROR_MESSAGE); // $NON-NLS-1$ frame.setVisible(false); client.die(); } launch(gui.getFrame()); }
/** * Switches the display cursor to or from the wait cursor. * * @param flag {@code true} to enable the wait cursor; {@code false} to enable the previous cursor * @see #isWaitCursorVisible() * @see Cursor#WAIT_CURSOR */ public void setWaitCursorVisible(boolean flag) { boolean old = isWaitCursorVisible(); if (flag != old) { waitCursorVisible = flag; if (isWaitCursorVisible()) { realCursor = getCursor(); super.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); } else { super.setCursor(realCursor); } firePropertyChange("waitCursorVisible", old, isWaitCursorVisible()); } }
/** * Konstruktøren. Initierer rammen og canvaset som det skal tegnes i. * * @param gameName : String - Tittel på JFrame */ public DisplayManager(String gameName) { frame = new JFrame(gameName); frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); frame.setIgnoreRepaint(true); frame.setSize(WIDTH, HEIGHT); frame.setResizable(false); frame.setLocationRelativeTo(null); frame.setVisible(true); frame.setCursor(getInvisibleCursor()); frame.setIconImage(new ImageIcon("images/ico.ico").getImage()); // Oppretter en buffer for å hindre "tearing" i grafikken. try { EventQueue.invokeAndWait( new Runnable() { @Override public void run() { frame.createBufferStrategy(2); } }); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } }
/** {@inheritDoc} */ @Override public void setCursor(Cursor c) { if (!isWaitCursorVisible()) { super.setCursor(c); } else { this.realCursor = c; } }
public static void setCursor(int id) { Toolkit toolkit = Toolkit.getDefaultToolkit(); String location = signlink.findcachedir() + "/Sprites/"; Cursor cursor = toolkit.createCustomCursor( toolkit.getImage(location + "CURSOR " + id + ".PNG"), new Point(0, 0), location + "CURSOR " + id + ".PNG"); frame.setCursor(cursor); }
@SuppressWarnings("deprecation") Runtime(JFrame app, KeyboardInput keyboard, MouseInput mouse) { window = app; window.setCursor(Cursor.CROSSHAIR_CURSOR); this.mouse = mouse; this.keyboard = keyboard; height = window.getHeight() - 20; width = window.getWidth(); }
public static void setCursor(client client, int id) { Toolkit toolkit = Toolkit.getDefaultToolkit(); Cursor cursor = toolkit.createCustomCursor( toolkit.getImage("C:/.hack3rClient/Sprites/Cursors/Cursor " + id + ".PNG"), new Point(0, 0), "C:/.hack3rClient/Sprites/Cursors/Cursor " + id + ".PNG"); // Cursor cursor = toolkit.createCustomCursor(toolkit.getImage("Cursors/Cursor "+id+".PNG"), new // Point(0,0), ".Cursor/Cursor "+id+".PNG"); frame.setCursor(cursor); // client.gameFrame.setCursor(cursor); }
@Override public void unregisterFileReceiver() { ClientMain.lock.lock(); try { this.fileReceiver = null; } finally { ClientMain.lock.unlock(); } receive.setEnabled(true); input.setEnabled(true); output.setEnabled(true); clientFrame.setCursor(null); }
public static void main(String[] args) throws ClassNotFoundException, InstantiationException { try { setPrimeiraConfig(); // UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel"); // UIManager.setLookAndFeel("com.jtattoo.plaf.mcwin.McWinLookAndFeel"); String[] mensagens = {". Carregando...", ". Mais Alguns Instantes..."}; JFrame janela = new JFrame("Carregando"); janela.setIconImage(ConfigController.defineIcon()); janela.setUndecorated(true); janela.setSize(400, 400); janela.setLocationRelativeTo(null); janela.setBackground(new Color(0, 0, 0, 2)); // Fundo da Frame deixa transparente janela.setContentPane(new MyPainelInvisible()); // Defino a imagem como opaque e visivel janela.setLayout(new BorderLayout()); JLabel lb = new JLabel("Carregando"); lb.setFont(ConfigController.definePrincipalFont(30f, Font.BOLD)); lb.setForeground(Color.black); janela.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); janela.getContentPane().add(lb); janela.setAlwaysOnTop(true); janela.setVisible(true); Thread t = new Thread( new Runnable() { @Override public void run() { // ConnectionFactoryConfig.openManger().openSession(); try { ConnectionFactoryRepository.getManager(); } catch (SQLException e) { e.printStackTrace(); JOptionPane.showMessageDialog( null, "Houve um falha ao conectar com o banco! Descri������o do erro " + "\n''" + e.getMessage() + "''"); System.exit(0); } isLoading = false; } /* * http://stackoverflow.com/questions/11703794/how-to-set-jframe-background-transparent-but-jpanel-or-jlabel-background-opaque */ }); t.start(); int cont = 0; while (Start.isLoading) { try { lb.setText(mensagens[(cont % 2)]); Thread.sleep(1 * 1000); cont++; Thread.sleep(1000); } catch (InterruptedException ex) { Logger.getLogger(Start.class.getName()).log(Level.SEVERE, null, ex); } } janela.dispose(); launch(args); // } catch (IllegalAccessException | UnsupportedLookAndFeelException e) { // e.printStackTrace(); } catch (GenericJDBCException e) { JOptionPane.showMessageDialog(null, "Falha ao conectar no banco"); throw new ExceptionInInitializerError(e); } }
public CustomCursor() { JFrame frame = new JFrame(); int[][] cursorImageArray = new int[][] { {1, 0, 0, 0, 0, 0, 0, 0, 0}, {1, 1, 0, 0, 0, 0, 0, 0, 0}, {1, 1, 1, 0, 0, 0, 0, 0, 0}, {1, 1, 1, 1, 0, 0, 0, 0, 0}, {1, 1, 1, 1, 1, 0, 0, 0, 0}, {1, 1, 1, 1, 1, 1, 0, 0, 0}, {1, 1, 1, 1, 1, 1, 1, 0, 0}, {1, 1, 1, 1, 1, 1, 1, 1, 0}, {1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 0, 1, 1, 0, 0, 0}, {1, 1, 0, 0, 1, 1, 0, 0, 0}, {1, 0, 0, 0, 0, 1, 1, 0, 0}, {0, 0, 0, 0, 0, 1, 1, 0, 0}, {0, 0, 0, 0, 0, 0, 1, 1, 0}, {0, 0, 0, 0, 0, 0, 1, 1, 0}, {0, 0, 0, 0, 0, 0, 0, 1, 1}, {0, 0, 0, 0, 0, 0, 0, 1, 1} }; // BufferedImage cursorImageSmall = new BufferedImage(cursorImageArray[0].length, // cursorImageArray.length, BufferedImage.TYPE_INT_ARGB); System.out.println("" + cursorImageArray[0].length + ", " + cursorImageArray.length); System.out.println( "" + Toolkit.getDefaultToolkit() .getBestCursorSize(cursorImageArray[0].length, cursorImageArray.length)); Dimension bestCursorSize = Toolkit.getDefaultToolkit() .getBestCursorSize(cursorImageArray[0].length, cursorImageArray.length); BufferedImage cursorImage = new BufferedImage(bestCursorSize.width, bestCursorSize.height, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics2D = (Graphics2D) cursorImage.getGraphics(); Color transparentColor = new Color(198, 198, 198, 0); Color opaqueColor = new Color(255, 0, 0, 255); for (int y = 0; y < cursorImageArray.length; y++) { for (int x = 0; x < cursorImageArray[0].length; x++) { if (cursorImageArray[y][x] == 0) { System.out.println("found transparent pixel!"); // Do nothing, because the background is already transparent // You could do this, if you wanted to make a pixel transparent: // graphics2D.setComposite(AlphaComposite.Src); // graphics2D.setColor(transparentColor); // graphics2D.drawRect(x, y, 1, 1); } else { System.out.println("found opaque pixel!"); graphics2D.setColor(opaqueColor); graphics2D.drawRect(x, y, 1, 1); } } } frame.setCursor( Toolkit.getDefaultToolkit().createCustomCursor(cursorImage, new Point(0, 0), "MyCursor")); JPanel panel = new MyPanel(); frame.setContentPane(panel); frame.setSize(400, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
public void setCursor(Cursor cursor) { frame.setCursor(cursor); }
/** * mouse moved off the label * * @param evt the mouse event */ @Override public void mouseExited(final MouseEvent evt) { parent.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); }
/** * mouse moved over the label * * @param evt the mouse event */ @Override public void mouseEntered(final MouseEvent evt) { parent.setCursor(new Cursor(Cursor.HAND_CURSOR)); }
public void actionPerformed(ActionEvent e) { Object src = e.getSource(); if (src == binfo) { JOptionPane.showMessageDialog( frame, "Programme crée par Sarathai\n" + "Licence creative commons\n" + "\n" + "Pour envoyer des fichiers sur le serveur, cliquer d'abord sur le bouton ajouter,\n" + "puis sélectionnez le dossier ou fichier à ajouter. Répétez cette opération autant de foi que nécessaire.\n" + "Puis cliquez sur le bouton envoyer en ayant d'abord rempli les champs de l'adresse ip et du port.\n" + "\n" + "Pour recevoir des fichiers sauvegardés sur le serveur, cliquez sur le bouton recevoir,\n" + "puis sélectionnez le ou les fichier(s) voulu(s) dans la liste de gauche, et enfin recliquez\n" + "sur le bouton recevoir pour importer les fichiers.\n" + "\n" + "Pour toutes les infos, bien lire le texte qui s'affiche dans le champ de texte en bas.", "Informations", JOptionPane.INFORMATION_MESSAGE); } else if (src == ajouter) { JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(chooser.getAcceptAllFileFilter()); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); int i = chooser.showOpenDialog(Fenetre.frame); if (i == JFileChooser.APPROVE_OPTION) { frame.setCursor(waitCursor); File file = chooser.getSelectedFile(); if (file.isDirectory()) { name = file.getAbsolutePath().toString() + sep; selection.addElement(name); new WhatIDo("Ajouté à la séléction", name); } else { name = file.getAbsolutePath().toString(); selection.addElement(name); new WhatIDo("Ajouté à la séléction", name); } liste.updateUI(); enlever.setEnabled(true); frame.setCursor(Cursor.getDefaultCursor()); } } else if (src == enlever) { try { int j = liste.getSelectedIndex(); new WhatIDo("Supprimé de la séléction", selection.elementAt(j).toString()); selection.removeElementAt(j); } catch (ArrayIndexOutOfBoundsException e1) { new WhatIDo("Supprimé de la séléction", selection.elementAt(0).toString()); selection.removeElementAt(0); } if (selection.size() == 0) { selection.clear(); liste.clearSelection(); enlever.setEnabled(false); } liste.updateUI(); } else if (src == bquitter) { System.exit(0); } else if (src == bnouveau) { selection.clear(); liste.clearSelection(); liste.updateUI(); new WhatIDo("Nouvelle sauvegarde"); } else if (src == benvoyer) { if (!selection.isEmpty()) { new Envoyer(selection); } else { new WhatIDo("Veuillez ajouter des fichiers ou dossiers"); } } else if (src == brecevoir) { if (!liste.isSelectionEmpty()) { Vector<String> vec = new Vector<String>(); for (int i : liste.getSelectedIndices()) { vec.addElement(selection.elementAt(i)); } new Recevoir(vec); } else { new Recevoir(); } } }
void loadGame() { JFileChooser fc = new JFileChooser("savegames"); fc.setLocation(frame.getLocation().x + 150, frame.getLocation().y + 100); fc.setDialogTitle(Messages.getString("MegaMek.SaveGameDialog.title")); fc.setFileFilter( new FileFilter() { @Override public boolean accept(File dir) { return ((dir.getName() != null) && (dir.getName().endsWith(".sav") || dir.getName().endsWith(".sav.gz") || dir.isDirectory())); // $NON-NLS-1$ } @Override public String getDescription() { return "Savegames"; } }); int returnVal = fc.showOpenDialog(frame); if ((returnVal != JFileChooser.APPROVE_OPTION) || (fc.getSelectedFile() == null)) { // I want a file, y'know! return; } HostDialog hd = new HostDialog(frame); hd.setVisible(true); if ((hd.playerName == null) || (hd.serverPass == null) || (hd.port == 0)) { return; } // Players should have to enter a non-blank, non-whitespace name. boolean foundValid = false; char[] nameChars = hd.playerName.toCharArray(); for (int loop = 0; !foundValid && (loop < nameChars.length); loop++) { if (!Character.isWhitespace(nameChars[loop])) { foundValid = true; } } if (!foundValid) { JOptionPane.showMessageDialog( frame, Messages.getString("MegaMek.PlayerNameAlert1.message"), Messages.getString("MegaMek.PlayerNameAlert1.title"), JOptionPane.ERROR_MESSAGE); // $NON-NLS-1$ //$NON-NLS-2$ return; } // kick off a RNG check d6(); // start server try { server = new Server(hd.serverPass, hd.port, hd.register, hd.register ? hd.metaserver : ""); } catch (IOException ex) { System.err.println("could not create server socket on port " + hd.port); StringBuffer error = new StringBuffer(); error .append("Error: could not start server at localhost") .append(":") .append(hd.port) .append(" (") .append(ex.getMessage()) .append(")."); JOptionPane.showMessageDialog( frame, error.toString(), Messages.getString("MegaMek.HostGameAlert.title"), JOptionPane.ERROR_MESSAGE); // $NON-NLS-1$ return; } if (!server.loadGame(fc.getSelectedFile())) { JOptionPane.showMessageDialog( frame, Messages.getString("MegaMek.LoadGameAlert.message"), Messages.getString("MegaMek.LoadGameAlert.title"), JOptionPane.ERROR_MESSAGE); // $NON-NLS-1$ //$NON-NLS-2$ server.die(); server = null; return; } client = new Client(hd.playerName, "localhost", hd.port); // $NON-NLS-1$ ClientGUI gui = new ClientGUI(client, controller); controller.clientgui = gui; frame.setCursor(new Cursor(Cursor.WAIT_CURSOR)); gui.initialize(); frame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); if (!client.connect()) { StringBuffer error = new StringBuffer(); error .append("Error: could not connect to server at localhost") .append(":") .append(hd.port) .append("."); JOptionPane.showMessageDialog( frame, error.toString(), Messages.getString("MegaMek.HostGameAlert.title"), JOptionPane.ERROR_MESSAGE); // $NON-NLS-1$ frame.setVisible(false); client.die(); } optdlg = null; // free some memory thats only needed in lounge // This normally happens in the deployment phase in Client, but // if we are loading a game, this phase may not be reached MechFileParser.dispose(); RandomNameGenerator.getInstance().dispose(); // We must do this last, as the name and unit generators can create // a new instance if they are running MechSummaryCache.dispose(); launch(gui.getFrame()); }
/** Start instances of both the client and the server. */ void host() { HostDialog hd; hd = new HostDialog(frame); hd.setVisible(true); // verify dialog data if ((hd.playerName == null) || (hd.serverPass == null) || (hd.port == 0)) { return; } // Players should have to enter a non-blank, non-whitespace name. boolean foundValid = false; char[] nameChars = hd.playerName.toCharArray(); for (int loop = 0; !foundValid && (loop < nameChars.length); loop++) { if (!Character.isWhitespace(nameChars[loop])) { foundValid = true; } } if (!foundValid) { JOptionPane.showMessageDialog( frame, Messages.getString("MegaMek.PlayerNameAlert.message"), Messages.getString("MegaMek.PlayerNameAlert.title"), JOptionPane.ERROR_MESSAGE); // $NON-NLS-1$ //$NON-NLS-2$ return; } // kick off a RNG check d6(); // start server try { server = new Server(hd.serverPass, hd.port, hd.register, hd.register ? hd.metaserver : ""); } catch (IOException ex) { System.err.println("could not create server socket on port " + hd.port); StringBuffer error = new StringBuffer(); error .append("Error: could not start server at localhost") .append(":") .append(hd.port) .append(" (") .append(ex.getMessage()) .append(")."); JOptionPane.showMessageDialog( frame, error.toString(), Messages.getString("MegaMek.HostGameAlert.title"), JOptionPane.ERROR_MESSAGE); // $NON-NLS-1$ return; } // initialize client client = new Client(hd.playerName, "localhost", hd.port); // $NON-NLS-1$ ClientGUI gui = new ClientGUI(client, controller); controller.clientgui = gui; frame.setCursor(new Cursor(Cursor.WAIT_CURSOR)); gui.initialize(); frame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); if (!client.connect()) { StringBuffer error = new StringBuffer(); error .append("Error: could not connect to server at localhost") .append(":") .append(hd.port) .append("."); JOptionPane.showMessageDialog( frame, error.toString(), Messages.getString("MegaMek.HostGameAlert.title"), JOptionPane.ERROR_MESSAGE); // $NON-NLS-1$ frame.setVisible(false); client.die(); } launch(gui.getFrame()); optdlg = null; }