Devido a uma solicitação, vou colocar o código fonte do jogo da forca que aqui foi postado em 16 de Dezembro de 2015.
Atenção este código já está desatualizado, como por exemplo a escrita e leitura de ficheiros, mas que ainda funcionam. Para a reprodução de som mp3 utilizei uma livraria externa, que se pode efetuar o download em http://jacomp3player.sourceforge.net/.
package jogoDaForcaV2; import java.awt.Color; import java.awt.Cursor; import java.awt.Desktop; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.LineNumberReader; import java.net.URI; import java.net.URISyntaxException; import java.text.Normalizer; import java.util.Random; import javax.swing.BorderFactory; import javax.swing.ButtonGroup; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JRadioButton; import javax.swing.JTextField; import javax.swing.UIManager; import javax.swing.plaf.ColorUIResource; import jaco.mp3.player.MP3Player; public class JogoDaForcaV2 { static JFrame frmMain; static JLabel lblPalavraNaoAdivinhada, lblimagem1, lblimagem2, lblimagem3, lblimagem4, lblimagem5, lblimagem6, lblimagem7; static JRadioButton rdbPalavraAjudaNao; static JTextField txtLetrasJogada, txtPalavraAjuda, txtPalaAdivinhar; static JButton btniniciar; static JButton[] btnBotoes = new JButton[26]; static String ficheiroAtivo = "animais.txt", palavra, letra; static int numeroTentaivas = 0; public static void main(String[] args) { frmMain = new JFrame("Jogo do Galo V2"); frmMain.setLayout(null); frmMain.setBounds(100, 100, 942, 690); frmMain.setResizable(false); // Impede que a frame seja ajustada com o rato frmMain.setLocationRelativeTo(null); // Centra a Jframe no centro do ecrã JMenuBar menu = new JMenuBar(); frmMain.setJMenuBar(menu); JMenu ficheiro = new JMenu("Ficheiro"); menu.add(ficheiro); JMenu ajuda = new JMenu("Ajuda"); menu.add(ajuda); JMenuItem inserir = new JMenuItem("Inserir"); ficheiro.add(inserir); inserir.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { inserir(); } }); JMenuItem sair = new JMenuItem("Sair"); ficheiro.add(sair); sair.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); JMenuItem credito = new JMenuItem("Créditos"); ajuda.add(credito); credito.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { creditos(); } }); Color minhaCor1 = new Color(255,255,255); // Côr personalizada RGB lblPalavraNaoAdivinhada = new JLabel("", JLabel.CENTER); lblPalavraNaoAdivinhada.setBounds(1, 100, 610, 40); lblPalavraNaoAdivinhada.setBorder(BorderFactory. createBevelBorder(1)); lblPalavraNaoAdivinhada.setFont(new Font("Verdana", Font.PLAIN, 22)); lblPalavraNaoAdivinhada.setForeground(Color.RED); frmMain.add(lblPalavraNaoAdivinhada); JLabel lblInfoLetrasJogadas = new JLabel("Letras Jogadas", JLabel.CENTER); lblInfoLetrasJogadas.setBounds(650, 93, 270, 50); lblInfoLetrasJogadas.setFont(new Font("Verdana", Font.BOLD, 22)); frmMain.add(lblInfoLetrasJogadas); txtLetrasJogada = new JTextField(); txtLetrasJogada.setBounds(622,133, 300, 30); txtLetrasJogada.setBackground(minhaCor1); // Coloca a côr em background txtLetrasJogada.setBorder(null); // Remove Borda da caixa de texto txtLetrasJogada.setEditable(false); // Impede que se edite o conteúdo da caixa frmMain.add(txtLetrasJogada); JLabel lblPalavraAdivinhar = new JLabel("Palavra a Adivinhar", JLabel.CENTER); lblPalavraAdivinhar.setBounds(650, 183, 270, 30); lblPalavraAdivinhar.setFont(new Font("Verdana", Font.BOLD, 22)); frmMain.add(lblPalavraAdivinhar); txtPalaAdivinhar = new JTextField(); txtPalaAdivinhar.setFont(new Font("Verdana", Font.PLAIN, 16)); // Define-se a fonte, tipo e tamanho txtPalaAdivinhar.setHorizontalAlignment(JTextField.CENTER); // Centra o texto txtPalaAdivinhar.setBackground(minhaCor1); txtPalaAdivinhar.setBorder(null); // Remove Borda da caixa de texto txtPalaAdivinhar.setEditable(false); // Impede que se edite o conteúdo da caixa txtPalaAdivinhar.setBounds(622, 223, 300, 30); frmMain.add(txtPalaAdivinhar); JLabel lblPalavraAjuda = new JLabel("Ajuda:", JLabel.LEFT); lblPalavraAjuda.setBounds(622,263, 270, 30); lblPalavraAjuda.setFont(new Font("Verdana", Font.BOLD,22)); frmMain.add(lblPalavraAjuda); txtPalavraAjuda = new JTextField(); txtPalavraAjuda.setFont(new Font("Verdana", Font.PLAIN, 16)); txtPalavraAjuda.setBackground(minhaCor1); txtPalavraAjuda.setBorder(null); txtPalavraAjuda.setEditable(false); txtPalavraAjuda.setBounds(622, 298, 300, 30); txtPalavraAjuda.setVisible(false); frmMain.add(txtPalavraAjuda); ButtonGroup btgPalavraAjuda = new ButtonGroup(); JRadioButton rdbPalavraAjudaSim = new JRadioButton("Sim"); rdbPalavraAjudaSim.setBounds(710, 265, 60, 30); rdbPalavraAjudaSim.addActionListener(palavraAjudaSimNao); frmMain.add(rdbPalavraAjudaSim); btgPalavraAjuda.add(rdbPalavraAjudaSim); rdbPalavraAjudaNao = new JRadioButton("Não", true); rdbPalavraAjudaNao.setBounds(770, 265, 60, 30); rdbPalavraAjudaNao.addActionListener(palavraAjudaSimNao); frmMain.add(rdbPalavraAjudaNao); btgPalavraAjuda.add(rdbPalavraAjudaNao); ButtonGroup btgTemas = new ButtonGroup(); JLabel animais = new JLabel(); animais.setBounds(610,333,48,48); animais.setIcon(new ImageIcon("icons/animais.gif")); frmMain.add(animais); JRadioButton rdbAnimais = new JRadioButton("Animais", true); rdbAnimais.setBounds(600, 380, 80, 20); frmMain.add(rdbAnimais); btgTemas.add(rdbAnimais); rdbAnimais.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ficheiroAtivo = "animais.txt"; } }); JLabel cidades = new JLabel(); cidades.setBounds(710, 333, 24, 48); cidades.setIcon(new ImageIcon("icons/cidades.gif")); frmMain.add(cidades); JRadioButton rdbCidades = new JRadioButton("Cidades"); rdbCidades.setBounds(680, 380, 80, 20); frmMain.add(rdbCidades); btgTemas.add(rdbCidades); rdbCidades.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ficheiroAtivo = "cidades.txt"; } }); JLabel desporto = new JLabel(); desporto.setBounds(780, 333, 48, 48); desporto.setIcon(new ImageIcon("icons/desporto.gif")); frmMain.add(desporto); JRadioButton rdbDesporto = new JRadioButton("Desporto"); rdbDesporto.setBounds(760, 380, 80, 20); frmMain.add(rdbDesporto); btgTemas.add(rdbDesporto); rdbDesporto.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ficheiroAtivo = "desporto.txt"; } }); JLabel frutos = new JLabel(); frutos.setBounds(860, 333, 48, 48); frutos.setIcon(new ImageIcon("icons/frutos.gif")); frmMain.add(frutos); JRadioButton rdbFrutos = new JRadioButton("Frutos"); rdbFrutos.setBounds(850, 380, 80, 20); frmMain.add(rdbFrutos); btgTemas.add(rdbFrutos); rdbFrutos.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ficheiroAtivo = "frutos.txt"; } }); btniniciar = new JButton("INICIAR"); btniniciar.setBounds(615, 1, 317, 93); btniniciar.setFont(new Font("Verdana", Font.BOLD,16)); UIManager.put("ToolTip.background", new ColorUIResource(255,255,255)); btniniciar.setToolTipText("<html>Clique aqui...<br/>para poder jogar...</html>"); frmMain.add(btniniciar); btniniciar.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { novoJogo(); palavraSorteada(); mostraLetrasJogadas(); } }); imagens(); // Função com as imagens for (int i = 0; i < 26; i++) { JButton btnTeclado = new JButton(); btnTeclado.setBounds(i%13*47, i/13*47, 47, 47); btnBotoes[i] = btnTeclado; btnTeclado.setText(String.valueOf((char)('A' + i))); UIManager.put("ToolTip.background", new ColorUIResource(255,255,255)); btnTeclado.setToolTipText("<html>Clique em qualquer tecla para jogar...</html>"); frmMain.add(btnTeclado); btnTeclado.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JButton btnLetra = (JButton) e.getSource(); btnLetra.setEnabled(false); txtLetrasJogada.setFont(new Font("Verdana", Font.PLAIN, 16)); letra = String.valueOf(btnLetra.getText()); txtLetrasJogada.setText(txtLetrasJogada.getText() + letra + " "); mostraLetrasJogadas(); if(verificaLetra()) { ganhou(); } else if (!verificaLetra() && !txtPalavraAjuda.getText().isEmpty()){ mostraForca(); } } }); } final Icon icoPlay = new ImageIcon("icons/speakerPlay.png"); final Icon icoStop = new ImageIcon("icons/speakerStop.png"); final JButton btnPlayStop = new JButton("|"); btnPlayStop.setBounds(850, 550, 80, 80); btnPlayStop.setBorder(BorderFactory.createBevelBorder(0)); btnPlayStop.setIcon(icoStop); btnPlayStop.setFont(new Font("Verdana", Font.PLAIN, 1)); frmMain.add(btnPlayStop); File ficheiroSom = new File("soms/Bruno_Sauty_ L_appel_de_la_foret.mp3"); final MP3Player reproduzSom = new MP3Player(ficheiroSom); btnPlayStop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String valBtn = e.getActionCommand(); if (valBtn.equals("|")) { btnPlayStop.setIcon(icoPlay); reproduzSom.play(); btnPlayStop.setText(">"); } else { btnPlayStop.setIcon(icoStop); reproduzSom.pause(); btnPlayStop.setText("|"); } } }); frmMain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Fecha os programas e a frame na cruz frmMain.setVisible(true); } //---------------------------------------------------------------------------------------------------- static private void inserir() { // Personalização de OptionPane UIManager.put("OptionPane.okButtonText", "OK"); // Mudar a texto do botão //UIManager.put("OptionPane.background", Color.WHITE); // Cor de fundo da caixa de diálogo UIManager.put("OptionPane.messageForeground", Color.BLACK); // Cor do texto //UIManager.put("Panel.background", Color.WHITE); // Cor de fundo do painel que se encontra dentro da caixa de diálogo UIManager.put("OptionPane.messageFont", new Font("Verdana", Font.BOLD, 16)); // Tipo de fonte e tamanho; JFrame frmInserir = new JFrame("Inserir Palavras Novas"); frmInserir.setLayout(null); frmInserir.setBounds(300, 300, 305, 274); frmInserir.setResizable(false); frmInserir.setLocationRelativeTo(null); int ficheiroEmUsoComprimento = ficheiroAtivo.length(); String ficheiroEmUsoPrimeiraLetra = ficheiroAtivo.substring(0, 1).toUpperCase(); String ficheiroEmUso = ficheiroAtivo.substring(1, ficheiroEmUsoComprimento-4); frmInserir.setTitle(ficheiroEmUsoPrimeiraLetra + ficheiroEmUso + ", em ficheiro " + ficheiroAtivo); JLabel lblPalavraInserir = new JLabel("Palavra Nova", JLabel.CENTER); lblPalavraInserir.setBounds(0, 0, 300, 35); lblPalavraInserir.setFont(new Font("Verdana", Font.BOLD, 22)); lblPalavraInserir.setBorder(BorderFactory.createBevelBorder(0)); frmInserir.add(lblPalavraInserir); final JTextField txtPalavraInserir = new JTextField(); txtPalavraInserir.setBounds(2, 36, 295, 30); txtPalavraInserir.setFont(new Font("Verdana", Font.PLAIN, 16)); txtPalavraInserir.setBorder(BorderFactory.createBevelBorder(1)); frmInserir.add(txtPalavraInserir); JLabel lblAjudaInserir = new JLabel("Ajuda", JLabel.CENTER); lblAjudaInserir.setBounds(0, 72, 300, 35); lblAjudaInserir.setFont(new Font("Verdana", Font.BOLD, 22)); lblAjudaInserir.setBorder(BorderFactory.createBevelBorder(0)); frmInserir.add(lblAjudaInserir); final JTextField txtAjudaInserir = new JTextField(); txtAjudaInserir.setBounds(2, 108, 295, 30); txtAjudaInserir.setFont(new Font("Verdana", Font.PLAIN, 16)); txtAjudaInserir.setBorder(BorderFactory.createBevelBorder(1)); frmInserir.add(txtAjudaInserir); JButton btnInserir = new JButton("INSERIR"); btnInserir.setBounds(0, 145, 300, 100); frmInserir.add(btnInserir); btnInserir.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String palavraNova = txtPalavraInserir.getText(); String ajudaNova = txtAjudaInserir.getText(); ImageIcon icoExclamacao = new ImageIcon("icons/exclamacao.gif"); // Icon personalizado if (palavraNova.isEmpty()) { JOptionPane.showMessageDialog(null, "Digite uma palavra nova válida...", "Palavra Nova Inválida", JOptionPane.INFORMATION_MESSAGE, icoExclamacao); } else if (ajudaNova.isEmpty()) { JOptionPane.showMessageDialog(null, "Digite uma ajuda nova válida...", "Ajuda Nova Inválida", JOptionPane.INFORMATION_MESSAGE, icoExclamacao); } else { if(verificaPalavra(palavraNova)) { ImageIcon icoExiste = new ImageIcon("icons/existe.gif"); JOptionPane.showMessageDialog(null, "A palavra digitada já existe, digite uma palavra nova...", "Palavra já Existe", JOptionPane.INFORMATION_MESSAGE, icoExiste); txtPalavraInserir.setText(""); txtAjudaInserir.setText(""); } else { ImageIcon icoPalavraNova = new ImageIcon("icons/palavranova.gif"); acrescentaPalavras(palavraNova, ajudaNova); JOptionPane.showMessageDialog(null, "Palavra acrescentada com sucesso...", "Palavra Acrescentada", JOptionPane.INFORMATION_MESSAGE, icoPalavraNova); txtPalavraInserir.setText(""); txtAjudaInserir.setText(""); } } } }); frmInserir.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // Fecha a frame que foi chamada clicando na cruz frmInserir.setVisible(true); } //---------------------------------------------------------------------------------------------------- static private boolean verificaPalavra(String palavraNova) { try { BufferedReader in = new BufferedReader(new FileReader(ficheiroAtivo)); String linhas = null; while((linhas = in.readLine()) != null) { String[] linha = linhas.split(";"); if((palavraNova.replace(" ", "").toUpperCase()).equals(linha[0].replace(" ", "").toUpperCase())) { // Remove espaços, converte para maíusculas e compara in.close(); //Fecha o buffer e ficheiro return true; } } in.close(); //Fecha o buffer e ficheiro } catch (Exception e) { System.err.println("Error: " + e.getMessage()); } return false; } //---------------------------------------------------------------------------------------------------- static private void acrescentaPalavras(String palavraNova, String ajudaNova) { palavraNova = Normalizer.normalize(palavraNova, Normalizer.Form.NFD); // Elimina acentos e cedilhas dos carateres palavraNova = palavraNova.replaceAll("[^\\p{ASCII}]", ""); // Expressão regular em que elimina carateres não reconhecidos após conversão //palavraNova = palavraNova.replace(" ", ""); // Elimina espaços em branco try { BufferedWriter out = new BufferedWriter(new FileWriter(ficheiroAtivo, true)); out.write(palavraNova + ";" + ajudaNova + "\r\n"); out.close(); } catch (IOException e) { e.printStackTrace(); } } //---------------------------------------------------------------------------------------------------- static private void imagens() { JLabel lblimagem0 = new JLabel(); lblimagem0.setBounds(100, 178,366,463); lblimagem0.setIcon(new ImageIcon("imagem/forca.gif")); // Mostra a base do jogo da forca frmMain.add(lblimagem0); lblimagem1 = new JLabel(); lblimagem1.setBounds(272,296,114,112); lblimagem1.setIcon(new ImageIcon("imagem/cabecaforca.gif")); lblimagem1.setVisible(false); frmMain.add(lblimagem1); lblimagem2 = new JLabel(); lblimagem2.setBounds(297,402,71,74); lblimagem2.setIcon(new ImageIcon("imagem/troncoforca.gif")); lblimagem2.setVisible(false); frmMain.add(lblimagem2); lblimagem3 = new JLabel(); lblimagem3.setBounds(282,398,20,86); lblimagem3.setIcon(new ImageIcon("imagem/bracoesq.gif")); lblimagem3.setVisible(false); frmMain.add(lblimagem3); lblimagem4 = new JLabel(); lblimagem4.setBounds(357,396,27,83); lblimagem4.setIcon(new ImageIcon("imagem/bracodir.gif")); lblimagem4.setVisible(false); frmMain.add(lblimagem4); lblimagem5 = new JLabel(); lblimagem5.setBounds(300,475,36,79); lblimagem5.setIcon(new ImageIcon("imagem/peesq.gif")); lblimagem5.setVisible(false); frmMain.add(lblimagem5); lblimagem6 = new JLabel(); lblimagem6.setBounds(335,472,41,84); lblimagem6.setIcon(new ImageIcon("imagem/pedir.gif")); lblimagem6.setVisible(false); frmMain.add(lblimagem6); lblimagem7 = new JLabel(); lblimagem7.setBounds(272,296,114,112); lblimagem7.setIcon(new ImageIcon("imagem/cabecaforcalingua.gif")); lblimagem7.setVisible(false); frmMain.add(lblimagem7); } //-------------------------------------------------------------------------------------------------- static ActionListener palavraAjudaSimNao = new ActionListener() { public void actionPerformed(ActionEvent e) { if(rdbPalavraAjudaNao.isSelected()) { txtPalavraAjuda.setVisible(false); } else { txtPalavraAjuda.setVisible(true); } } }; //-------------------------------------------------------------------------------------------------- static private void novoJogo() { for (int i = 0; i < 26; i++) { btnBotoes[i].setEnabled(true); } txtLetrasJogada.setText(""); txtPalaAdivinhar.setText(""); txtPalavraAjuda.setText(""); numeroTentaivas = 0; lblPalavraNaoAdivinhada.setText(""); lblimagem7.setVisible(false); lblimagem1.setVisible(false); lblimagem2.setVisible(false); lblimagem3.setVisible(false); lblimagem4.setVisible(false); lblimagem5.setVisible(false); lblimagem6.setVisible(false); lblimagem7.setVisible(false); } //-------------------------------------------------------------------------------------------------- private static void palavraSorteada() { int linha, linhas = 0; try { FileReader ficheiro = new FileReader(ficheiroAtivo); LineNumberReader leLinhas = new LineNumberReader(ficheiro); while(leLinhas.readLine() != null) { linhas = leLinhas.getLineNumber(); //Número de linhas do ficheiro } leLinhas.close(); //Fecha o ficheiro } catch (Exception e) { System.err.println("Error: " + e.getMessage()); } Random linhaAleatoria = new Random(); linha = (linhaAleatoria.nextInt(linhas))+1; try{ FileReader ficheiro = new FileReader(ficheiroAtivo); BufferedReader in = new BufferedReader(ficheiro); for (int i = 1; i <= linhas; i++) { if (i == linha) { String palavrasLinha[] = (in.readLine()).split(";"); //Divide o conteúdo quando encontra o carater especificado e coloca num array palavra = palavrasLinha[0].toUpperCase(); String ajuda = palavrasLinha[1].toUpperCase(); txtPalavraAjuda.setText(ajuda); } else { in.readLine(); //passa para a linha seguinte } } in.close(); //Fecha o ficheiro }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } //-------------------------------------------------------------------------------------------------- static private void mostraLetrasJogadas() { if(txtPalavraAjuda.getText().isEmpty()) { for (int i = 0; i < 26; i++) { btnBotoes[i].setEnabled(true); } txtLetrasJogada.setText(""); JOptionPane.showMessageDialog(frmMain, "Clique primeiro no botão INICIAR, para jogar."); return; } String letrasJaUsadas = txtLetrasJogada.getText(); String s = ""; for (int i = 0; i < palavra.length(); i++) { char letra = palavra.charAt(i); if(letrasJaUsadas.indexOf(letra) >= 0) { s = s + letra + " "; } else { s = s + "_ "; } } txtPalaAdivinhar.setText(s); } //-------------------------------------------------------------------------------------------------- static private boolean verificaLetra() { String letrasAcertadas = txtPalaAdivinhar.getText(); if (letrasAcertadas.contains(letra) ) { return true; } else { return false; } } //-------------------------------------------------------------------------------------------------- static private void ganhou() { if(palavra.replace(" ", "").equals(txtPalaAdivinhar.getText().replace(" ", ""))) { File ficheiro = new File("soms/BeeGeesStayingAlive.mp3"); final MP3Player player = new MP3Player(ficheiro); player.play(); for (int i = 0; i < 26; i++) { btnBotoes[i].setEnabled(false); } JFrame frmGanhou = new JFrame("Ganhou"); frmGanhou.setLayout(null); frmGanhou.setResizable(false); frmGanhou.setBounds(400, 350, 350, 110); frmGanhou.getContentPane().setBackground(Color.WHITE); // Muda cor de fundo da JFrame frmGanhou.setLocationRelativeTo(null); JLabel lblGanhasteImagem = new JLabel(); lblGanhasteImagem.setBounds(10, 10, 60, 60); lblGanhasteImagem.setIcon(new ImageIcon("icons/ganhou.gif")); lblGanhasteImagem.setToolTipText("<html>Clique aqui...<br/>Som off...</html>"); frmGanhou.add(lblGanhasteImagem); lblGanhasteImagem.addMouseListener(new MouseListener() { public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub } public void mousePressed(MouseEvent e) { // TODO Auto-generated method stub } public void mouseExited(MouseEvent e) { // TODO Auto-generated method stub } public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub } public void mouseClicked(MouseEvent e) { player.stop(); // Clica na imagem pára som } }); JLabel lblGanhaste = new JLabel("Parabéns Ganhaste..."); lblGanhaste.setBounds(80, 5, 280, 80); lblGanhaste.setFont(new Font("Verdana", Font.PLAIN, 22)); lblGanhaste.setForeground(Color.BLUE); frmGanhou.add(lblGanhaste); frmGanhou.addWindowListener(new WindowListener() { public void windowOpened(WindowEvent e) { // TODO Auto-generated method stub } public void windowIconified(WindowEvent e) { // TODO Auto-generated method stub } public void windowDeiconified(WindowEvent e) { // TODO Auto-generated method stub } public void windowDeactivated(WindowEvent e) { // TODO Auto-generated method stub } public void windowClosing(WindowEvent e) { // TODO Auto-generated method stub } public void windowClosed(WindowEvent e) { player.stop(); // Pára som ao sair } public void windowActivated(WindowEvent e) { // TODO Auto-generated method stub } }); frmGanhou.setVisible(true); frmGanhou.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // Fecha a frame que foi chamada clicando na cruz } } //-------------------------------------------------------------------------------------------------- static private void mostraForca() { numeroTentaivas++; switch (numeroTentaivas) { case 1: lblimagem1.setVisible(true); break; case 2: lblimagem2.setVisible(true); break; case 3: lblimagem3.setVisible(true); break; case 4: lblimagem4.setVisible(true); break; case 5: lblimagem5.setVisible(true); break; case 6: lblimagem6.setVisible(true); lblimagem1.setVisible(false); lblimagem7.setVisible(true); for (int i = 0; i < 26; i++) { btnBotoes[i].setEnabled(false); } lblPalavraNaoAdivinhada.setText("A palavra é: " + palavra); break; } } //-------------------------------------------------------------------------------------------------- static private void creditos() { JFrame frmCreditos = new JFrame("Créditos"); frmCreditos.setLayout(null); frmCreditos.setResizable(false); frmCreditos.setBounds(400, 350, 350,200); frmCreditos.getContentPane().setBackground(Color.WHITE); // Muda cor de fundo da JFrame frmCreditos.setLocationRelativeTo(null); JLabel lblJogoVersao = new JLabel("Jogo da Forca V2", JLabel.CENTER); lblJogoVersao.setBounds(0, 0, 300, 35); lblJogoVersao.setFont(new Font("Verdana", Font.BOLD, 22)); frmCreditos.add(lblJogoVersao); JLabel lblNome = new JLabel("Desenvolvido por: José Carlos", JLabel.CENTER); lblNome.setBounds(0, 40, 300, 35); lblNome.setFont(new Font("Verdana", Font.PLAIN, 12)); frmCreditos.add(lblNome); JLabel lblContacto = new JLabel("<html>Contacto: <a href='http://zcarlos.pt'>http://zcarlos.pt</a></html>", JLabel.CENTER); lblContacto.setBounds(0, 75, 300, 35); lblContacto.setFont(new Font("Verdana", Font.PLAIN, 12)); lblContacto.setCursor(new Cursor(Cursor.HAND_CURSOR)); frmCreditos.add(lblContacto); lblContacto.addMouseListener(new MouseListener() { @Override public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mousePressed(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseExited(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseClicked(MouseEvent e) { try { Desktop.getDesktop().browse(new URI("http://zcarlos.pt")); } catch (IOException erro) { // TODO Auto-generated catch block erro.printStackTrace(); } catch (URISyntaxException erro) { // TODO Auto-generated catch block erro.printStackTrace(); } } }); frmCreditos.setVisible(true); frmCreditos.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // Fecha a frame que foi chamada clicando na cruz } }