Codice PHP:
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.*;
import javax.swing.*;
public class ProvaEventi2 extends JFrame{
....
private Container CR;
private GridBagLayout GBL;
private GridBagConstraints GBC;
...
private JTextArea jta1;
private JButton jbt1;
public ProvaEventi2(){
initProvaEventi();
this.setLocation(250,250);
setVisible(true);
}
...
private void initProvaEventi(){
setTitle("Prove Eventi");
GBL = new GridBagLayout();
CR = getContentPane();
CR.setLayout(GBL);
...
//Bottone "GET"
GBC = new GridBagConstraints();
jbt1.setPreferredSize(new Dimension(50,22));
jbt1.setMargin(new Insets(2,2,2,2));
CR.add(jbt1);
GBC.gridx = 2;
GBC.gridy = 0;
GBL.setConstraints(jbt1, GBC);
//Gestione evento bottone GET
jbt1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jta1.append(jfld1.getText());//jfld1 è un textField in cui scrivo qualcosa che
//viene registrata dal evento scatenato dal GET
}
});
...
//Area di testo che si allunga quando il testo arriva al limite orrizzontale
jta1 = new JTextArea();
jta1.setColumns(14);
jta1.setRows(3);
jta1.setBorder(BorderFactory.createEtchedBorder());
jta1.setEditable(false);
jta1.setOpaque(false);
GBC = new GridBagConstraints();
CR.add(jta1);
GBC.gridx = 0;
GBC.gridy = 2;
GBC.gridwidth = 2;
GBC.anchor = GridBagConstraints.WEST;
GBC.insets.top = 5;
GBL.setConstraints(jta1, GBC);