Creating a GUI

suggest change

Applets could easily be used to create a GUI. They act like a Container and have an add() method that takes any awt or swing component.

public class MyGUIApplet extends JApplet{

    private JPanel panel;
    private JButton button;
    private JComboBox<String> cmbBox;
    private JTextField textField;

    public void init(){
        panel = new JPanel();        
        button = new JButton("ClickMe!");
        button.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent ae) {
                if(((String)cmbBox.getSelectedItem()).equals("greet")) {
                    JOptionPane.showMessageDialog(null,"Hello " + textField.getText());
                } else {
                    JOptionPane.showMessageDialog(null,textField.getText() + " stinks!");
        cmbBox = new JComboBox<>(new String[]{"greet", "offend"});
        textField = new JTextField("John Doe");

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents