fiz um programa q abre um dialog e pede pra entra com uma frase
eu queria q essa frase fosse mostrada em uma frame!a frame eu ja fiz mas naum sei como faze pra pode mostra a resposta. tem como eu fazer isso?
agradeço aos q puderem me ajudar! :lol:
tem como postra o codigo?
eu resolvi esse problema mas agora to querenu receber valores inteiros no dialog e imprimi eles na frame mas naum sei como faço pra converte int em string para aparece na frame.
o codigo e esse ate intao.Valeu!!!
[code]import javax.swing.*;
public class num
{
static int entrada(String msg)
{
String A;
int B;
A = JOptionPane.showInputDialog(msg);
try
{
B = Integer.parseInt(A);
}
catch(NumberFormatException intTry)
{
JOptionPane.showMessageDialog(null,"Invalido","ERRO",JOptionPane.ERROR_MESSAGE);
B = 0;
}
return B;
}
static String entrada2(String msg)
{
String r;
int R;
r = JOptionPane.showInputDialog(msg);
try
{
R = Integer.parseInt(r);
}
catch(NumberFormatException intTry)
{
JOptionPane.showMessageDialog(null,"Invalido","ERRO",JOptionPane.ERROR_MESSAGE);
R = 0;
}
return r;
}
public static void main(String args[])
{
//cria a entrada da Dialog
int a,b,R;
String r ="";
a=entrada("Entre com um numero: ");
b=entrada("Entre com outro numero: ");
R= a+b;
//cria a entrada da Frame
JFrame frame = new JFrame("Soma!");
JLabel label = new JLabel();
frame.getContentPane().add(label);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}[/code]
Para mostrar um int como string faça isto:
String numeroparastring = Integer.toString(seu_numero);
blz
eu entendi mas naum consegui usa corretamente alguem pode me explicar como eu uso esse tipo de comando
Fico grato aos q me ajadarem
Valeu m4des c ajudo muito velho ja fiz o q eu queria Brigadao!!!ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh