giovedì 21 gennaio 2010

Inserimento-esercizio in java

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Inserimento {
private JFrame f1 = new JFrame("Inserimento");
private JButton b1 = new JButton ("invio");
private JTextField t1 = new JTextField();
private JFrame f2 =new JFrame ("Saluti");
private JLabel l1 = new JLabel();
private JLabel l2 = new JLabel();
private JLabel l3 = new JLabel();
public void apriFinestra(){
f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f1.add(BorderLayout.NORTH,t1);
f1.add(BorderLayout.SOUTH,b1);
b1.addActionListener(new Leggi());
f1.setSize(200,200);
f1.setVisible(true);
}
public class Leggi implements ActionListener{
public void actionPerformed(ActionEvent E){
String nome=t1.getText();
l1.setText(nome);
l2.setText("Auguri");
ImageIcon icon = new ImageIcon("C:/Documents and Settings/All Users/Documenti/Immagini/Immagini campione/iverno.jpeg");
l3= new JLabel(icon);
f2.add(BorderLayout.WEST,l3);
f2.add(BorderLayout.CENTER,l1);
f2.setSize(200,200);
f2.setVisible(true);
}
}
public static void main(String[]args){
Inserimento I1= new Inserimento();
I1.apriFinestra();
}
}

Nessun commento: