post #1 of 1
Thread Starter 
Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


public class ButtonGUI extends JFrame implements ActionListener{
    private JButton button1;
    private JButton button2;

    public ButtonGUI(String title){
        buildGUI();
        setTitle(title);
        pack();
        setVisible(true);
    }

    public void buildGUI(){
        Container contentPane = getContentPane();
        contentPane.setLayout(new BorderLayout());
        button1 = new JButton("Left");
        button1.addActionListener(this);
        button2 = new JButton("Right!");
        button2.addActionListener(this);
        JPanel inputPanel = new JPanel();
        inputPanel.add(button1);
        inputPanel.add(button2);
        contentPane.add(inputPanel);
    }

    public void actionPerformed(ActionEvent e){
        String bText=button1.getText();
        button1.setText(button2.getText());
        button2.setText(bText);
    }

        public static void main(String args[])
    {
        new ButtonGUI("Button Game");
    }

}

How I make it when clicks a button , display its label in the JTextField . A JButton()'s labal can be gotten with the getText() method ?
Help please .