[/b]eu fiz um programa onde eu tenhu uma frame com 4 botoes criados so q eu naum consigo atribuir funçoes a eles gostaria de saber como faço isso se alguem puder me ajudar fico agradecido! :D[quote]
/ *esse programa recebe valor quantidade e nome de compra e de cliente enumera e imprimi
*os valores na ordem dentro de uma frame
**/
import javax.swing.;
import java.util.;
import java.awt.;
import java.awt.event.;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class DadosClientes3
{
//Entrada dialog recebe String
static String entrada(String msg)
{
String a;
a = JOptionPane.showInputDialog(msg);
return a;
}
//Entrada dialog recebe Float
static Float entrada2(String msg)
{
String d;
float c;
d = JOptionPane.showInputDialog(msg);
try
{
c = Float.parseFloat(d);
}
catch(NumberFormatException tryInt)
{
JOptionPane.showMessageDialog(null,"Valor invalido","ERRO",JOptionPane.ERROR_MESSAGE);
c = 0;
}
return c;
}
//Entrada dialog recebe Int
static int entrada3(String msg)
{
String e;
int f;
e = JOptionPane.showInputDialog(msg);
try
{
f = Integer.parseInt(e);
}
catch(NumberFormatException tryInt)
{
JOptionPane.showMessageDialog(null,"Valor Invalido","ERRO",JOptionPane.ERROR_MESSAGE);
f = 0;
}
return f;
}
public static void main(String args[])
{
//Apresenta o programa
System.out.println("Produzido por AlexandreLTD");
System.out.println("Aguarde...");
//
//Entrada de valores
float Valor = 0;
int Qloop = 0;
int Quantidade = 0;
int QPessoa = 0;
String Nome ="";
String recebe ="";
String recebe2 ="";
Vector nome = new Vector();
Vector valor = new Vector();
Vector quantidade = new Vector();
//
//O usuario escolhe quantas vezes o programa vai rodar
Qloop = entrada3("Digite o numero de clientes: ");
//
//Loop1
for(QPessoa = 0; QPessoa < Qloop; QPessoa++)
{
//Entrada de dados
Nome = entrada ("Entre com o nome ou o codigo da pessoa: ");
nome.add(Nome);
Valor = entrada2("Entre com o valor da compra: ");
valor.add(Valor);
Quantidade = entrada3("Entre com a quantidade: ");
quantidade.add(Quantidade);
}
//
//Cria a Frame e a Box
//
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame Frame = new JFrame("Lista de Clientes");
Box box = Box.createVerticalBox();
JTextArea TA = new JTextArea("",15,15);
JButton BSair = new JButto("Exit");
JButton Correcao = new JButto("Corrigir"); [b]Bototes[/b]
//Frame
Frame.getContentPane().add(box);
Frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
//Box
box.add(new JScrollPane(TA));
box.add(BSair);
box.add(Correcao); [b]Botoes[/b]
//TextArea
TA.setBackground(Color.white);
TA.setForeground(Color.blue);
TA.setEditable(false);
//Frame
Frame.setSize(572,370);
Frame.setVisible(true);
//
//Cria a frame2 e a box2
//
JFrame Frame2 = new JFrame("Area de ediçao");
Box box2 = Box.createVerticalBox();
JTextArea TA2 = new JTextArea("",10,15);
JButton BSair2 = new JButton("Exit");
JButton salva = new JButton("Salvar");
//Frame
Frame2.getContentPane().add(box2);
Frame2.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
Frame2.setBounds(300,300,100,100);
//Box
box2.add(new JScrollPane(TA2));
box2.add(BSair2);
box2.add(salva);
//TextArea
TA2.setBackground(Color.white);
TA2.setForeground(Color.blue);
TA2.setEditable(true);
//Frame
Frame2.setSize(572,370);
Frame2.setVisible(true);
//
//Loop2
for(int y = 0; y < Qloop; y++)
{
if ((nome == null) || (quantidade == null) || (valor == null))
{
System.exit(0);
}
recebe = TA.getText()+"Nº"+(y+1)+"\nNome do cliente: "+nome.elementAt(y)+"\nValor da compra: "+valor.elementAt(y)+"\nQuantidade comprada: "+quantidade.elementAt(y)+"\n\n";
recebe2= "Faça a correção nessa area:\n";
TA.setText(recebe);
TA2.setText(recebe2);
}
//Saida
System.out.println("End Of Program!");
}
}