java - classes, métodos e interface gráfica

21
MINISTÉRIO DA EDUCAÇÃO UNIVERSIDADE FEDERAL DOS VALES DO JEQUITINHONHA E MUCURI CAMPUS AVANÇADO DO MUCURI TEÓFILO OTONI - MG BACHARELADO EM CIÊNCIA E TECNOLOGIA www.ufvjm.edu.br [email protected] Aluno: Rogério Fonseca Santos - Algoritmo e Programação Questão 1) Para que serve os Componentes Visuais Abaixo: a) JOptionPane = permite a exibição de caixas de diálogo utilizadas com o objetivo de interagir com o usuário da aplicação, exibindo mensagens importantes ou recebendo informações inseridas pelo usuário da aplicação. b) JFrame = Possui todos os componentes visuais necessários da aplicação. c) JLabel = Fornece um componente na qual é possível inserir texto ou informações. d) JPanel = Permite a inclusão de painéis na aplicação. e) JButton = Promove a ação de interação com o usuário gerando eventos e permitindo visualizar texto e imagem. f) JCheckBox = Utilizado quando se tem a necessidade de seleção múltipla, oferecendo grande flexibilidade para o usuário do sistema. g) JComboBox = Utilizado quando se tem a necessidade de selecionar um determinado item entre vários disponíveis. h) JMenu = Possibilita a seleção de ações através de uma disposição de botões embutidos em uma estrutura configurável e elegante. Questão 2) Elabore uma Classe Ola com os métodos: a. Um método show que recebe uma string e mostra o conteúdo no JOptionPane. b. Um método leString que utiliza o JOptionPane para lê e retornar uma string. c. Um método leInteiro que utiliza o JOptionPane para lê e retornar um numero inteiro. package Teste; /** * * @author Rogério */ import javax.swing.JOptionPane; public class Ola { void show (String s) { JOptionPane.showMessageDialog(null, s); } String leString() { String s=JOptionPane.showInputDialog("Digite: ");

Upload: rogerio-fonseca

Post on 25-Nov-2015

100 views

Category:

Documents


0 download

TRANSCRIPT

  • MINISTRIO DA EDUCAO

    UNIVERSIDADE FEDERAL DOS VALES DO JEQUITINHONHA E MUCURI CAMPUS AVANADO DO MUCURI TEFILO OTONI - MG

    BACHARELADO EM CINCIA E TECNOLOGIA www.ufvjm.edu.br [email protected]

    Aluno: Rogrio Fonseca Santos - Algoritmo e Programao

    Questo 1) Para que serve os Componentes Visuais Abaixo:

    a) JOptionPane = permite a exibio de caixas de dilogo utilizadas com o objetivo de

    interagir com o usurio da aplicao, exibindo mensagens importantes ou

    recebendo informaes inseridas pelo usurio da aplicao.

    b) JFrame = Possui todos os componentes visuais necessrios da aplicao. c) JLabel = Fornece um componente na qual possvel inserir texto ou informaes.

    d) JPanel = Permite a incluso de painis na aplicao. e) JButton = Promove a ao de interao com o usurio gerando eventos e

    permitindo visualizar texto e imagem.

    f) JCheckBox = Utilizado quando se tem a necessidade de seleo mltipla,

    oferecendo grande flexibilidade para o usurio do sistema.

    g) JComboBox = Utilizado quando se tem a necessidade de selecionar um determinado item entre vrios disponveis.

    h) JMenu = Possibilita a seleo de aes atravs de uma disposio de botes embutidos em uma estrutura configurvel e elegante.

    Questo 2) Elabore uma Classe Ola com os mtodos: a. Um mtodo show que recebe uma string e mostra o contedo no JOptionPane.

    b. Um mtodo leString que utiliza o JOptionPane para l e retornar uma string.

    c. Um mtodo leInteiro que utiliza o JOptionPane para l e retornar um numero inteiro. package Teste;

    /**

    *

    * @author Rogrio

    */

    import javax.swing.JOptionPane;

    public class Ola {

    void show (String s)

    { JOptionPane.showMessageDialog(null, s);

    }

    String leString()

    { String s=JOptionPane.showInputDialog("Digite: ");

  • MINISTRIO DA EDUCAO

    UNIVERSIDADE FEDERAL DOS VALES DO JEQUITINHONHA E MUCURI CAMPUS AVANADO DO MUCURI TEFILO OTONI - MG

    BACHARELADO EM CINCIA E TECNOLOGIA www.ufvjm.edu.br [email protected]

    Aluno: Rogrio Fonseca Santos - Algoritmo e Programao

    return s;

    }

    int leInteiro()

    { String s= JOptionPane.showInputDialog("Digite: ");

    int x=Integer.parseInt(s);

    return x;

    }

    }

    Questo 3) Elabore uma Classe Carro com os atributos (marca, cor), com mtodos e um servio especializado (ligar). package Teste;

    /**

    *

    * @author Rogrio

    */

    public class Carro {

    Ola ol = new Ola();

    String marca = ol.leString();

    String cor = ol.leString();

    }

    Questo 4) Elabore uma Interface Grfica que chame a classe Carro utilizando todos os mtodos ( utilize uma interface de Formulrio para L e Mostrar informaes ). package Teste;

    /**

    *

    * @author Rogrio

    */

    public class DadosCarro extends javax.swing.JFrame {

    public DadosCarro() {

    initComponents();

    }

  • MINISTRIO DA EDUCAO

    UNIVERSIDADE FEDERAL DOS VALES DO JEQUITINHONHA E MUCURI CAMPUS AVANADO DO MUCURI TEFILO OTONI - MG

    BACHARELADO EM CINCIA E TECNOLOGIA www.ufvjm.edu.br [email protected]

    Aluno: Rogrio Fonseca Santos - Algoritmo e Programao

    private void IniciarActionPerformed(java.awt.event.ActionEvent

    evt) {

    Carro car = new Carro();

    VerMarca.setText(car.marca);

    VerCor.setText(car.cor);

    }

    private void VerMarcaActionPerformed(java.awt.event.ActionEvent

    evt) {}

    public static void main(String args[]) {

    private javax.swing.JButton Iniciar;

    private javax.swing.JTextField VerCor;

    private javax.swing.JTextField VerMarca;

    private javax.swing.JLabel jLabel1;

    private javax.swing.JLabel jLabel2;

    private javax.swing.JLabel jLabel3;

    private javax.swing.JLabel jLabel4;

    private javax.swing.JLabel jLabel5;

    private javax.swing.JPanel jPanel2;

    }

    Questo 5) Elabore uma Classe Math que tenha: a. Um mtodo setAleatrio(), que retorna um numero aleatrio entre 10 e 80.

    b. Um mtodo setQuadrado(), que recebe um num retorna o quadrado do nmero.

    c. um mtodo setFatorial(), que recebe um num e retorna o fatorial do nmero.

    d. um mtodo setArranjo(), que recebe 2 num e retorna o arranjo dos mesmos. package Teste;

    /**

    *

    * @author Rogrio

    */

    import java.util.Random;

    public class Math {

    public int getAleatorio()

    { Random func=new Random();

    int n = func.nextInt(70);

  • MINISTRIO DA EDUCAO

    UNIVERSIDADE FEDERAL DOS VALES DO JEQUITINHONHA E MUCURI CAMPUS AVANADO DO MUCURI TEFILO OTONI - MG

    BACHARELADO EM CINCIA E TECNOLOGIA www.ufvjm.edu.br [email protected]

    Aluno: Rogrio Fonseca Santos - Algoritmo e Programao

    n=n+10;

    return n;

    }

    public int getQuadrado(int x)

    { x=x*x;

    return x;

    }

    public int getFatorial(int x)

    { int fat=1;

    for(int i=1; i

  • MINISTRIO DA EDUCAO

    UNIVERSIDADE FEDERAL DOS VALES DO JEQUITINHONHA E MUCURI CAMPUS AVANADO DO MUCURI TEFILO OTONI - MG

    BACHARELADO EM CINCIA E TECNOLOGIA www.ufvjm.edu.br [email protected]

    Aluno: Rogrio Fonseca Santos - Algoritmo e Programao

    ResAr.setText(String.valueOf(ma.getArranjo(num1, num2)));

    }

    private void VerAleActionPerformed(java.awt.event.ActionEvent

    evt) { }

    public static void main(String args[]) {

    java.awt.EventQueue.invokeLater(new Runnable() {

    public void run() {

    new Contas().setVisible(true);

    }

    });

    }

    private javax.swing.JButton Ini;

    private javax.swing.JTextField NumAr1;

    private javax.swing.JTextField NumAr2;

    private javax.swing.JTextField NumFat;

    private javax.swing.JTextField NumQ;

    private javax.swing.JTextField ResAr;

    private javax.swing.JTextField ResFat;

    private javax.swing.JTextField VerAle;

    private javax.swing.JTextField VerQuad;

    private javax.swing.JLabel jLabel1;

    private javax.swing.JLabel jLabel10;

    private javax.swing.JLabel jLabel2;

    private javax.swing.JLabel jLabel3;

    private javax.swing.JLabel jLabel4;

    private javax.swing.JLabel jLabel5;

    private javax.swing.JLabel jLabel6;

    private javax.swing.JLabel jLabel7;

    private javax.swing.JLabel jLabel8;

    private javax.swing.JLabel jLabel9;

    private javax.swing.JPanel jPanel1;

    private javax.swing.JPanel jPanel2;

    private javax.swing.JTextField jTextField7;

    private javax.swing.JTextField n1;

    private javax.swing.JTextField n2;

    }

    Questo 6) Quais os componentes necessrios para criar um MENU? JmenuComponent, JmenuBar,JmenuItem e Separador

  • MINISTRIO DA EDUCAO

    UNIVERSIDADE FEDERAL DOS VALES DO JEQUITINHONHA E MUCURI CAMPUS AVANADO DO MUCURI TEFILO OTONI - MG

    BACHARELADO EM CINCIA E TECNOLOGIA www.ufvjm.edu.br [email protected]

    Aluno: Rogrio Fonseca Santos - Algoritmo e Programao

    Questo 7) Dado o componente jButton, elabore um cdigo de programao que quando pressionado, imprima a mensagem Ola Mundo. package Teste;

    /**

    *

    * @author Rogrio

    */

    public class Questo7 extends javax.swing.JFrame {

    private void jButton1ActionPerformed(java.awt.event.ActionEvent

    evt) {

    System.out.println("Ol mundo!");

    }

    public static void main(String args[]) {

    java.awt.EventQueue.invokeLater(new Runnable() {

    public void run() {

    new Questo7().setVisible(true);

    }

    });

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables

    private javax.swing.JButton jButton1;

    private javax.swing.JPanel jPanel1;

    // End of variables declaration//GEN-END:variables

    }

    Questo 8) Dado o componente jCheckBox1, elabore um cdigo de programao que verifique se o componente esta selecionado ou no e imprima uma mensagem utilizando a classe Ola. package Teste;

    /**

    *

    * @author Rogrio

    */

    public class Questo8 extends javax.swing.JFrame {

    Ola ol = new Ola();

    public Questo8() {

    initComponents();

    }

  • MINISTRIO DA EDUCAO

    UNIVERSIDADE FEDERAL DOS VALES DO JEQUITINHONHA E MUCURI CAMPUS AVANADO DO MUCURI TEFILO OTONI - MG

    BACHARELADO EM CINCIA E TECNOLOGIA www.ufvjm.edu.br [email protected]

    Aluno: Rogrio Fonseca Santos - Algoritmo e Programao

    private void jButton1ActionPerformed(java.awt.event.ActionEvent

    evt) {//GEN-FIRST:event_jButton1ActionPerformed

    if(Caixa.isSelected())

    ol.show("Selecionada!");

    else

    ol.show("No Selecinada!");

    }

    public static void main(String args[]) {

    java.awt.EventQueue.invokeLater(new Runnable() {

    public void run() {

    new Questo8().setVisible(true);

    }

    });

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables

    private javax.swing.JCheckBox Caixa;

    private javax.swing.JButton jButton1;

    private javax.swing.JPanel jPanel1;

    // End of variables declaration//GEN-END:variables

    }

    Questo 9) Dado 1 componentes jTextField1 elabore um cdigo de programao que limpe as informaes digitada. package Teste;

    /**

    *

    * @author Rogrio

    */

    public class Questo9 extends javax.swing.JFrame {

    public Questo9() {

    initComponents();

    }

    private void jButton1ActionPerformed(java.awt.event.ActionEvent

    evt) {

    Campo.setText(null);

    }

    public static void main(String args[]) {

  • MINISTRIO DA EDUCAO

    UNIVERSIDADE FEDERAL DOS VALES DO JEQUITINHONHA E MUCURI CAMPUS AVANADO DO MUCURI TEFILO OTONI - MG

    BACHARELADO EM CINCIA E TECNOLOGIA www.ufvjm.edu.br [email protected]

    Aluno: Rogrio Fonseca Santos - Algoritmo e Programao

    java.awt.EventQueue.invokeLater(new Runnable() {

    public void run() {

    new Questo9().setVisible(true);

    }

    });

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables

    private javax.swing.JTextField Campo;

    private javax.swing.JButton jButton1;

    private javax.swing.JPanel jPanel1;

    // End of variables declaration//GEN-END:variables

    }

    Questo 10) Dado 2 componentes jTextField1 e jTextField2, elabore um cdigo de programao que leia do primeiro componente e escreva no segundo componente e mostre utilizando a classe Ola. package Teste;

    /**

    *

    * @author Rogrio

    */

    public class Questo10 extends javax.swing.JFrame {

    Ola ol = new Ola();

    public Questo10() {

    initComponents();

    }

    private voidTransferirActionPerformed(java.awt.event.ActionEvent

    evt) {

    String texto = Quadro1.getText();

    Quadro2.setText(texto);

    ol.show(texto);

    }

    public static void main(String args[]) {

  • MINISTRIO DA EDUCAO

    UNIVERSIDADE FEDERAL DOS VALES DO JEQUITINHONHA E MUCURI CAMPUS AVANADO DO MUCURI TEFILO OTONI - MG

    BACHARELADO EM CINCIA E TECNOLOGIA www.ufvjm.edu.br [email protected]

    Aluno: Rogrio Fonseca Santos - Algoritmo e Programao

    java.awt.EventQueue.invokeLater(new Runnable() {

    public void run() {

    new Questo10().setVisible(true);

    }

    });

    }

    private javax.swing.JTextField Quadro1;

    private javax.swing.JTextField Quadro2;

    private javax.swing.JButton Transferir;

    }

    Questo 11) Dado o componente jComboBox1, elabore um cdigo de programao que recupere a informao selecionada e imprima utilizando a classe Ola. package Teste;

    /**

    *

    * @author Rogrio

    */

    public class Questo11 extends javax.swing.JFrame {

    Ola ol = new Ola();

    public Questo11() {

    initComponents();

    }

    private void VerificarActionPerformed(java.awt.event.ActionEvent

    evt) {

    String select = (String)Combo.getSelectedItem();

    ol.show(select);

    }

    public static void main(String args[]) {

    java.awt.EventQueue.invokeLater(new Runnable() {

    public void run() {

    new Questo11().setVisible(true);

    }

    });

    }

  • MINISTRIO DA EDUCAO

    UNIVERSIDADE FEDERAL DOS VALES DO JEQUITINHONHA E MUCURI CAMPUS AVANADO DO MUCURI TEFILO OTONI - MG

    BACHARELADO EM CINCIA E TECNOLOGIA www.ufvjm.edu.br [email protected]

    Aluno: Rogrio Fonseca Santos - Algoritmo e Programao

    private javax.swing.JComboBox Combo;

    private javax.swing.JButton Verificar;

    private javax.swing.JPanel jPanel1;

    }

    Questo 12) Marque V ou F para as afirmaes abaixo: a) [F ] Um componente do tipo jLabel utilizado para exibir uma lista de dados; b) [V] Um componente do tipo jTextField utilizado para obter uma entrada de dados do usurio; c) [F] A propriedade Text est relacionada posio do Componente da Tela; d) [V] Horizontal e Vertical Size so propriedades relacionadas Altura e Largura de um objeto; e) [F] A propriedade icon utilizada para definir um nome do Componente; f) [ ] A propriedade mnemonic utilizada para definir um atalho de tela para o componente; g) [V] Um componente jComboBox utilizado para apresentar uma Lista para seleo; h) [ ]A propriedade name serve como uma apelido para um componente.

    Questo 13) Marque a opo correta: Cdigo para fechar uma aplicao Java: a) [ ] System.out; b) [ X ] System.exit(0); c) [ ] System.close(); d)[ ] System.end(); Questo 14) Assumindo a definio dos componentes jComboBox e jButton, crie um cdigo de programao para o jButton TESTE de forma que seja exibida uma mensagem com o dia da semana selecionado.

    package Teste;

    import javax.swing.JOptionPane;

  • MINISTRIO DA EDUCAO

    UNIVERSIDADE FEDERAL DOS VALES DO JEQUITINHONHA E MUCURI CAMPUS AVANADO DO MUCURI TEFILO OTONI - MG

    BACHARELADO EM CINCIA E TECNOLOGIA www.ufvjm.edu.br [email protected]

    Aluno: Rogrio Fonseca Santos - Algoritmo e Programao

    /**

    *

    * @author Rogrio

    */

    public class Questo14 extends javax.swing.JFrame {

    public Questo14() {

    initComponents();

    }

    private void jButton1ActionPerformed(java.awt.event.ActionEvent

    evt) {

    String dia = (String)Combo.getSelectedItem();

    JOptionPane.showMessageDialog(null, dia);

    }

    public static void main(String args[]) {

    java.awt.EventQueue.invokeLater(new Runnable() {

    public void run() {

    new Questo14().setVisible(true);

    }

    });

    }

    private javax.swing.JComboBox Combo;

    private javax.swing.JButton jButton1;

    private javax.swing.JPanel jPanel1;

    }

    Questo 15) Elabore um Formulrio para a interface abaixo e quando pressionado o Boto Processamento mostre as informaes utilizando a classe Ola.

  • MINISTRIO DA EDUCAO

    UNIVERSIDADE FEDERAL DOS VALES DO JEQUITINHONHA E MUCURI CAMPUS AVANADO DO MUCURI TEFILO OTONI - MG

    BACHARELADO EM CINCIA E TECNOLOGIA www.ufvjm.edu.br [email protected]

    Aluno: Rogrio Fonseca Santos - Algoritmo e Programao

    package Teste;

    /**

    *

    * @author Rogrio

    */

    public class Questo15 extends javax.swing.JFrame {

    Ola ol = new Ola();

    public Questo15() {

    initComponents();

    }

    private void jButton1ActionPerformed(java.awt.event.ActionEvent

    evt) {

    String nome = Nome.getText();

    ol.show(nome);

    String idade = Idade.getText();

    ol.show(idade);

    if(CorAzul.isSelected())

    ol.show("Azul");

    else

    ol.show("Verde");

    String cidade = (String)Combo.getSelectedItem();

    ol.show(cidade);

    if(SexoM.isSelected())

    ol.show("Masculino");

    else

    ol.show("Feminino");

  • MINISTRIO DA EDUCAO

    UNIVERSIDADE FEDERAL DOS VALES DO JEQUITINHONHA E MUCURI CAMPUS AVANADO DO MUCURI TEFILO OTONI - MG

    BACHARELADO EM CINCIA E TECNOLOGIA www.ufvjm.edu.br [email protected]

    Aluno: Rogrio Fonseca Santos - Algoritmo e Programao

    }

    public static void main(String args[]) {

    java.awt.EventQueue.invokeLater(new Runnable() {

    public void run() {

    new Questo15().setVisible(true);

    }

    });

    }

    private javax.swing.JComboBox Combo;

    private javax.swing.JCheckBox CorAzul;

    private javax.swing.JCheckBox CorVerde;

    private javax.swing.JTextField Idade;

    private javax.swing.JTextField Nome;

    private javax.swing.JRadioButton SexoM;

    private javax.swing.ButtonGroup buttonGroup1;

    private javax.swing.ButtonGroup buttonGroup2;

    private javax.swing.JButton jButton1;

    private javax.swing.JLabel jLabel1;

    private javax.swing.JLabel jLabel2;

    private javax.swing.JLabel jLabel3;

    private javax.swing.JLabel jLabel4;

    private javax.swing.JLabel jLabel5;

    private javax.swing.JPanel jPanel1;

    private javax.swing.JRadioButton jRadioButton2;

    }

    Questo 16) Dado o cdigo abaixo complete as lacunas public class Exemplo2 {

    public static void main(String args[ ]){

    String s = JOptionPane. showInputDialog (digite um num); int x = Integer.parseInt(s);

    for(int i=0 ; i < x ;i++ ){

    System.out.Println(i);

    i+=2;

    } } }

    Questo 17) Dado o cdigo abaixo complete as lacunas public class Exemplo2 {

    public static void main(String args[ ]){

    Janela ja = new Janela();

  • MINISTRIO DA EDUCAO

    UNIVERSIDADE FEDERAL DOS VALES DO JEQUITINHONHA E MUCURI CAMPUS AVANADO DO MUCURI TEFILO OTONI - MG

    BACHARELADO EM CINCIA E TECNOLOGIA www.ufvjm.edu.br [email protected]

    Aluno: Rogrio Fonseca Santos - Algoritmo e Programao

    ja.setVisible( true);

    }

    }

    Questo 18) Qual o resultado quando voc compilar e executar o cdigo abaixo? public class teste {

    public int misterio(int x) {

    int a=1;

    for( int i=3; i < x ; i++)

    for(int k=2; k > 1; k--)

    a+=i+k;

    return(a);

    }

    }

    public class teste1 {

    public static void main (String[] args) {

    teste te = new teste();

    int re = te.misterio(4);

    System.out.println("Resultado = "+re);

    }

    }

    Resultado = 6

    Questo 19) Elabore uma aplicao Jogo da Velha conforme figura abaixo.

    package Teste;

    import javax.swing.JOptionPane;

    /**

    *

    * @author Rogrio

    */

    public class Velha extends javax.swing.JFrame {

    boolean jogador1 = true, jogador2 = false;

    int jogO = 0, jogX=0, emp=0;

    public Velha() {

    initComponents();

    }

    void jogadorativo(){

    if(jogador1==true){

    jogador1=false;

  • MINISTRIO DA EDUCAO

    UNIVERSIDADE FEDERAL DOS VALES DO JEQUITINHONHA E MUCURI CAMPUS AVANADO DO MUCURI TEFILO OTONI - MG

    BACHARELADO EM CINCIA E TECNOLOGIA www.ufvjm.edu.br [email protected]

    Aluno: Rogrio Fonseca Santos - Algoritmo e Programao

    jogador2=true;

    }

    else

    {

    jogador1=true;

    jogador2=false;

    }

    vencedor("X");

    vencedor("O");

    }

    public void vencedor(String simbol){

    if((B11.getText().equals(simbol))&&(B12.getText().equals(simbol))&&

    (B13.getText().equals(simbol)))

    {

    if(B11.getText().equals("X"))

    winner("X");

    else

    winner("O");

    }

    if((B21.getText().equals(simbol))&&(B22.getText().equals(simbol))&&

    (B23.getText().equals(simbol)))

    {

    if(B21.getText().equals("X"))

    winner("X");

    else

    winner("O");

    }

    if((B31.getText().equals(simbol))&&(B32.getText().equals(simbol))&&

    (B33.getText().equals(simbol)))

    {

    if(B31.getText().equals("X"))

    winner("X");

    else

    winner("O");

    }

    if((B11.getText().equals(simbol))&&(B21.getText().equals(simbol))&&

    (B31.getText().equals(simbol)))

    {

    if(B11.getText().equals("X"))

    winner("X");

    else

    winner("O");

  • MINISTRIO DA EDUCAO

    UNIVERSIDADE FEDERAL DOS VALES DO JEQUITINHONHA E MUCURI CAMPUS AVANADO DO MUCURI TEFILO OTONI - MG

    BACHARELADO EM CINCIA E TECNOLOGIA www.ufvjm.edu.br [email protected]

    Aluno: Rogrio Fonseca Santos - Algoritmo e Programao

    }

    if((B12.getText().equals(simbol))&&(B22.getText().equals(simbol))&&

    (B32.getText().equals(simbol)))

    {

    if(B12.getText().equals("X"))

    winner("X");

    else

    winner("O");

    }

    if((B13.getText().equals(simbol))&&(B23.getText().equals(simbol))&&

    (B33.getText().equals(simbol)))

    {

    if(B13.getText().equals("X"))

    winner("X");

    else

    winner("O");

    }

    if((B11.getText().equals(simbol))&&(B22.getText().equals(simbol))&&

    (B33.getText().equals(simbol)))

    {

    if(B11.getText().equals("X"))

    winner("X");

    else

    winner("O");

    }

    if((B13.getText().equals(simbol))&&(B22.getText().equals(simbol))&&

    (B31.getText().equals(simbol)))

    {

    if(B13.getText().equals("X"))

    winner("X");

    else

    winner("O");

    }

    }

    public void winner(String venc){

    if(venc.equals("X"))

    {JOptionPane.showMessageDialog(null, "Parabns 'X', voc

    venceu!");

    jogX++;

    String v1 = Integer.toString(jogX);

    Vitx.setText(v1);

    limpa();

    }

    else

  • MINISTRIO DA EDUCAO

    UNIVERSIDADE FEDERAL DOS VALES DO JEQUITINHONHA E MUCURI CAMPUS AVANADO DO MUCURI TEFILO OTONI - MG

    BACHARELADO EM CINCIA E TECNOLOGIA www.ufvjm.edu.br [email protected]

    Aluno: Rogrio Fonseca Santos - Algoritmo e Programao

    {JOptionPane.showMessageDialog(null, "Parabns 'O', voc

    venceu!");

    jogO++;

    String v2 = Integer.toString(jogO);

    Vit0.setText(v2);

    limpa();

    }

    }

    private void B11ActionPerformed(java.awt.event.ActionEvent evt)

    {

    if(jogador1==true){

    switch (B11.getText()) {

    case "":

    B11.setText("X");

    jogadorativo();

    break;}}

    else{

    switch(B11.getText()){

    case "":

    B11.setText("O");

    jogadorativo();

    break;

    }

    }

    }

    private void VitxActionPerformed(java.awt.event.ActionEvent

    evt) { }

    private void Vit0ActionPerformed(java.awt.event.ActionEvent

    evt) { }

    private void ResEmpActionPerformed(java.awt.event.ActionEvent

    evt) { }

    private void B12ActionPerformed(java.awt.event.ActionEvent evt)

    {

    if(jogador1==true){

    switch (B12.getText()) {

    case "":

    B12.setText("X");

    jogadorativo();

    break;

    }}

    else

    {

    switch (B12.getText()) {

    case "":

    B12.setText("O");

    jogadorativo();

    break;

    }

    }

    }

  • MINISTRIO DA EDUCAO

    UNIVERSIDADE FEDERAL DOS VALES DO JEQUITINHONHA E MUCURI CAMPUS AVANADO DO MUCURI TEFILO OTONI - MG

    BACHARELADO EM CINCIA E TECNOLOGIA www.ufvjm.edu.br [email protected]

    Aluno: Rogrio Fonseca Santos - Algoritmo e Programao

    private void B13ActionPerformed(java.awt.event.ActionEvent evt)

    { if(jogador1==true){

    switch (B13.getText()) {

    case "":

    B13.setText("X");

    jogadorativo();

    break;

    }}

    else

    {

    switch (B13.getText()) {

    case "":

    B13.setText("O");

    jogadorativo();

    break;

    }

    } // TODO add your handling code here:

    }

    private void B21ActionPerformed(java.awt.event.ActionEvent evt)

    {

    if(jogador1==true){

    switch (B21.getText()) {

    case "":

    B21.setText("X");

    jogadorativo();

    break;

    }}

    else

    {

    switch (B21.getText()) {

    case "":

    B21.setText("O");

    jogadorativo();

    break;

    }

    }

    }

    private void B22ActionPerformed(java.awt.event.ActionEvent evt)

    { if(jogador1==true){

    switch (B22.getText()) {

    case "":

    B22.setText("X");

    jogadorativo();

    break;

    }}

    else

    {

    switch (B22.getText()) {

    case "":

    B22.setText("O");

    jogadorativo();

    break;

  • MINISTRIO DA EDUCAO

    UNIVERSIDADE FEDERAL DOS VALES DO JEQUITINHONHA E MUCURI CAMPUS AVANADO DO MUCURI TEFILO OTONI - MG

    BACHARELADO EM CINCIA E TECNOLOGIA www.ufvjm.edu.br [email protected]

    Aluno: Rogrio Fonseca Santos - Algoritmo e Programao

    }

    }

    }

    private void B23ActionPerformed(java.awt.event.ActionEvent evt)

    {

    if(jogador1==true){

    switch (B23.getText()) {

    case "":

    B23.setText("X");

    jogadorativo();

    break;

    }}

    else

    {

    switch (B23.getText()) {

    case "":

    B23.setText("O");

    jogadorativo();

    break;

    }

    }

    }

    private void B31ActionPerformed(java.awt.event.ActionEvent evt)

    { if(jogador1==true){

    switch (B31.getText()) {

    case "":

    B31.setText("X");

    jogadorativo();

    break;

    }}

    else

    {

    switch (B31.getText()) {

    case "":

    B31.setText("O");

    jogadorativo();

    break;

    }

    }

    }

    private void B32ActionPerformed(java.awt.event.ActionEvent evt)

    { if(jogador1==true){

    switch (B32.getText()) {

    case "":

    B32.setText("X");

    jogadorativo();

    break;

    }}

    else

    {

    switch (B32.getText()) {

  • MINISTRIO DA EDUCAO

    UNIVERSIDADE FEDERAL DOS VALES DO JEQUITINHONHA E MUCURI CAMPUS AVANADO DO MUCURI TEFILO OTONI - MG

    BACHARELADO EM CINCIA E TECNOLOGIA www.ufvjm.edu.br [email protected]

    Aluno: Rogrio Fonseca Santos - Algoritmo e Programao

    case "":

    B32.setText("O");

    jogadorativo();

    break;

    }

    } }

    private void B33ActionPerformed(java.awt.event.ActionEvent evt)

    {

    if(jogador1==true){

    switch (B33.getText()) {

    case "":

    B33.setText("X");

    jogadorativo();

    break;

    }}

    else

    {

    switch (B33.getText()) {

    case "":

    B33.setText("O");

    jogadorativo();

    break;

    }

    }

    }

    private void NovoActionPerformed(java.awt.event.ActionEvent

    evt) {

    limpa();

    emp++;

    String v = Integer.toString(emp);

    ResEmp.setText(v);

    }

    private void jButton1ActionPerformed(java.awt.event.ActionEvent

    evt) {

    System.exit(0);

    }

    public void limpa(){

    B11.setText("");

    B12.setText("");

    B13.setText("");

    B21.setText("");

    B22.setText("");

    B23.setText("");

    B31.setText("");

    B32.setText("");

    B33.setText("");

    }

  • MINISTRIO DA EDUCAO

    UNIVERSIDADE FEDERAL DOS VALES DO JEQUITINHONHA E MUCURI CAMPUS AVANADO DO MUCURI TEFILO OTONI - MG

    BACHARELADO EM CINCIA E TECNOLOGIA www.ufvjm.edu.br [email protected]

    Aluno: Rogrio Fonseca Santos - Algoritmo e Programao

    public static void main(String args[]) {

    java.awt.EventQueue.invokeLater(new Runnable() {

    public void run() {

    new Velha().setVisible(true);

    }

    });

    }

    private javax.swing.JButton B11;

    private javax.swing.JButton B12;

    private javax.swing.JButton B13;

    private javax.swing.JButton B21;

    private javax.swing.JButton B22;

    private javax.swing.JButton B23;

    private javax.swing.JButton B31;

    private javax.swing.JButton B32;

    private javax.swing.JButton B33;

    private javax.swing.JButton Novo;

    private javax.swing.JTextField ResEmp;

    private javax.swing.JTextField Vit0;

    private javax.swing.JTextField Vitx;

    private javax.swing.JButton jButton1;

    private javax.swing.JLabel jLabel1;

    private javax.swing.JLabel jLabel2;

    private javax.swing.JLabel jLabel3;

    private javax.swing.JPanel jPanel1;

    private javax.swing.JPanel jPanel3;

    }