Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
eu só to querendo cadastrar listar e pesquisar mas n ta dando....sempre da erro
package sistema2;
public class Parte1 {
private String modelo;
private String cor;
private double valor;
private double imposto;
private String pesquisar;
public String getModelo() {
return modelo;
} this.modelo = modelo;
} return cor;
} this.cor = cor;
} return valor;
} this.valor = valor;
} return imposto;
} this.imposto = imposto;
}
}
package sistema2;
public class Elemento {
Parte1 objeto;
int proximo;
}
package sistema2;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Scanner;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class Lista implements ActionListener{
Scanner enter = new Scanner(System.in);
Elemento[] vetor;
int disponivel;
int primeiro;
int cont=0;
JFrame tela = new JFrame();
JPanel painel = new JPanel();
JFrame tela1 = new JFrame();
JPanel painel1 = new JPanel();
JFrame tela2 = new JFrame();
JPanel painel2 = new JPanel();
JLabel lbmodelo = new JLabel("Modelo");
JLabel lbcor = new JLabel("Cor");
JLabel lbvalor = new JLabel("Valor");
JLabel lbimposto = new JLabel("Imposto");
JLabel lbpesquisar = new JLabel("Pesquisar");
JTextField txtmodelo = new JTextField();
JTextField txtcor = new JTextField();
JTextField txtvalor = new JTextField();
JTextField txtimposto = new JTextField();
JTextField txtpesquisar = new JTextField();
JLabel lbarea = new JLabel("Listando Informações");
JTextArea txtarea = new JTextArea();
JButton btnsalvar = new JButton("Salvar");
JButton btnpesquisar = new JButton("Pesquisar");
JButton btnfechar = new JButton("Fechar");
JButton btnfechar1 = new JButton("Fechar Lista");
JButton btnfechar2 = new JButton("Fechar pesquisar");
public void criarTela(){
tela.setSize(380, 320);
tela.setLocation(300, 250);
tela.setTitle("Cadastrando Carros - Tai1");
tela.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
painel.setLayout(null);
//nomes
lbmodelo.setBounds(30, 10, 80, 20);
lbcor.setBounds(30, 40, 80, 20);
lbvalor.setBounds(30, 70, 80, 20);
lbimposto.setBounds(30, 100, 80, 20);
//caixa texto
txtmodelo.setBounds(110, 10, 80, 20);
txtcor.setBounds(110, 40, 80, 20);
txtvalor.setBounds(110, 70, 80, 20);
txtimposto.setBounds(110, 100, 80, 20);
txtimposto.enable(false);
//botoes
btnsalvar.setBounds(60, 220, 80, 20);
btnsalvar.addActionListener(this);
ImageIcon img = new ImageIcon("d:\\sair1.jpg");
btnfechar = new JButton (img);
btnfechar.setBounds(160, 220, 80, 20);
btnfechar.addActionListener(this);
painel.add(lbmodelo);
painel.add(lbcor);
painel.add(lbvalor);
painel.add(lbimposto);
painel.add(txtmodelo);
painel.add(txtcor);
painel.add(txtvalor);
painel.add(txtimposto);
painel.add(btnsalvar);
painel.add(btnfechar);
tela.getContentPane().add(painel);
tela.setVisible(true);
}
public void criarTelaListar(){
tela1.setSize(380, 320);
tela1.setLocation(300, 250);
tela1.setTitle("Listando Carros - Tai1");
tela1.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
painel1.setLayout(null);
//nomes
lbarea.setBounds(30, 30, 100, 150);
txtarea.setBounds(30, 30, 200, 300);
//botoes
listar();
btnfechar1.setBounds(160, 220, 80, 20);
btnfechar1.addActionListener(this);
painel1.add(lbarea);
painel1.add(txtarea);
painel1.add(btnfechar1);
tela1.getContentPane().add(painel1);
tela1.setVisible(true);
}
public void criarPesquisa(){
tela2.setSize(600, 550);
tela2.setLocation(300, 250);
tela2.setTitle("pesquisa - Tai1");
tela2.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
painel2.setLayout(null);
//nomes
lbpesquisar.setBounds(30, 10, 80, 20);
txtpesquisar.setBounds(110, 10, 80, 20);
lbarea.setBounds(50, 50, 150, 20);
txtarea.setBounds(50, 50, 200, 200);
//botoes
listar();
btnfechar2.setBounds(360, 220, 200, 20);
btnfechar2.addActionListener(this);
btnpesquisar.setBounds(360, 250,150, 20);
btnpesquisar.addActionListener(this);
painel2.add(lbarea);
painel2.add(txtarea);
painel2.add(lbpesquisar);
painel2.add(txtpesquisar);
painel2.add(btnpesquisar);
painel2.add(btnfechar2);
tela2.getContentPane().add(painel2);
tela2.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==btnsalvar){
inserir();
}
if(e.getSource()==btnfechar){
tela.dispose();
}
if (e.getSource()==btnfechar1){
tela1.dispose();
}
if (e.getSource()==btnfechar2){
tela2.dispose();
}
if (e.getSource()==btnpesquisar){
pesquisar();
}
}
void criarLista(){
vetor = new Elemento[5];
disponivel=0;
primeiro=5;
for(int i=0; i<5; i++){
vetor[i] = new Elemento();
vetor[i].objeto = new Parte1();
vetor[i].proximo=i+1;
}//for
}//criarLista
void inserir(){
if(disponivel!=5){
if(primeiro==5){
primeiro=disponivel;
}
int posicao=disponivel;
vetor[posicao].objeto.setModelo(txtmodelo.getText());
vetor[posicao].objeto.setCor(txtcor.getText());
if(vetor[posicao].objeto.getValor()>30000){
vetor[posicao].objeto.setImposto(
vetor[posicao].objeto.getValor()*6/100);
}else{
vetor[posicao].objeto.setImposto(
vetor[posicao].objeto.getValor()*4/100);
}
txtimposto.setText(String.valueOf(
vetor[posicao].objeto.getImposto()));
cont++;
disponivel=vetor[posicao].proximo;
JOptionPane.showMessageDialog(null, "Cadastrou massa");
}else{
JOptionPane.showMessageDialog(null, "Lista Cheia");
}
}
void listar(){
if(cont==0){
JOptionPane.showMessageDialog(null, "Lista vazia");
}else{
int posicao=primeiro;
for(int i=0; i<cont; i++){
txtarea.setText("\n"+txtarea.getText()+
"\nO modelo do carro é: "
+vetor[posicao].objeto.getModelo()
+"\n A cor é: "
+vetor[posicao].objeto.getCor()
+"\nO valor é: R$ "
+vetor[posicao].objeto.getValor()
+"\nO valor do imposto é: R$ "
+vetor[posicao].objeto.getImposto());
posicao=vetor[posicao].proximo;
}
}
}
void pesquisar (){
int x = 0;
int posicao=disponivel;
JOptionPane.showMessageDialog(null, "##Pesquisando##");
String pes = null;
pes = JOptionPane.showInputDialog(null, "Digite o nome para pesquisa");
boolean achou = false;
if (cont==0){
JOptionPane.showMessageDialog(null, "Lista está vazia!!");
}else{
if (vetor[posicao].objeto.getModelo().equals(pes)){
for (int i = 0 ; i <cont ; i++){
achou = true;
JOptionPane.showMessageDialog(null, "AKi o resultado"+vetor[i].objeto.getModelo());
txtarea.setText("\n"+txtarea.getText()+
"\nO modelo do carro é: "
+vetor[i].objeto.getModelo()
+"\n A cor é: "
+vetor[i].objeto.getCor()
+"\nO valor é: R$ "
+vetor[i].objeto.getValor()
+"\nO valor do imposto é: R$ "
+vetor[i].objeto.getImposto());
}//if
posicao=vetor[posicao].proximo;
}//for
if (achou==false){
JOptionPane.showMessageDialog(null, "O modelo nunca foi cadastrado!!");
}
}//else
}
}
package sistema2;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Scanner;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class Lista implements ActionListener{
Scanner enter = new Scanner(System.in);
Elemento[] vetor;
int disponivel;
int primeiro;
int cont=0;
JFrame tela = new JFrame();
JPanel painel = new JPanel();
JFrame tela1 = new JFrame();
JPanel painel1 = new JPanel();
JFrame tela2 = new JFrame();
JPanel painel2 = new JPanel();
JLabel lbmodelo = new JLabel("Modelo");
JLabel lbcor = new JLabel("Cor");
JLabel lbvalor = new JLabel("Valor");
JLabel lbimposto = new JLabel("Imposto");
JLabel lbpesquisar = new JLabel("Pesquisar");
JTextField txtmodelo = new JTextField();
JTextField txtcor = new JTextField();
JTextField txtvalor = new JTextField();
JTextField txtimposto = new JTextField();
JTextField txtpesquisar = new JTextField();
JLabel lbarea = new JLabel("Listando Informações");
JTextArea txtarea = new JTextArea();
JButton btnsalvar = new JButton("Salvar");
JButton btnpesquisar = new JButton("Pesquisar");
JButton btnfechar = new JButton("Fechar");
JButton btnfechar1 = new JButton("Fechar Lista");
JButton btnfechar2 = new JButton("Fechar pesquisar");
public void criarTela(){
tela.setSize(380, 320);
tela.setLocation(300, 250);
tela.setTitle("Cadastrando Carros - Tai1");
tela.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
painel.setLayout(null);
//nomes
lbmodelo.setBounds(30, 10, 80, 20);
lbcor.setBounds(30, 40, 80, 20);
lbvalor.setBounds(30, 70, 80, 20);
lbimposto.setBounds(30, 100, 80, 20);
//caixa texto
txtmodelo.setBounds(110, 10, 80, 20);
txtcor.setBounds(110, 40, 80, 20);
txtvalor.setBounds(110, 70, 80, 20);
txtimposto.setBounds(110, 100, 80, 20);
txtimposto.enable(false);
//botoes
btnsalvar.setBounds(60, 220, 80, 20);
btnsalvar.addActionListener(this);
ImageIcon img = new ImageIcon("d:\\sair1.jpg");
btnfechar = new JButton (img);
btnfechar.setBounds(160, 220, 80, 20);
btnfechar.addActionListener(this);
painel.add(lbmodelo);
painel.add(lbcor);
painel.add(lbvalor);
painel.add(lbimposto);
painel.add(txtmodelo);
painel.add(txtcor);
painel.add(txtvalor);
painel.add(txtimposto);
painel.add(btnsalvar);
painel.add(btnfechar);
tela.getContentPane().add(painel);
tela.setVisible(true);
}
public void criarTelaListar(){
tela1.setSize(380, 320);
tela1.setLocation(300, 250);
tela1.setTitle("Listando Carros - Tai1");
tela1.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
painel1.setLayout(null);
//nomes
lbarea.setBounds(30, 30, 100, 150);
txtarea.setBounds(30, 30, 200, 300);
//botoes
listar();
btnfechar1.setBounds(160, 220, 80, 20);
btnfechar1.addActionListener(this);
painel1.add(lbarea);
painel1.add(txtarea);
painel1.add(btnfechar1);
tela1.getContentPane().add(painel1);
tela1.setVisible(true);
}
public void criarPesquisa(){
tela2.setSize(600, 550);
tela2.setLocation(300, 250);
tela2.setTitle("pesquisa - Tai1");
tela2.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
painel2.setLayout(null);
//nomes
lbpesquisar.setBounds(30, 10, 80, 20);
txtpesquisar.setBounds(110, 10, 80, 20);
lbarea.setBounds(50, 50, 150, 20);
txtarea.setBounds(50, 50, 200, 200);
//botoes
listar();
btnfechar2.setBounds(360, 220, 200, 20);
btnfechar2.addActionListener(this);
btnpesquisar.setBounds(360, 250,150, 20);
btnpesquisar.addActionListener(this);
painel2.add(lbarea);
painel2.add(txtarea);
painel2.add(lbpesquisar);
painel2.add(txtpesquisar);
painel2.add(btnpesquisar);
painel2.add(btnfechar2);
tela2.getContentPane().add(painel2);
tela2.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==btnsalvar){
inserir();
}
if(e.getSource()==btnfechar){
tela.dispose();
}
if (e.getSource()==btnfechar1){
tela1.dispose();
}
if (e.getSource()==btnfechar2){
tela2.dispose();
}
if (e.getSource()==btnpesquisar){
pesquisar();
}
}
void criarLista(){
vetor = new Elemento[5];
disponivel=0;
primeiro=5;
for(int i=0; i<5; i++){
vetor[i] = new Elemento();
vetor[i].objeto = new Parte1();
vetor[i].proximo=i+1;
}//for
}//criarLista
void inserir(){
if(disponivel!=5){
if(primeiro==5){
primeiro=disponivel;
}
int posicao=disponivel;
vetor[posicao].objeto.setModelo(txtmodelo.getText());
vetor[posicao].objeto.setCor(txtcor.getText());
if(vetor[posicao].objeto.getValor()>30000){
vetor[posicao].objeto.setImposto(
vetor[posicao].objeto.getValor()*6/100);
}else{
vetor[posicao].objeto.setImposto(
vetor[posicao].objeto.getValor()*4/100);
}
txtimposto.setText(String.valueOf(
vetor[posicao].objeto.getImposto()));
cont++;
disponivel=vetor[posicao].proximo;
JOptionPane.showMessageDialog(null, "Cadastrou massa");
}else{
JOptionPane.showMessageDialog(null, "Lista Cheia");
}
}
void listar(){
if(cont==0){
JOptionPane.showMessageDialog(null, "Lista vazia");
}else{
int posicao=primeiro;
for(int i=0; i<cont; i++){
txtarea.setText("\n"+txtarea.getText()+
"\nO modelo do carro é: "
+vetor[posicao].objeto.getModelo()
+"\n A cor é: "
+vetor[posicao].objeto.getCor()
+"\nO valor é: R$ "
+vetor[posicao].objeto.getValor()
+"\nO valor do imposto é: R$ "
+vetor[posicao].objeto.getImposto());
posicao=vetor[posicao].proximo;
}
}
}
void pesquisar (){
int x = 0;
int posicao=disponivel;
JOptionPane.showMessageDialog(null, "##Pesquisando##");
String pes = null;
pes = JOptionPane.showInputDialog(null, "Digite o nome para pesquisa");
boolean achou = false;
if (cont==0){
JOptionPane.showMessageDialog(null, "Lista está vazia!!");
}else{
if (vetor[posicao].objeto.getModelo().equals(pes)){
for (int i = 0 ; i <cont ; i++){
achou = true;
JOptionPane.showMessageDialog(null, "AKi o resultado"+vetor[i].objeto.getModelo());
txtarea.setText("\n"+txtarea.getText()+
"\nO modelo do carro é: "
+vetor[i].objeto.getModelo()
+"\n A cor é: "
+vetor[i].objeto.getCor()
+"\nO valor é: R$ "
+vetor[i].objeto.getValor()
+"\nO valor do imposto é: R$ "
+vetor[i].objeto.getImposto());
}//if
posicao=vetor[posicao].proximo;
}//for
if (achou==false){
JOptionPane.showMessageDialog(null, "O modelo nunca foi cadastrado!!");
}
}//else
}
}
package sistema2;
public class Teste {
/**
* @param args
*/
public static void main(String[] args) {
Principal lista = new Principal();
lista.criarJanela();
}
}
eu sei que é grande mas n sei qual é o erro....to desesperado
Carregando comentários...