All pastes #294513 Raw Edit

Something

public text v1 · immutable
#294513 ·published 2006-12-28 16:03 UTC
rendered paste body
import java.applet.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import org.jibble.jmegahal.*;


public class Main extends JApplet implements ActionListener {
    private String myName;
    private JTextField nameField;
    private JTextArea status;
    private JMegaHal hal = new JMegaHal();

    public void init() {
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    createGUI();
                }
            });
        } catch (Exception e) {
            System.err.println("Unable to do the stuff, die.");
        }
    }

    private void createGUI() {
        JPanel contentPane = new JPanel(new GridBagLayout());
        contentPane.setBorder(BorderFactory.createCompoundBorder(
                                    BorderFactory.createLineBorder(Color.BLACK),
                                    BorderFactory.createEmptyBorder(10,10,5,5)));
        setContentPane(contentPane);
        
        GridBagConstraints c = new GridBagConstraints();
        c.insets = new Insets(0,0,5,5);

        JLabel receiverLabel = new JLabel("Your input:", 
                                          JLabel.TRAILING);
        add(receiverLabel, c);

        nameField = new JTextField("Type your text here!",
                                                10);
        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 1.0;
        add(nameField, c);
        nameField.addActionListener(this);

        JButton button = new JButton("Send message");
        c.gridwidth = GridBagConstraints.REMAINDER; 
        c.anchor = GridBagConstraints.LINE_START; 
                                               
        c.fill = GridBagConstraints.NONE;
  
        c.weightx = 0.0;
        add(button, c);
        button.addActionListener(this);

        status = new JTextArea(5, 60);
        status.setEditable(false);
        c.anchor = GridBagConstraints.CENTER;
        c.fill = GridBagConstraints.BOTH;
        c.weighty = 1.0;
        add(new JScrollPane(status), c);

        c.weightx = 0.0;
        c.weighty = 0.0;
    }

    public void actionPerformed(ActionEvent event) {
        String input = nameField.getText();
        
        hal.add(input);
        String sentence1 = hal.getSentence();
        status.append(sentence1 + "\n");
    }
}