GustavoLaguna 23 de abr. de 2008
Boa Tarde ghostta,
Seja bem vindo ao fórum. Procure utilizar as tags “code” para colocar o seu código.
Assim:
import javax.swing.* ;
import java.awt.* ;
public class calculos extends JFrame
{
private JButton b1 ;
private JButton b2 ;
public calculos ()
{
super ( "Calculos" );
b1 = new JButton ( "So inteiros" );
b2 = new JButton ( "Reais" );
Container c = getContentPane ();
c . setLayout ( new FlowLayout ());
Panel a , b ;
a = new Panel ();
b = new Panel ();
b . setLayout ( new GridLayout ( 100 , 100 ));
c . add ( b1 );
c . add ( b2 );
setSize ( 400 , 100 );
show ();
}
public static void main ( String [] args )
{
calculos calc = new calculos ();
}
}
GustavoLaguna 23 de abr. de 2008
Acho que sua resposta será colocar um evento no botão, voce pode procurar sobre ActionListener.
colored 23 de abr. de 2008
Agora os botoes ja tem ação agora faça seus calculos =D
public class LoL extends JFrame implements ActionListener
{
private JButton b1 ;
private JButton b2 ;
public LoL ()
{
super ( "Calculos" );
b1 = new JButton ( "So inteiros" );
b1 . addActionListener ( this );
b2 = new JButton ( "Reais" );
b2 . addActionListener ( this );
Container c = getContentPane ();
c . setLayout ( new FlowLayout ());
Panel a , b ;
a = new Panel ();
b = new Panel ();
b . setLayout ( new GridLayout ( 100 , 100 ));
c . add ( b1 );
c . add ( b2 );
setSize ( 400 , 100 );
}
public static void main ( String [] args )
{
new LoL (). setVisible ( true );
}
@Override
public void actionPerformed ( ActionEvent e ) {
if ( e . getSource () == b1 ){
JOptionPane . showMessageDialog ( null , "So Inteiros" );
}
if ( e . getSource () == b2 ){
JOptionPane . showMessageDialog ( null , "So Reais" );
}
}
}
ghostta 23 de abr. de 2008
[size=18]Valeu pelas dicas.
Consegui aqui o que eu queria.
Vlw[/size]
paulofernandesjr 23 de abr. de 2008
esse mesmo evento para botões é igual para JMenu ???
colored 23 de abr. de 2008
HUm Jmenu é akela aba neh tipo arquivo editar…
Pros itens q tem dentro sim…
Ex:
Arquivo
Salvar
Sair
Durmir
if ( e .getSource == Jmenuitem ) {
new Form () .setvisible ( true ) ;
}