/** Constructor for allocating memory and simple initializing. */ public GameBoard() { dealerPanel = new JPanel(); playerPanel = new JPanel(); controlPanel = new JPanel(); money = new JLabel(); record = new JLabel(); inputImage = new JLabel(new ImageIcon("res/INPUT.gif")); moneyLabel = new JLabel(new ImageIcon("res/MONEY.gif")); betLabel = new JLabel(new ImageIcon("res/MAKE_YOUR_BET.gif")); recordLabel = new JLabel(new ImageIcon("res/BEST_SCORE.gif")); betButton = new JButton(new ImageIcon("res/BET.gif")); resultButton = new JButton(new ImageIcon("res/RESULT.gif")); betInput = new JTextField(); try { recordReader = new BufferedReader(new FileReader("res/record")); bestScore = Integer.parseInt(recordReader.readLine()); recordReader.close(); } catch (Exception e) { e.printStackTrace(); } inputImage.setLayout(new BorderLayout()); controlPanel.setLayout(new FlowLayout()); betInput.setHorizontalAlignment(JTextField.CENTER); betButton.setBorder(BorderFactory.createEmptyBorder()); betButton.setContentAreaFilled(false); resultButton.setBorder(BorderFactory.createEmptyBorder()); resultButton.setContentAreaFilled(false); resultButton.setEnabled(false); betButton.addMouseListener(new BetListener()); resultButton.addMouseListener(new ResultListener()); betInput.setOpaque(false); betInput.setBorder(BorderFactory.createEmptyBorder()); money.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 30)); record.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 30)); setOpaque(false); initGame(); initRound(); }
// Panel below board (Contains Label Indicating Player 1's turn private JPanel southWindowPanel() { JPanel lab1Panel = new JPanel(); lab1Panel.setLayout(new BorderLayout()); lab1Panel.setPreferredSize(new Dimension(300, 150)); lab1Panel.setOpaque(false); statusLabel1 = new JLabel("Player 1's Turn", JLabel.CENTER); statusLabel1.setForeground(new Color(203, 159, 0)); statusLabel1.setFont(new Font("Belta Regular", Font.ITALIC, 45)); lab1Panel.add(statusLabel1, BorderLayout.CENTER); JPanel eastContainer = new JPanel(); eastContainer.setLayout(new BorderLayout()); eastContainer.setOpaque(false); eastContainer.setPreferredSize(new Dimension(200, 300)); JPanel btnPanel = new JPanel(); btnPanel.setOpaque(false); btnPanel.setPreferredSize(new Dimension(300, 60)); eastContainer.add(btnPanel, BorderLayout.SOUTH); // Add help button to panel instructBtn.setPreferredSize(new Dimension(50, 40)); instructBtn.setBorder(BorderFactory.createLineBorder(Color.black, 5)); instructBtn.addActionListener(new ButtonListener()); btnPanel.add(instructBtn); // Add restart button to panel restartBtn.setPreferredSize(new Dimension(100, 40)); restartBtn.setBorder(BorderFactory.createLineBorder(Color.black, 5)); restartBtn.addActionListener(new ButtonListener()); // Add Action Listener (Reset Game) btnPanel.add(restartBtn); JPanel westContainer = new JPanel(); westContainer.setPreferredSize(new Dimension(200, 300)); westContainer.setOpaque(false); lab1Panel.add(westContainer, BorderLayout.WEST); lab1Panel.add(eastContainer, BorderLayout.EAST); return lab1Panel; }
/** This method is called from within the constructor to initialize the form. */ public void initComponents() { /** *************** The main frame ************************************** */ // width, height this.setSize(560, 370); Container container = this.getContentPane(); container.setLayout(new BoxLayout(getContentPane(), 1)); container.setBackground(containerBackGroundColor); this.setLocation(0, 0); this.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { new AlertInstantMessaging( "Your changes will not be checked: use the Submit button!!!", JOptionPane.WARNING_MESSAGE); hideFrame(); } }); /** **************** The components ********************************* */ firstPanel = new JPanel(); firstPanel.setBorder(BorderFactory.createEmptyBorder(15, 4, 15, 4)); // If put to False: we see the container's background firstPanel.setOpaque(false); // rows, columns, horizontalGap, verticalGap firstPanel.setLayout(new GridLayout(11, 2, 2, 2)); container.add(firstPanel); outboundProxyAddressLabel = new JLabel("Outbound proxy IP address:"); outboundProxyAddressLabel.setForeground(Color.black); outboundProxyAddressTextField = new JTextField(20); outboundProxyAddressLabel.setBorder(labelBorder); outboundProxyAddressLabel.setOpaque(true); outboundProxyAddressLabel.setBackground(labelBackGroundColor); firstPanel.add(outboundProxyAddressLabel); firstPanel.add(outboundProxyAddressTextField); outboundProxyPortLabel = new JLabel("Outbound proxy port:"); outboundProxyPortLabel.setForeground(Color.black); outboundProxyPortTextField = new JTextField(20); outboundProxyPortLabel.setBorder(labelBorder); outboundProxyPortLabel.setOpaque(true); outboundProxyPortLabel.setBackground(labelBackGroundColor); firstPanel.add(outboundProxyPortLabel); firstPanel.add(outboundProxyPortTextField); registrarAddressLabel = new JLabel("Registrar IP address:"); registrarAddressLabel.setForeground(Color.black); registrarAddressTextField = new JTextField(20); registrarAddressLabel.setBorder(labelBorder); registrarAddressLabel.setOpaque(true); registrarAddressLabel.setBackground(labelBackGroundColor); firstPanel.add(registrarAddressLabel); firstPanel.add(registrarAddressTextField); registrarPortLabel = new JLabel("Registrar port:"); registrarPortLabel.setForeground(Color.black); registrarPortTextField = new JTextField(20); registrarPortLabel.setBorder(labelBorder); registrarPortLabel.setOpaque(true); registrarPortLabel.setBackground(labelBackGroundColor); firstPanel.add(registrarPortLabel); firstPanel.add(registrarPortTextField); imAddressLabel = new JLabel("Contact IP address:"); imAddressLabel.setForeground(Color.black); imAddressTextField = new JTextField(20); imAddressLabel.setBorder(labelBorder); imAddressLabel.setOpaque(true); imAddressLabel.setBackground(labelBackGroundColor); firstPanel.add(imAddressLabel); firstPanel.add(imAddressTextField); imPortLabel = new JLabel("Contact port:"); imPortLabel.setForeground(Color.black); imPortTextField = new JTextField(20); imPortLabel.setBorder(labelBorder); imPortLabel.setOpaque(true); imPortLabel.setBackground(labelBackGroundColor); firstPanel.add(imPortLabel); firstPanel.add(imPortTextField); imProtocolLabel = new JLabel("Contact transport:"); imProtocolLabel.setForeground(Color.black); imProtocolTextField = new JTextField(20); imProtocolLabel.setBorder(labelBorder); imProtocolLabel.setOpaque(true); imProtocolLabel.setBackground(labelBackGroundColor); firstPanel.add(imProtocolLabel); firstPanel.add(imProtocolTextField); outputFileLabel = new JLabel("Output file:"); outputFileLabel.setForeground(Color.black); outputFileTextField = new JTextField(20); outputFileLabel.setBorder(labelBorder); outputFileLabel.setOpaque(true); outputFileLabel.setBackground(labelBackGroundColor); firstPanel.add(outputFileLabel); firstPanel.add(outputFileTextField); buddiesFileLabel = new JLabel("Buddies file:"); buddiesFileLabel.setForeground(Color.black); buddiesFileTextField = new JTextField(20); buddiesFileLabel.setBorder(labelBorder); buddiesFileLabel.setOpaque(true); buddiesFileLabel.setBackground(labelBackGroundColor); firstPanel.add(buddiesFileLabel); firstPanel.add(buddiesFileTextField); authenticationFileLabel = new JLabel("Authentication file:"); authenticationFileLabel.setForeground(Color.black); authenticationFileTextField = new JTextField(20); authenticationFileLabel.setBorder(labelBorder); authenticationFileLabel.setOpaque(true); authenticationFileLabel.setBackground(labelBackGroundColor); firstPanel.add(authenticationFileLabel); firstPanel.add(authenticationFileTextField); defaultRouterLabel = new JLabel("Default router class name:"); defaultRouterLabel.setForeground(Color.black); defaultRouterTextField = new JTextField(20); defaultRouterLabel.setBorder(labelBorder); defaultRouterLabel.setOpaque(true); defaultRouterLabel.setBackground(labelBackGroundColor); firstPanel.add(defaultRouterLabel); firstPanel.add(defaultRouterTextField); thirdPanel = new JPanel(); thirdPanel.setOpaque(false); // top, left, bottom, right thirdPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); submitButton = new JButton(" Submit "); submitButton.setToolTipText("Submit your changes!"); submitButton.setFocusPainted(false); submitButton.setFont(new Font("Dialog", 1, 16)); submitButton.setBackground(buttonBackGroundColor); submitButton.setBorder(buttonBorder); submitButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent evt) { submitButtonActionPerformed(evt); } }); thirdPanel.add(submitButton); container.add(thirdPanel); }
public MancalaPanel(LetsPlayMancala game) { // ------------------------------------------------------------------------------ // Import font "Belta Regular" // ----------------------------------------------------------------------------- try { InputStream in = MancalaPanel.class.getResourceAsStream("belta-regular.ttf"); Font font = Font.createFont(Font.TRUETYPE_FONT, in); } catch (Exception ex) { System.out.println("Font couldn't be loaded."); } // ---------------------------------------------------------------------------- // Set background image // ---------------------------------------------------------------------------- imageFile = "/Images/GameBackground.png"; this.game = game; SMALL_PIT_COUNT = 12; setLayout(new BorderLayout()); add(northWindowPanel(), BorderLayout.NORTH); add(westWindowPanel(), BorderLayout.WEST); add(makeBoardPanel(), BorderLayout.CENTER); add(eastWindowPanel(), BorderLayout.EAST); add(southWindowPanel(), BorderLayout.SOUTH); winners = new LinkedStack<String>(); winnersLabel = new JLabel(); resultFrame = new JFrame(); boardResultPanel = new BkImagePanel("/Images/board2.png"); resultNorth = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 50)); resultNorth.setOpaque(false); resultCenter = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0)); resultCenter.setOpaque(false); resultSouth = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 20)); resultSouth.setOpaque(false); playAgainBtn.setPreferredSize(new Dimension(240, 80)); playAgainBtn.setBackground(new Color(135, 17, 76)); playAgainBtn.setForeground(Color.white); playAgainBtn.setBorder(BorderFactory.createLineBorder(Color.white, 6)); playAgainBtn.setFont(new Font("Belta Regular", Font.BOLD, 40)); playAgainBtn.addActionListener(new ButtonListener()); scoresBtn.setPreferredSize(new Dimension(340, 80)); scoresBtn.setBorder(BorderFactory.createLineBorder(Color.white, 6)); scoresBtn.addActionListener(new ButtonListener()); quitBtn.setPreferredSize(new Dimension(150, 80)); quitBtn.setBorder(BorderFactory.createLineBorder(Color.white, 6)); quitBtn.addActionListener(new ButtonListener()); result = new JLabel(); result.setFont(new Font("Belta Regular", Font.BOLD, 40)); result.setForeground(Color.white); result.setBackground(new Color(0, 158, 121)); result.setBorder(BorderFactory.createLineBorder(Color.white, 6)); result.setOpaque(true); result.setPreferredSize(new Dimension(380, 80)); winnersLabel = new JLabel(); winnersLabel.setFont(new Font("Belta Regular", Font.BOLD, 40)); winnersLabel.setForeground(Color.white); winnersLabel.setPreferredSize(new Dimension(420, 200)); boardResultPanel.setLayout(new BorderLayout(50, 50)); boardResultPanel.setPreferredSize(new Dimension(800, 700)); boardResultPanel.setBackground(Color.yellow); boardResultPanel.add(resultNorth, BorderLayout.NORTH); boardResultPanel.add(resultCenter, BorderLayout.CENTER); boardResultPanel.add(resultSouth, BorderLayout.SOUTH); resultCenter.add(winnersLabel); resultSouth.add(scoresBtn); resultSouth.add(playAgainBtn); resultSouth.add(quitBtn); resultFrame.add(boardResultPanel); }
public void init() { areaventana = new JPanel(); areabotones = new JPanel(); imagen = new JLabel(""); presentacion = new JButton(imgPlay); siguiente = new JButton(imgSiguiente); atras = new JButton(imgAnterior); ptiempo = new JSlider(); carpeta = new JButton(imgNuevaCarpeta); grid = new JButton(imgGrid); bcomentario = new JButton(imgComentario); zoom = new JButton(imgZoom); /* Agregando los componentes */ areaventana.add(imagen); // areaventana.add(desplazamiento); areabotones.add(grid); areabotones.add(atras); areabotones.add(presentacion); areabotones.add(siguiente); areabotones.add(ptiempo); areabotones.add(carpeta); areabotones.add(bcomentario); areabotones.add(zoom); areabotones.setBackground(colorGris); areaventana.setBackground(colorGris); // desplazamiento.setVisible(false); // areaventana.add(desplazamiento); /* GUI GUI GUI GUI */ presentacion.setBackground(colorGris); atras.setBackground(colorGris); siguiente.setBackground(colorGris); carpeta.setBackground(colorGris); grid.setBackground(colorGris); ptiempo.setBackground(colorGris); bcomentario.setBackground(colorGris); zoom.setBackground(colorGris); presentacion.setPreferredSize(new Dimension(100, 80)); atras.setPreferredSize(new Dimension(100, 80)); siguiente.setPreferredSize(new Dimension(100, 80)); carpeta.setPreferredSize(new Dimension(100, 80)); grid.setPreferredSize(new Dimension(100, 80)); bcomentario.setPreferredSize(new Dimension(100, 80)); zoom.setPreferredSize(new Dimension(100, 80)); grid.setFocusPainted(false); atras.setFocusPainted(false); siguiente.setFocusPainted(false); carpeta.setFocusPainted(false); presentacion.setFocusPainted(false); bcomentario.setFocusPainted(false); zoom.setFocusPainted(false); grid.setBorder(null); atras.setBorder(null); siguiente.setBorder(null); carpeta.setBorder(null); presentacion.setBorder(null); areabotones.setBorder(null); areaventana.setBorder(null); bcomentario.setBorder(null); zoom.setBorder(null); /* GUI GUI GUI GUI */ /* Action Listeners */ siguiente.addActionListener(this); atras.addActionListener(this); presentacion.addActionListener(this); carpeta.addActionListener(this); grid.addActionListener(this); bcomentario.addActionListener(this); zoom.addActionListener(this); this.setLayout(new BorderLayout()); add(areaventana, BorderLayout.CENTER); add(areabotones, BorderLayout.SOUTH); ptiempo.setVisible(false); siguiente.setEnabled(false); atras.setEnabled(false); presentacion.setEnabled(false); grid.setEnabled(false); bcomentario.setEnabled(false); zoom.setEnabled(false); /* Abre el selector desde que inicia el programa */ chooser = new JFileChooser(); chooser.setDialogTitle("Selecciona una imagen..."); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setAcceptAllFileFilterUsed(false); // Abrir archivo es de acá... returnChooser = chooser.showOpenDialog(ArcViewer.this); if (returnChooser == 0) { imagenes = lista.Miranda(chooser, returnChooser); siguiente.setEnabled(true); atras.setEnabled(true); presentacion.setEnabled(true); grid.setEnabled(true); bcomentario.setEnabled(true); zoom.setEnabled(true); for (int asd1 = 0; asd1 < imagenes.size(); asd1++) { imagenesbean.add(new ImagenBean(imagenes.get(asd1), 0, 0)); } String getImgSelected = chooser.getSelectedFile().getPath(); for (int index = 0; index < imagenesbean.size(); index++) { if (getImgSelected.equals(imagenesbean.get(index).getIcon())) { imagen.setIcon(new ImageIcon(imagenesbean.get(index).getIcon())); indexaux = index; } } } else { System.out.println("No Selection"); carpeta.setEnabled(true); } // for (int asd1=0; asd1 < imagenes.size(); asd1++) { // imagenesbean.add(new ImagenBean(imagenes.get(asd1),0,0)); // } // String getImgSelected = chooser.getSelectedFile().getPath(); // for (int index=0; index < imagenesbean.size(); index++) { // if (getImgSelected.equals( imagenesbean.get(index).getIcon() )) { // imagen.setIcon(new ImageIcon(imagenesbean.get(index).getIcon())); // indexaux = index; // } // } }
public Design() throws Exception { super.setBackground(Color.BLACK); this.setTitle(""); con = getContentPane(); con.setLayout(null); dim = tk.getDefaultToolkit().getScreenSize(); this.setTitle("Customer Peer Login"); l1 = new JLabel(new ImageIcon("plain.jpg")); l1.setBounds(0, 0, 400, 400); con.add(l1); l1.setBorder(BorderFactory.createEtchedBorder(5, Color.black, Color.black)); title = new JLabel("CUSTOMER PEER LOGIN "); title.setFont(new Font("Bookman Old Style", Font.ROMAN_BASELINE, 20)); title.setForeground(Color.red); title.setBounds(80, 30, 300, 30); l1.add(title); l4 = new JLabel("CMACHINE NAME"); l4.setFont(new Font("Bookman Old Style", Font.BOLD, 16)); l4.setForeground(Color.BLUE); l4.setBounds(70, 100, 160, 20); // l4.setBorder(BorderFactory.createEtchedBorder(5,Color.green,Color.green)); l1.add(l4); jtf2 = new JTextField(); jtf2.setBounds(250, 100, 100, 20); jtf2.setBorder(BorderFactory.createEtchedBorder(5, Color.green, Color.green)); l1.add(jtf2); l2 = new JLabel("CUSER LOGIN"); l2.setFont(new Font("Bookman Old Style", Font.BOLD, 16)); l2.setForeground(Color.blue); l2.setBounds(70, 150, 120, 20); l1.add(l2); jtf1 = new JTextField(); jtf1.setBounds(250, 150, 100, 20); jtf1.setBorder(BorderFactory.createEtchedBorder(5, Color.green, Color.green)); l1.add(jtf1); l3 = new JLabel("CPASSWORD"); l3.setFont(new Font("Bookman Old Style", Font.BOLD, 16)); l3.setForeground(Color.blue); l3.setBounds(70, 200, 120, 20); l1.add(l3); jptf1 = new JPasswordField(); jptf1.setBounds(250, 200, 100, 20); jptf1.setBorder(BorderFactory.createEtchedBorder(5, Color.green, Color.green)); l1.add(jptf1); JLabel l4 = new JLabel("DAgent"); l4.setFont(new Font("Bookman Old Style", Font.BOLD, 16)); l4.setForeground(Color.blue); l4.setBounds(70, 250, 120, 20); l1.add(l4); box = new JComboBox(); box.setBounds(250, 250, 100, 20); box.setBorder(BorderFactory.createEtchedBorder(5, Color.green, Color.green)); l1.add(box); b2 = new JButton("Register"); b2.setBounds(50, 300, 100, 20); l1.add(b2); b2.setBorder(BorderFactory.createEtchedBorder(10, Color.BLUE, Color.BLUE)); b3 = new JButton("Login"); b3.setBounds(150, 300, 100, 20); b3.setBorder(BorderFactory.createEtchedBorder(10, Color.BLUE, Color.BLUE)); l1.add(b3); b1 = new JButton("Cancel"); b1.setBounds(250, 300, 100, 20); b1.setBorder(BorderFactory.createEtchedBorder(10, Color.BLUE, Color.BLUE)); l1.add(b1); b1.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent we) { dispose(); } }); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn = DriverManager.getConnection("jdbc:odbc:agent"); } catch (Exception exp) { } try { Statement satem = conn.createStatement(); ResultSet rsatem = satem.executeQuery("select * from Dagent"); while (rsatem.next()) { String namem = rsatem.getString("uname"); box.addItem(namem); } } catch (Exception expo1) { } b2.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent we) { String username = jtf1.getText().trim(); String password = jptf1.getText().trim(); String mechine = jtf2.getText().trim(); String dname = box.getSelectedItem().toString(); int porte = 0; try { Statement sate = conn.createStatement(); ResultSet rsate = sate.executeQuery("select * from Dagent where uname='" + dname + "'"); if (rsate.next()) { servermachine = rsate.getString("umechine"); porte = rsate.getInt("ulistport"); System.out.println(servermachine); } System.out.println(servermachine); } catch (Exception exp) { exp.printStackTrace(); } try { packet p = new packet(); p.setaction("Creg"); p.setCuser(username); p.setCpass(password); p.setCmname(mechine); p.setCDpeer(dname); Socket soc = new Socket(servermachine, porte); ObjectOutputStream out = new ObjectOutputStream(soc.getOutputStream()); out.writeObject(p); ObjectInputStream in = new ObjectInputStream(soc.getInputStream()); packet rpac = (packet) in.readObject(); if (rpac.getaction().equals("ok")) { JOptionPane.showMessageDialog(null, "Sucessfully Registered"); jtf2.setText(""); jtf1.setText(""); jptf1.setText(""); } else { JOptionPane.showMessageDialog(null, "Already Registered"); jtf2.setText(""); jtf1.setText(""); jptf1.setText(""); } } catch (Exception exp) { } } }); b3.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent we) { String username = jtf1.getText().trim(); String password = jptf1.getText().trim(); String mechine = jtf2.getText().trim(); String Dname = box.getSelectedItem().toString(); int porte = 0; try { Statement sate = conn.createStatement(); ResultSet rsate = sate.executeQuery("select * from Dagent where uname='" + Dname + "'"); if (rsate.next()) { servermachine = rsate.getString("umechine"); porte = rsate.getInt("ulistport"); System.out.println(servermachine); } System.out.println(servermachine); } catch (Exception exp) { } try { packet p1 = new packet(); p1.setaction("clogin"); p1.setCuser(username); p1.setCpass(password); p1.setCmname(mechine); p1.setCDpeer(Dname); Socket soc1 = new Socket(servermachine, porte); ObjectOutputStream out1 = new ObjectOutputStream(soc1.getOutputStream()); out1.writeObject(p1); ObjectInputStream in1 = new ObjectInputStream(soc1.getInputStream()); packet rpac1 = (packet) in1.readObject(); if (rpac1.getaction().equals("ok")) { int port1 = 0; try { int portm = rpac1.getCport(); System.out.println("XXXXXXX" + portm); // JOptionPane.showMessageDialog(null,"Sucessfully Started"); new Listen(portm); new process(username, portm); dispose(); } catch (Exception exp) { } } else { JOptionPane.showMessageDialog( null, "Enter valid username and password", "Server reply", 2); jtf1.setText(""); jtf2.setText(""); jptf1.setText(""); } } catch (Exception exp) { } } }); setSize(400, 400); show(); setLocation(150, 100); setResizable(false); }