Re: Swing GUI
- From: RedGrittyBrick <redgrittybrick@xxxxxxxxxxxxx>
- Date: Wed, 22 Aug 2007 10:52:04 +0100
RedGrittyBrick wrote:
lando wrote:<snip>
Where can I found examples for a gui with a big textarea and some buttons ?
Thanks.
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** ");
}
}
.
- References:
- Swing GUI
- From: lando
- Re: Swing GUI
- From: RedGrittyBrick
- Swing GUI
- Prev by Date: Re: Swing GUI
- Next by Date: Enums vs static final Strings
- Previous by thread: Re: Swing GUI
- Next by thread: Re: Swing GUI
- Index(es):