Re: Swing GUI
RedGrittyBrick wrote:
lando wrote:
Where can I found examples for a gui with a big textarea and some
buttons ?
Thanks.
<snip>
Here's a more useful example, just in case I seem too sarcastic :-)
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
public class ABigTextAreaAndSomeButtons implements ActionListener {
private static final String THIS="This", THAT="That", OTHER="Other";
private JTextArea area = new JTextArea(40,80);
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new ABigTextAreaAndSomeButtons();
}
});
}
ABigTextAreaAndSomeButtons() {
JPanel p = new JPanel();
p.setLayout(new BorderLayout());
p.add(area, BorderLayout.CENTER);
JPanel bp = new JPanel();
bp.add(makeJButton(THIS));
bp.add(makeJButton(THAT));
bp.add(makeJButton(OTHER));
p.add(bp, BorderLayout.SOUTH);
JFrame f = new JFrame("A big text area with some buttons");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(p);
f.pack();
f.setVisible(true);
}
private JButton makeJButton(String label) {
JButton b = new JButton(label);
b.addActionListener(this);
return b;
}
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
area.append("\n" + command);
if (OTHER.equals(command))
area.append(" **bonus** ");
}
}