import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class lez20070404_01 extends JFrame
{
	JTextArea areatesto;
	JTextField campotesto;
	JButton pulsante;
	JSlider r, g, b;
	JPanel pannelloCampotesto;
	JPanel pannelloRGB;
	
	public static void main(String[] a)
	{
		lez20070404_01 f = new lez20070404_01();
		f.setVisible(true);
	}
	
	public lez20070404_01()
	{
		setTitle("Prova textarea");
		setSize(400,400);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		
		setLayout(new BorderLayout());
		
		campotesto = new JTextField();
		campotesto.setPreferredSize(new Dimension(200,30));
		pannelloCampotesto = new JPanel();
		pannelloCampotesto.add(campotesto);
		pulsante = new JButton("aggiungi");
		
		pulsante.addActionListener( new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				areatesto.setText(areatesto.getText() +"\n"+ campotesto.getText());
				campotesto.setText("");
		}});
		
		pannelloCampotesto.add(pulsante);
		add(pannelloCampotesto, BorderLayout.NORTH);
		
		areatesto = new JTextArea();
		JScrollPane jsp = new JScrollPane(areatesto);
		add(jsp, BorderLayout.CENTER);
		
		pannelloRGB = new JPanel();
		pannelloRGB.setLayout(new GridLayout(3,1));
		
		r = new JSlider(0, 255, 255);
		r.addChangeListener(new ChangeListener(){
			public void stateChanged(ChangeEvent e) {
				pannelloCampotesto.setBackground(new Color(r.getValue(),g.getValue(),b.getValue()));
			}});
		pannelloRGB.add(r);
		g = new JSlider(0, 255, 255);
		g.addChangeListener(new ChangeListener(){
			public void stateChanged(ChangeEvent e) {
				pannelloCampotesto.setBackground(new Color(r.getValue(),g.getValue(),b.getValue()));
				}});
		pannelloRGB.add(g);
		b = new JSlider(0, 255, 255);
		b.addChangeListener(new ChangeListener(){
			public void stateChanged(ChangeEvent e) {
				pannelloCampotesto.setBackground(new Color(r.getValue(),g.getValue(),b.getValue()));
				}});
		pannelloRGB.add(b);
		
		add(pannelloRGB, BorderLayout.SOUTH);
		
		campotesto.setText("paolo");
		areatesto.setText("selva");
		pannelloCampotesto.setBackground(new Color(r.getValue(),g.getValue(),b.getValue()));
	}
}
