Ola pessoal estou tentando aprende java heheheh ....
e estou com algumas duvidas....
fiz a tela principal
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class PRINCIPAL extends JFrame{
/*Declarar na área pública a variável que vai receber a barra de menu*/
JMenuBar barra;
JMenu CADASTRO;
/*declara as variáveis que irão receber os itens do menu como*/
JMenuItem cad_clientes,cad_veiculos,cad_mecanicos,cad_pecas;
public PRINCIPAL(){
super("Exemplo de Menus");
Container tela = getContentPane();
tela.setLayout(null);
/*Criar a barra de menus*/
barra = new JMenuBar();
/*Anexam a barra de menus à janela com uma chamada ao método setJMenuBar da classe JFrame (janela): setJMenuBar(barra)*/
setJMenuBar(barra);
/*O menu CADASTRO é criado com a seguinte instrução*/
CADASTRO = new JMenu("CADASTRO");
/*Depois é anexado a barra de menus*/
barra.add(CADASTRO);
cad_clientes = new JMenuItem("CADASTRO DE CLIENTES");
cad_veiculos = new JMenuItem("CADASTRO DE VEICULOS");
cad_mecanicos = new JMenuItem("CADASTO DE MECANICOS");
cad_pecas = new JMenuItem("CADASTRO DE PEÇAS");
/*anexa os itens no menu CADASTRO*/
CADASTRO.add(cad_clientes);
CADASTRO.add(cad_veiculos);
CADASTRO.add(cad_mecanicos);
CADASTRO.add(cad_pecas);
/*PROPRIEDADES DA TELA*/
setSize(800,600);
setLocationRelativeTo(null);
setVisible(true);
}
public static void main (String args[]){
PRINCIPAL app = new PRINCIPAL();
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
e fiz a tela de cadastro
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class TELA1 extends JFrame {
/*CRIANDO OS JLabel*/
JLabel rotulo1,rotulo2,rotulo3,rotulo4,rotulo5,rotulo6,rotulo7,rotulo8,rotulo9,rotulo_obs;
/*CRIANDO OS JTextField*/
JTextField texto1,texto2,texto3,texto4,texto5,texto6,texto7,texto8,texto9;
/*CRIANDO BOTOES*/
JButton botao1,botao2,botao3,botao4;
/*CRIANDO ICONES PARA OS BOTOES*/
ImageIcon icone1,icone2,icone3,icone4;
/*LISTA DO JComboBox*/
JComboBox lista;
String UF[]={"AC","AL","AM","AP","BA","CE","DF","ES","GO","MA","MG","MS","MT","PA","PB","PE","PI","PR","RJ","RN","RO","RR","RS","SC","SE","SP","TO"};
/*ADICIONANDO A LISTA DE VARIAVEIS PUBLICAS O JCombobox*/
JComboBox lista_uf;
/*ADICIONANDO A LISTA DE VARIAVEIS PUBLICAS O JTextArea*/
JTextArea OBS;
public TELA1 (){
super ("..::CADASTRO DE CLIENTES::..");
Container tela = getContentPane();
setLayout (null);
/*CRIANDO O CAMPO TEXTO*/
OBS = new JTextArea(20,30);
/*FPOSICIONANDO O CAMPO OBS*/
OBS.setBounds(30,230,520,80);
/*ADICIOANDO A TELA*/
tela.add(OBS);
/*Jcombobox das UF*/
lista_uf=new JComboBox(UF);
/*DEFININDO SEUS VALORES(JLABEL)*/
rotulo1=new JLabel("CÓDIGO:");
rotulo2=new JLabel("NOME:");
rotulo3=new JLabel("RG:");
rotulo4=new JLabel("CPF:");
rotulo5=new JLabel("RUA:");
rotulo6=new JLabel("NUMERO:");
rotulo7=new JLabel("CIDADE:");
rotulo8=new JLabel("UF:");
rotulo9=new JLabel("TELEFONE:");
rotulo_obs=new JLabel("OBSERVAÇÕES:");
/*POSICIONANDO OS JLABEL*/
rotulo1.setBounds(30,20,80,20);
rotulo2.setBounds(30,40,80,20);
rotulo3.setBounds(30,60,80,20);
rotulo4.setBounds(270,60,80,20);
rotulo5.setBounds(30,100,80,20);
rotulo6.setBounds(30,120,80,20);
rotulo7.setBounds(210,120,80,20);
rotulo8.setBounds(30,160,80,20);
rotulo9.setBounds(30,180,80,20);
rotulo_obs.setBounds(30,200,200,30);
/*imagem.setBounds(400,10,200,220);
/*ADICIONANDO OS JLabel PARA A TELA*/
tela.add(rotulo1);
tela.add(rotulo2);
tela.add(rotulo3);
tela.add(rotulo4);
tela.add(rotulo5);
tela.add(rotulo6);
tela.add(rotulo7);
tela.add(rotulo8);
tela.add(rotulo9);
tela.add(rotulo_obs);
/*tela.add(imagem);*/
/*DEFININDO SEUS TAMANHOS(JTEXTFIELD)*/
texto1=new JTextField(3);
texto2=new JTextField(30);
texto3=new JTextField(10);
texto4=new JTextField(10);
texto5=new JTextField(30);
texto6=new JTextField(5);
texto7=new JTextField(20);
texto8=new JTextField(2);
texto9=new JTextField(10);
/*POSICIONANDO OS JTextField*/
texto1.setBounds(110,20,40,20);
texto2.setBounds(110,40,330,20);
texto3.setBounds(110,60,150,20);
texto4.setBounds(300,60,140,20);
texto5.setBounds(110,100,330,20);
texto6.setBounds(110,120,80,20);
texto7.setBounds(260,120,180,20);
texto9.setBounds(110,180,100,20);
lista_uf.setBounds(110,160,40,20);
/*ADICIONANDO OS JTextLabel PARA A TELA*/
tela.add(texto1);
tela.add(texto2);
tela.add(texto3);
tela.add(texto4);
tela.add(texto5);
tela.add(texto6);
tela.add(texto7);
tela.add(lista_uf);
tela.add(texto9);
/*ICONE DOS BOTOES
icone1=new ImageIcon("C:/Documents and Settings/Pedro/Desktop/JAVA/JCREATOR/adicionar.png");
icone2=new ImageIcon("C:/Documents and Settings/Pedro/Desktop/JAVA/JCREATOR/voltar.png");
icone3=new ImageIcon("C:/Documents and Settings/Pedro/Desktop/JAVA/JCREATOR/procimo.png");
icone4=new ImageIcon("C:/Documents and Settings/Pedro/Desktop/JAVA/JCREATOR/alterar.png");
/*ICONE DA TELA
ImageIcon icone=new ImageIcon("C:/Documents and Settings/Pedro/Desktop/JAVA/JCREATOR/cadastro.png");
ImageIcon icone_cliente=new ImageIcon("C:/Documents and Settings/Pedro/Desktop/JAVA/JCREATOR/user.png");
imagem=new JLabel(icone_cliente);
/*DEFININDO SEUS VALORES(JBUTTON)*/
botao1=new JButton("ADICIONAR",icone1);
botao2=new JButton("ANTERIOR",icone2);
botao3=new JButton("PRÓCIMO",icone3);
botao4=new JButton("ALTERAR",icone4);
/*ADICIONANDO ATALHO AOS BOTOES*/
botao1.setMnemonic(KeyEvent.VK_A);
botao2.setMnemonic(KeyEvent.VK_N);
botao3.setMnemonic(KeyEvent.VK_P);
botao4.setMnemonic(KeyEvent.VK_L);
/*POSICIONANDO OS BOTOES*/
botao1.setBounds(30,330,130,30);
botao2.setBounds(160,330,130,30);
botao3.setBounds(290,330,130,30);
botao4.setBounds(420,330,130,30);
/*ADICIONANDO OS BOTOES PARA A TELA*/
tela.add(botao1);
tela.add(botao2);
tela.add(botao3);
tela.add(botao4);
// Detecta a interação com o item do Botao
botao1.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(null, "CLIENTE ADICIONADO COM SUCESSO!");
}});
botao4.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(null, "CLIENTE ALTERADO COM SUCESSO!");
}});
/*PROPRIEDADES DA TELA*/
/*setIconImage(icone.getImage());*/
setResizable(false); /*NAO DEIXA ALTERAR O TAMANHO DA JANELA*/
setSize (590, 410);
setVisible (true);
setLocationRelativeTo (null); /*APARECER NO CENTRO DA TELA*/
}
public static void main(String args[]){
TELA1 app = new TELA1();
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}}
e agora eu queria q quando desse um click em cadastro>cadastro de cliente (na tela principal)
abric a TELA1 q é o segundo codigo q postei ...
desde ja obrigado ....
e ignorem c tiver alguma anotação errada kkkkk
falow
