/*CODIGO 1*/
import javax.swing.*;
public class SArreglo {
public static void main( String args[] )
{
String salida = "";
int n[] = new int [10];
salida = "El Arreglo en Swing es: \n";
for( int i = 0; i < 10; i++ )
{
n[i] = i;
salida += "" + n[i] + "";
}
JTextArea areaSalida = new JTextArea( 11, 10 );
areaSalida.setText( salida );
JOptionPane.showMessageDialog( null, areaSalida,
"Arreglo desde Swing...",
JOptionPane.INFORMATION_MESSAGE);
System.exit( 0 );
}
}
/*CODIGO 2*/
import java.awt.*;
import java.awt.event.*;
/**
* Sample application using Frame.
*
* @author
* @version 1.00 07/09/13
*/
public class SArregloFrame extends Frame {
/**
* The constructor.
*/
public SArregloFrame() {
MenuBar menuBar = new MenuBar();
Menu menuFile = new Menu();
MenuItem menuFileExit = new MenuItem();
menuFile.setLabel("File");
menuFileExit.setLabel("Exit");
// Add action listener.for the menu button
menuFileExit.addActionListener
(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
SArregloFrame.this.windowClosed();
}
}
);
menuFile.add(menuFileExit);
menuBar.add(menuFile);
setTitle("SArreglo");
setMenuBar(menuBar);
setSize(new Dimension(400, 400));
// Add window listener.
this.addWindowListener
(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
SArregloFrame.this.windowClosed();
}
}
);
}
/**
* Shutdown procedure when run as an application.
*/
protected void windowClosed() {
// TODO: Check if it is safe to close the application
// Exit application.
System.exit(0);
}
}
|