Boa Noite Pessoal estou com dificuldades de colocar objetos dentro de um array via interface grafica e tambem estou querendo que os valores retornem double mas so sei usar o parseINT alguem pode me ajudar ?
segue o codigo
//classe do CODIGO
public class SLVeiculos {
String novoOuUsado, novo = "n", usado= "u";
double valorVenda,SomaComissaoVeiculo,valorAcessorio,valorFinanciado,porcentagem,comissaoFinanciamento;
public double comissaoVeiculo (double valorVenda){
this.valorVenda = 0;
this.valorVenda = valorVenda;
this.SomaComissaoVeiculo =0;
if(this.novoOuUsado.equalsIgnoreCase(novo)){
this.SomaComissaoVeiculo = valorVenda * 0.004;
}
if(this.novoOuUsado.equalsIgnoreCase(usado)){
this.SomaComissaoVeiculo = valorVenda * 0.005;
}
/*System.out.println(SomaComissaoVeiculo);*/
return SomaComissaoVeiculo;
}
public double comissaoAcessorio(double valorAcessorio){
this.valorAcessorio =0;
this.valorAcessorio = valorAcessorio * 0.05;
/*System.out.println(this.valorAcessorio);*/
return this.valorAcessorio;
}
public double comissaoFinanciamento(double valorFinanciado, double porcentagem){
this.valorFinanciado =0;
this.porcentagem =0;
this.comissaoFinanciamento =0;
this.porcentagem = porcentagem;
this.valorFinanciado = valorFinanciado;
this.valorFinanciado = valorFinanciado * this.porcentagem;
this.comissaoFinanciamento = this.valorFinanciado * 0.20;
/*System.out.println("Valor Comissao: " + this.comissaoFinanciamento);*/
return comissaoFinanciamento;
}
public String mostra(){
System.out.println("Comissao da Venda do Veiculo: \r \n" + this.SomaComissaoVeiculo+" " + "Comissao Venda Acessorios: " + this.valorAcessorio+" " +
"Comissao do Financiamento: " + comissaoFinanciamento);
return "Comissao da Venda do Veiculo: \r \n" + this.SomaComissaoVeiculo + "Comissao Venda Acessorios: " + this.valorAcessorio +
"Comissao do Financiamento: " + comissaoFinanciamento;
}
public void setNovoOuUsado(String novoOuUsado) {
this.novoOuUsado = novoOuUsado;
}
public void setValorVenda(double valorVenda) {
this.valorVenda = valorVenda;
}
}
// Classe do Array
public class Array {
SLVeiculos [] sl;
public Array(){
this.sl = new SLVeiculos [50];
}
void adicionaArray(SLVeiculos f ){
for(int x = 0; x < this.sl.length; x++ ){
if(sl[x] == null){
this.sl[x] = f;
break;
}
}
}
public String verificar(){
for(int x = 0; x < this.sl.length; x++){
if(this.sl[x] == null){
System.out.println("Nao possui DADOS !!!");
}
else{
this.sl[x].mostra();
}
}
return null;
}
}
// classe da interface grafica OBS nao esta terminada ainda estou primeiro ajustando essa parte do array e do double para depois arrumar bonitinho o layout
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.JTextArea;
import javax.swing.JTextField;
public class Interface extends JFrame implements ActionListener {
SLVeiculos sl = null;
Array a1 = null;
JButton botaovendaveiculo;
JButton botaovendaacessorio;
JButton botaovendafinanciamento;
JButton botaoResultado;
JButton botaoSair;
JTextField vendaveiculo2 = new JTextField();
JTextField vendaacessorio2 = new JTextField();
JTextField vendafinanciamento2 = new JTextField();
JTextField Resultado2 = new JTextField();
JTextField tipo = new JTextField();
Interface(SLVeiculos slv){
this.sl = slv;
Array a1 = new Array();
a1.adicionaArray(sl);
setTitle("SL Veiculos Comissoes");
setSize(800,600);
setResizable(false);
//Setando as Escritas
JLabel vendaveiculo = new JLabel("Valor Venda Veiculo: ");
JLabel vendaacessorio = new JLabel("Valor Venda Acessorio: ");
JLabel vendafinanciamento = new JLabel("Valor Venda Financiamento: ");
JLabel tipo2 = new JLabel("Valor Venda Financiamento: ");
Resultado2 = new JTextField();
// os Botoes OK
botaovendaveiculo = new JButton("OK");
botaovendaacessorio = new JButton ("OK");
botaovendafinanciamento = new JButton ("OK");
botaoResultado = new JButton ("Resultado: ");
botaoSair = new JButton ("Sair");
//setando nullo o Layout
getContentPane().setLayout(null);
//Setando os lugares dos objetos
vendaveiculo.setBounds(20, 50,200, 20);
vendaacessorio.setBounds(20, 20, 80, 50);
vendafinanciamento.setBounds(50, 93, 10, 10);
vendaveiculo2.setBounds(20,80,150,20);
tipo.setBounds(40,150,20,150);
Resultado2.setBounds(100,100,500,400);
getContentPane().add(vendaveiculo);
getContentPane().add(vendaveiculo2);
getContentPane().add(Resultado2);
getContentPane().add(tipo);
vendaveiculo2.addActionListener(this);
Resultado2.addActionListener(this);
tipo.addActionListener(this);
/* letram.setBounds(50, 150, 10,10);
quantidadem.setBounds(90,145,100,20);
botaom.setBounds(202,138,70,30);
letrag.setBounds(50, 203, 10, 10);
quantidadeg.setBounds(93, 198, 100, 20);
botaog.setBounds(204, 192, 70, 30);
botaoResultado.setBounds(600, 250, 150, 30);
quantidadeResultado.setBounds(5, 300,785, 170);
botaoSair.setBounds(700, 480, 80, 30);
//Adicionando o Objeto
getContentPane().add(vendaveiculo);
getContentPane().add(quantidadep);
getContentPane().add(letrap);
getContentPane().add(botaop);
getContentPane().add(letram);
getContentPane().add(quantidadem);
getContentPane().add(botaom);
getContentPane().add(letrag);
getContentPane().add(quantidadeg);
getContentPane().add(botaog);
getContentPane().add(botaoResultado);
getContentPane().add(quantidadeResultado);
getContentPane().add(botaoSair);
*/
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public void actionPerformed (ActionEvent e){
if(e.getSource() == vendaveiculo2 ){
this.sl.comissaoVeiculo(Integer.parseInt(vendaveiculo2.getText()));
}
if(e.getSource() == vendaveiculo2 ){
this.a1.adicionaArray(sl);
}
if(e.getSource() == Resultado2){
Resultado2.setText(this.sl.mostra());
}
if(e.getSource() == tipo){
this.sl.setNovoOuUsado(tipo.getText());
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
SLVeiculos sl10 = new SLVeiculos();
Interface add = new Interface(sl10);
}
}
entao essa seria minha duvida eu quero criar um objeto e gravar esse objeto junto com os valores no array automaticamente quando a pessoa clicar ou der enter no vendaveiculo2 na classe interface.
obrigado.