Ajuda com questão de programação em java com interface grafica!

1 resposta
P

[img]http://i.imgur.com/LF8u4sB.jpg[/img]

[img]http://i.imgur.com/ksQZ5jZ.jpg[/img]

Gostaria da ajuda de vocês para resolver essa questão...Eu fiz uma parte dela e vou estar colocando abaixo porque não to conseguindo finalizar esse trabalho de jeito nenhum.

Classe aluno

package janela;


public class Aluno {
    private int matricula;
    private String nome;
    private char sexo;
    private int idade;        
    private String nomeCurso;
    private float notaAv1;
    private float notaAv2;
    private float notaAv3;
    private float media;
    
     Endereco endereco = new Endereco();
    
     private Aluno() {
    }
    
    private Aluno(int matricula, String nome) {
        this.matricula = matricula;
        this.nome = nome;
    }
    
    private Aluno(int idade, char sexo) {
        this.idade = idade;
        this.sexo = sexo;
    }
    
    private void media(float media){  
        media=((notaAv1+notaAv2+notaAv3)/3);  
    } 
    
     private int getMatricula(){
        return matricula;
    }
     private String getNome(){
         return this.nome;
     }
    private char getSexo(){
        return this.sexo;
    }
    private int getIdade(){
        return this.idade;
    }
    private String getNomecurso(){
        return this.nomeCurso;
    }
    private float getNotaav1(){
        return this.notaAv1;
    }
    private float getNotaav2(){
        return this.notaAv2;
    }
    private float getNotaav3(){
        return this.notaAv3;
    }
    private void setMatricula(int matricula){
        this.matricula = matricula;
    }
    private void setNome(String nome){
        this.nome = nome;
    }
    private void setSexo(char sexo){
        this.sexo = sexo;
    }
    private void setIdade(int idade){
        this.idade = idade;
    }
    private void setNomecurso(String nomeCurso){
        this.nomeCurso = nomeCurso;
    }
    private void setNotaav1(float notaAv1){
        this.notaAv1 = notaAv1;
    }
    private void setNotaav2(float notaAv2){
        this.notaAv2 = notaAv2;
    }
    private void setNotaav3(float notaAv3){
        this.notaAv3 = notaAv3;
    }
    
    
}
Numero maior
        int a;  
        int b;  
        int c;  
        int d;  
        int e;  

        int maior (int a, int b, int c, int d, int e){
              if (a > b | a > c | a > d | a > e) { // "a" maior que todos
              
              System.out.printf ("Este e o maior deles: %d\n", a); 

              return 0;
}

Esse finalzinho do numero maior é apenas um exemplo de como achar o maior deles...gostaria de saber onde preciso encaixa-lo da forma que está pedindo no exercicio.

Classe endereço

package janela;

            
           
public class Endereco {
    
    private String tipoLogradouro,
            numero,
            complemento,
            bairro,
            cidade,
            estado;
    
    private Endereco(String Tl, String N, 
            String Co, String B, 
            String Ci, String E){
        
        this.tipoLogradouro = Tl;
        this.numero = N;
        this.complemento = Co;
        this.bairro = B;
        this.cidade = Ci;
        this.estado = E;
    }

    Endereco() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
     
    private String getTipoLogradouro(){
        return this.tipoLogradouro;
    }
    private String getNumero(){
        return this.numero;
    }
    private String getComplemento(){
        return this.complemento;
    }
    private String getBairro(){
        return this.bairro;
    }
    private String getCidade(){
        return this.cidade;
    }
    private String getEstado(){
        return this.cidade;
    }
    
    private void setTipoLogradouro(String Tl){
        this.tipoLogradouro=Tl;
    }
    private void setNumero(String N){
        this.numero=N;
    }
    private void setComplemento(String Co){
        this.complemento=Co;
    }
    private void setBairro(String B){
        this.bairro=B;
    }
    private void setCidade(String Ci){
        this.cidade=Ci;
    }
    private void setEstado(String E){
        this.estado=E;
    }
   
}

Um exemplo de janela

package janela;


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Janela extends JFrame
   implements ActionListener
{
    JLabel Lb1 = new JLabel("Janela de teste, verificar o título.");
    JButton B1=new JButton("Voltar");
    
    public Janela(String texto){
    	 super(texto);// Recebe o título da janela.
         Container c = getContentPane();
         c.setLayout(new FlowLayout());
         c.add(Lb1);
         c.add(B1);
	 B1.addActionListener(this);
	 setSize( 450, 150 );
         setVisible( true );
    }
    @Override
    public void actionPerformed(ActionEvent evt)
    {   Object obj=evt.getSource();
         if(obj==B1)
           {
                this.dispose();//fecha a janela.
           }
    }
}

Um exemplo de menu

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package janela;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Menu extends JFrame implements ActionListener {
    		JMenuBar barraMenu = new JMenuBar();//Objeto Menu
                //Opção Arquivo e suas 3 subopções
                JMenu op1 = new JMenu("Arquivo");
    		JMenuItem op1sub1 = new JMenuItem("Maior de 5 números");
                JMenuItem op1sub2 = new JMenuItem("Situação do aluno");
                JMenuItem op1sub3 = new JMenuItem("IMC");
                //Opção Cadastro e suas 2 subopções
                JMenu op2 = new JMenu("Cadastro");
                JMenuItem op2sub1 = new JMenuItem("Aluno");
                JMenuItem op2sub2 = new JMenuItem("Endereço");
                //Opção de Saída
                JMenu op3 = new JMenu("Sair");
                JMenuItem op3sub1 = new JMenuItem("Sair");
	public Menu()
	{
                //Construtor 
		super("Janela de 5 numeros");// Menu da janela
		op1.setMnemonic('A');// define a tecla de atalho da opção do menu
		op1sub1.setMnemonic('1');// define a tecla de atalho da subopção
		op1.add(op1sub1);// adiciona a subopção a sua devida opção
		op1sub2.setMnemonic('2');
		op1.add(op1sub2);	
		op1sub3.setMnemonic('3');
		op1.add(op1sub3);
		op2.setMnemonic('C');
		op2sub1.setMnemonic('1');
		op2.add(op2sub1);
		op2sub2.setMnemonic('2');
		op2.add(op2sub2);	
		op3.setMnemonic('S');
		op3sub1.setMnemonic('S');
		op3.add(op3sub1);
        
		setJMenuBar(barraMenu);//define a barra de menu
		barraMenu.add(op1);// adiciona as opções ao menu
                barraMenu.add(op2);
                barraMenu.add(op3);
		// adiciona ao Listener os objetos que terão tratamento de eventos.
                op1sub1.addActionListener(this);
                op1sub2.addActionListener(this);
                op1sub3.addActionListener(this);
                op2sub1.addActionListener(this);
                op2sub2.addActionListener(this);
                op3sub1.addActionListener(this);
		getContentPane();
		setSize(200, 200);
		setVisible(true);
	}
    @Override
        public void actionPerformed(ActionEvent e) { 
            Object obj=e.getSource();
            //Trata o evento por objeto, usa sempre a mesma janela, mas define o título da janela através do construtor.
            if(obj == op1sub1){
                Janela j = new Janela("Menu Arquivo Opção 1");
                j.setVisible(true);
            }
            if(obj == op1sub2){
                Janela j = new Janela("Menu Arquivo Opção 2");
                j.setVisible(true);
            }
            if(obj == op1sub3){
                Janela j = new Janela("Menu Arquivo Opção 3");
                j.setVisible(true);
            }
            if(obj == op2sub1){
                Janela j = new Janela("Menu Cadastro Opção 1");
                j.setVisible(true);
            }
            if(obj == op2sub2){
                Janela j = new Janela("Menu Cadastro Opção 2");
                j.setVisible(true);
            }
            if(obj == op3sub1){
                System.exit(0);
            }
        }
	public static void main(String[] args)
	{
                //cria a aplicação
		Menu app = new Menu();
		app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
}

E um exemplo de uma janela que eu fiz...só que não sei como colocar ela no meu menu e gostaria de qualquer dica caso a minha esteja errada.

package janela;  
  
import java.awt.FlowLayout;  
import java.awt.GridLayout;  
import java.awt.event.ActionEvent;  
import java.awt.event.ActionListener;  
  
import javax.swing.JButton;  
import javax.swing.JFrame;  
import javax.swing.JLabel;  
import javax.swing.JPanel;  
import javax.swing.JTextField;  
  
 
public class Media extends JFrame implements ActionListener{  
      
    private JLabel lblNome, lblN1, lblN2,lblN3 , lblMedia;  
    private JTextField txtNome, txtN1, txtN2, txtN3 , txtMedia;  
    private JButton btOK, btLimpa;  
    private JPanel painel;  
      
    private Aluno al;  
//---------------------------------------------------------------------------------------------   
    public Media(){  
        lblNome = new JLabel("Nome: ");  
        lblN1 = new JLabel("1ª Nota: ");  
        lblN2 = new JLabel("2ª Nota: ");
        lblN3 = new Jlabel("3º Nota: ");
        lblMedia = new JLabel("Media: ");  
        txtNome = new JTextField(30);  
        txtN1 = new JTextField(4);  
        txtN2 = new JTextField(4);
        txtN3 = new JtextField(4);
        txtMedia = new JTextField(10);  
        txtMedia.setEditable(false);      
          
        btOK = new JButton("OK");  
        btOK.addActionListener(this);  
        btLimpa = new JButton("Limpar");  
        btLimpa.addActionListener(this);  
        painel = new JPanel();  
      
        setTitle("Cadastro de Alunos");  
        painel.setLayout(new GridLayout(10,2));  
        setLocation(400,300);  
        setSize(150,200);  
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
          
         
        painel.add(lblNome);  
        painel.add(txtNome);  
          
          
        painel.add(lblN1);  
        painel.add(txtN1);  
          
        painel.add(lblN2);  
        painel.add(txtN2);  
        
        painel.add(lblN3);  
        painel.add(txtN3); 
          
        painel.add(lblMedia);  
        painel.add(txtMedia);  
          
        painel.add(btOK);  
        painel.add(btLimpa);  
        add(painel);  
        pack();  
    }     
     
    public void actionPerformed(ActionEvent aplica){  
        double a,b,c;  
        if (aplica.getSource()==btOK){  
                al.setNome(txtNome.getText());  
                al.getMedia(txtN1.getText().txtN2.getText());  
                  
                a= Double.valueOf(txtN1.getText()).doubleValue();  
                b= Double.valueOf(txtN2.getText()).doubleValue(); 
                c= Double.valueOf(txtN3.getText()).doubleValue(); 
                  
                txtMedia.setText(floatvalueOf(a));   
  
            }  
            if(aplica.getSource()==btLimpa){  
                txtNome.setText("");  
                txtN1.setText("");  
                txtN2.setText("");
                txtN3.setText(""); 
                  
            }             
    }  
  
        public void setAluno(Aluno al){     // Liga a classe aluno nesta classe  
        this.al = al;  
    }  
}

Um grande abraço a todos e espero que alguem possa me ajudar a solucionar esse caso :-D

1 Resposta

P

Se alguem puder me dizer como faço para colocar as janelas no menu e alguem me mostrasse algum exemplo de janela feita eu já conseguria fazer o resto. Isso deve facilitar a alguem me ajudar e não ter tanto trabalho.

Criado 7 de junho de 2013
Ultima resposta 7 de jun. de 2013
Respostas 1
Participantes 1