Package org.onemind.swingweb.widgetdemo

Source Code of org.onemind.swingweb.widgetdemo.LabelButtonTextDemo

/*
* Copyright (C) 2004 TiongHiang Lee
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not,  write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*
* Email: thlee@onemindsoft.org
*/

package org.onemind.swingweb.widgetdemo;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.InputStream;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.onemind.swingweb.component.layout.TableLayout;
public class LabelButtonTextDemo extends AbstractDemo implements ActionListener, ChangeListener
{

    public LabelButtonTextDemo(DemoConsole console)
    {
        super("Label, Button and Text", console);
        setLayout(new FlowLayout());
        add(getDemoArea());
    }

    public Container getDemoArea()
    {
        JPanel pnl = new JPanel();
        TableLayout layout = new TableLayout(pnl);
        pnl.setLayout(layout);
        layout.getConstraint().fill = GridBagConstraints.BOTH;
        layout.getConstraint().insets = new Insets(5, 5, 5, 5);
        Icon icon = new ImageIcon(getClass().getResource("/org/onemind/swingweb/widgetdemo/icecream.jpg"));

        /** labels **/
        //just a label
        JLabel lbl = new JLabel("This is a yellow JLabel");
        lbl.setForeground(Color.YELLOW);
        layout.addNextRow(lbl);
       
        //label with colors
        lbl = new JLabel("<html>This is a <font color=\"blue\"><i>html</i></font> JLabel</html>");
        layout.addNextRow(lbl);
       
        //label with icon
        lbl = new JLabel("JLabel with icon");
        lbl.setIcon(icon);
        layout.addNextRow(lbl);

        //disabled label
        lbl = new JLabel("Disabled JLabel");
        layout.addNextRow(lbl);
       
        /** buttons **/
        //button
        JButton btn = new JButton("Button1");
        btn.setBackground(Color.YELLOW);
        layout.addNextRow(btn);
        layout.addNextCell(new JLabel("Just a JButton with yellow background"));
       
        //button with listener
        btn = new JButton("Button2");
        btn.addActionListener(this);
        layout.addNextRow(btn);
        layout.addNextCell(new JLabel("JButton with listener. Push will submit"));
       
        //button with no border
        btn = new JButton("Button3");
        btn.setBorder(null);
        layout.addNextRow(btn);
        layout.addNextCell(new JLabel("JButton with no border"));
       
        //button with icon
        btn = new JButton("Button4");
        btn.setIcon(icon);
        layout.addNextRow(btn);
        layout.addNextCell(new JLabel("JButton with icon"));
       
        /** checkboxes **/
        //button
        JCheckBox checkbox = new JCheckBox("Checkbox1");
        checkbox.setBackground(Color.YELLOW);
        layout.addNextRow(checkbox);
        layout.addNextCell(new JLabel("Just a JCheckbox with yellow background"));
       
        //button with listener
        checkbox = new JCheckBox("Checkbox2");
        checkbox.addChangeListener(this);
        layout.addNextRow(checkbox);
        layout.addNextCell(new JLabel("JCheckBox with change listener. Push will submit"));
       
        //button in a group
        JPanel subPanel = new JPanel();
        subPanel.setLayout(new GridLayout(1, 2));
        ButtonGroup group = new ButtonGroup();
        checkbox = new JCheckBox("Checkbox3");
        group.add(checkbox);
        subPanel.add(checkbox);
        checkbox = new JCheckBox("Checkbox4");
        group.add(checkbox);
        subPanel.add(checkbox);
        layout.addNextRow(subPanel);
        layout.addNextCell(new JLabel("JCheckBox in button group. Push always submit"));
       
        /** radio buttons **/
//      button in a group
        subPanel = new JPanel();
        subPanel.setLayout(new GridLayout(1, 2));
        group = new ButtonGroup();
        JRadioButton rbtn = new JRadioButton("RadioButton1");
        group.add(rbtn);
        subPanel.add(rbtn);
        rbtn = new JRadioButton("RadioButton2");
        group.add(rbtn);
        subPanel.add(rbtn);
        layout.addNextRow(subPanel);       
        layout.addNextCell(new JLabel("RadioButtons in button group"));
       
        //button in a group with listener
        subPanel = new JPanel();
        subPanel.setLayout(new GridLayout(1, 2));
        group = new ButtonGroup();
        rbtn = new JRadioButton("RadioButton1");
        group.add(rbtn);
        rbtn.addChangeListener(this);
        subPanel.add(rbtn);
        rbtn = new JRadioButton("RadioButton2");
        group.add(rbtn);
        rbtn.addActionListener(this);
        subPanel.add(rbtn);
        layout.addNextRow(subPanel);       
        layout.addNextCell(new JLabel("RadioButtons with change/action listener in button group. Push will submit"));
       
        /** text demo **/
        //Text field
        JTextField fld = new JTextField();
        fld.setColumns(10);
        fld.setText("Test");
        layout.addNextRow(fld);
        layout.addNextCell(new JLabel("Just a text field"));
       
        //Text field with TextListner
        fld = new JTextField();
        fld.setColumns(10);
        fld.setText("Test");
        layout.addNextRow(fld);
        layout.addNextCell(new JLabel("Texd field with text listener"));
       
        //Password field
        fld = new JPasswordField();
        fld.setColumns(10);
        layout.addNextRow(fld);
        layout.addNextCell(new JLabel("A password field"));
       
        //Text area
        JTextArea tfld = new JTextArea();
        tfld.setColumns(10);
        tfld.setRows(4);
        layout.addNextRow(tfld);
        layout.addNextCell(new JLabel("A text area"));
        return pnl;
    }

    public void actionPerformed(ActionEvent e)
    {
        getConsole().log(e.toString());
    }

    public void stateChanged(ChangeEvent e)
    {
        getConsole().log(e.toString());
    }
}
TOP

Related Classes of org.onemind.swingweb.widgetdemo.LabelButtonTextDemo

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.