lunedì 15 dicembre 2008

ALBERO NATALE

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
public class AlberoNatale{
private JFrame albero;
private PannelloAlbero a;
private JButton accende;
private JButton spegne;
public AlberoNatale(){
albero=new JFrame("Albero del santo Natale 2008");
albero.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
albero.setSize(500,500);
a=new PannelloAlbero();
accende=new JButton("accendi lampadine");
spegne=new JButton("spegne le lampadine");
albero.add(a,BorderLayout.CENTER);
albero.add(accende,BorderLayout.SOUTH);
albero.setVisible(true);
}

public class PannelloAlbero extends JPanel{
public void paintComponent(Graphics g){
Graphics g2d=(Graphics2D) g;
Image alberoImmagine=new ImageIcon("albNat.jpg").getImage();
g.drawImage(alberoImmagine,0,0,albero.getWidth(),albero.getHeight(),null);
}
}
public static void main(String[] args){
AlberoNatale albero=new AlberoNatale();
}
}
_____________________________________________________________________________________
Free Image Hosting at www.ImageShack.us

QuickPost Quickpost this image to Myspace, Digg, Facebook, and others!

lunedì 8 dicembre 2008

CALCOLATRICE

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Finestra2 implements ActionListener{
JLabel l1=new JLabel("primo numero");
JLabel l2=new JLabel("secondo numero");
JTextField t1=new JTextField();
JTextField t2=new JTextField();
JButton b1=new JButton("+");
JTextField risultato=new JTextField();
public void creaForm1(){
JFrame finestra1=new JFrame("finestra IVL");
finestra1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
finestra1.setSize(300,300);
finestra1.setLayout(new GridLayout(3,2));
finestra1.add(l1);
finestra1.add(t1);
finestra1.add(l2);
finestra1.add(t2);
finestra1.add(b1);
finestra1.add(risultato);
b1.addActionListener(this);
finestra1.setVisible(true);
}
public void actionPerformed(ActionEvent event){
String testo1=t1.getText();
String testo2=t2.getText();
int a=Integer.parseInt(testo1);
int b=Integer.parseInt(testo2);
int somma=a+b;
String r=Integer.toString(somma);
risultato.setText(r);
}
}

l'operazione della somma viene svolta cliccando sul "+" tramite l'applet!

giovedì 4 dicembre 2008

Somma
import javax.swing.JOptionPane;public class Somma{ public static void main(String[] args){ String primoNumero=JOptionPane.showInputDialog("digita il primo numero"); String secondoNumero=JOptionPane.showInputDialog("digita il secondo numero"); int a=Integer.parseInt(primoNumero); int b=Integer.parseInt(secondoNumero); int c=a+b; JOptionPane.showMessageDialog(null, "somma= " + c, "somma di due interi", JOptionPane.PLAIN_MESSAGE); }}
_____________________________________________________________________
Free Image Hosting at <a href=www.ImageShack.us" />

QuickPost Quickpost this image to Myspace, Digg, Facebook, and others!

___________________________________________________________________________________
Free Image Hosting at www.ImageShack.us

QuickPost Quickpost this image to Myspace, Digg, Facebook, and others!
_____________________________________________________________________________________
Free Image Hosting at www.ImageShack.us

QuickPost Quickpost this image to Myspace, Digg, Facebook, and others!

lunedì 1 dicembre 2008

Come costruire una finestra

import javax.swing.*;public class Finestra1 { public void creaForm1(){ JFrame finestra1=new JFrame("finestra IVL"); finestra1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); finestra1.setSize(300,300); finestra1.setVisible(true); }
}


___________________________________________________________________________________


public class TestaFinestra1{ public static void main(String[] args){ Finestra1 f=new Finestra1(); f.creaForm1(); }
}