Sie sind auf Seite 1von 23

1

PROGRAMA INTERFAZ GRAFICA IMPLEMENTADO


HILOS
Crear una interfaz grfica con un men que contenga botones que permita calcular las
siguientes operaciones:
1. Generar la serie de nmeros primos.
2. Generar la serie de nmeros Palndromos.
Usar e implementar todos los botones y validaciones que necesite.
Use el botn Limpiar, Resultado, Regresar al Men y Salir de la aplicacin
Para las dos opciones ingresar el inicio y el fin de la serie y mostrar el resultado, usando el
concepto de hilos o multitarea estableciendo un tiempo de ejecucin.

Cdigo Ventana Principal
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.SystemColor;
import java.awt.Toolkit;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.ImageIcon;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JPopupMenu;
import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.ButtonGroup;
import java.awt.*;
import javax.swing.JSeparator;
import javax.swing.JLabel;

public class VentanaPrincipal extends JFrame {
private JPanel contentPane;
private final ButtonGroup buttonGroup = new ButtonGroup();

public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
VentanaPrincipal frame = new VentanaPrincipal();
frame.setVisible(true);
} catch (Exception e) {
2

e.printStackTrace();
}
}
});
}


public VentanaPrincipal() {


setIconImage(Toolkit.getDefaultToolkit().getImage(VentanaPrincipal.class.
getResource("/javax/swing/plaf/basic/icons/JavaCup16.png")));
setTitle("MENU OPCIONES");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 378, 152);

JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);

JMenu mnOperaciones = new JMenu("OPCIONES");
menuBar.add(mnOperaciones);

JMenuItem mntmSuma = new JMenuItem("PRIMOS");
mntmSuma.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
VentanaPrimos suma=new VentanaPrimos();
suma.setVisible(true);
dispose();
}
});
mnOperaciones.add(mntmSuma);

JMenuItem mntmResta = new JMenuItem("PALINDROMOS");
mntmResta.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
VentanaPalindromos resta=new VentanaPalindromos();
resta.setVisible(true);
dispose();
}
});
mnOperaciones.add(mntmResta);

JSeparator separator = new JSeparator();
mnOperaciones.add(separator);

JMenuItem mntmSalir_1 = new JMenuItem("SALIR");
mntmSalir_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
mnOperaciones.add(mntmSalir_1);
contentPane = new JPanel();
contentPane.setBackground(new Color(255, 255, 255));
contentPane.setForeground(new Color(192, 192, 192));
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
3



JPopupMenu popupMenu = new JPopupMenu();
popupMenu.setBounds(210, 11, 49, 38);
addPopup(contentPane, popupMenu);

JMenuItem mntmInformacion = new JMenuItem("INFORMACION ?");
mntmInformacion.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFrameConFondo info=new JFrameConFondo();
info.setVisible(true);
dispose();
}
});
popupMenu.add(mntmInformacion);

JLabel label = new JLabel("REALIZADO POR:");
label.setForeground(Color.RED);
label.setFont(new Font("Calisto MT", Font.BOLD, 12));
label.setBounds(77, 11, 136, 27);
contentPane.add(label);

JLabel label_1 = new JLabel("FREDDY ALVAREZ");
label_1.setForeground(Color.BLUE);
label_1.setFont(new Font("Californian FB", Font.ITALIC, 15));
label_1.setBounds(144, 40, 196, 27);
contentPane.add(label_1);

}
private static void addPopup(Component component, final JPopupMenu popup)
{
component.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
if (e.isPopupTrigger()) {
showMenu(e);
}
}
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
showMenu(e);
}
}
private void showMenu(MouseEvent e) {
popup.show(e.getComponent(), e.getX(), e.getY());
}
});
}
}
Cdigo Ventana Primos
import java.awt.BorderLayout;
import java.awt.Event;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
4

import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.ImageIcon;
import java.awt.*;
import javax.swing.*;
import java.util.*;

public class VentanaPrimos extends JFrame
{

private JPanel contentPane;
private JTextField num1;
private JTextField num2;
private JLabel lblRESULTADO;
private String numero1;
private String numero2;
private int numeroint1;
private int numeroint2;


class Hilo1 implements Runnable
{
private int inicio,fin;
private String rs="";
private String rserie="";
private JLabel lbl;

public Hilo1(int num1,int num2,JLabel jlbl)
{
inicio=num1;
fin=num2;
lbl=jlbl;
}

public void run()
{

int contador=0;
int i=0;
int verificar=0;
int primo,mod,incremento,cuantos;
String serie="";
//Para saber cuantos nmeros primos existen
cuantos=0;




if(inicio>0 && fin>0)
{

if(inicio<fin)
{
//Controlamos si ingreso como valor inicial el 1
if (inicio==1)
{
5

inicio=2;
}
//Bucle de anlisis
for(incremento=inicio; incremento<=fin;
incremento++)
{
//Inicializamos las variables en cada
bucle
primo = 1;
mod = 2;
//Analizamos mientras mod sea menor o
igual a incremento dividido 2 y la variable primo == a uno.
while(mod<=incremento/2 && primo==1)
{
if(incremento % mod == 0)
{
primo = 0;
}
else
{
mod++;
}
}
//Si llegamos hasta aqu con primo igual
a uno muestra el nmero
if(primo == 1)
{
try
{
Thread.currentThread();
Thread.sleep((long)(450));
}catch(InterruptedException e)
{

System.out.println(e.getMessage());
}

serie=serie+" "+incremento;
lbl.setText(""+serie);
//Aumentamos el contador final
cuantos++;
}

}
}
}
else
if(inicio<0 && fin<0)
{

if(Math.abs(inicio)>Math.abs(fin))
{
//Controlamos si ingreso como valor
inicial el 1
if (Math.abs(fin)==1)
{
fin=2;
}
6

//Bucle de anlisis
for(incremento=Math.abs(fin);
incremento<=Math.abs(inicio); incremento++)
{
//Inicializamos las variables en
cada bucle
primo = 1;
mod = 2;
//Analizamos mientras mod sea menor
o igual a incremento dividido 2 y la variable primo == a uno.
while(mod<=incremento/2 &&
primo==1)
{
if(incremento % mod == 0)
{
primo = 0;
}
else
{
mod++;
}
}
//Si llegamos hasta aqu con primo
igual a uno muestra el nmero
if(primo == 1)
{
try
{

Thread.currentThread();

Thread.sleep((long)(450));
}catch(InterruptedException
e)
{

System.out.println(e.getMessage());
}

serie=serie+" -"+incremento;
lbl.setText(serie);
//Aumentamos el contador
final
cuantos++;
}

}
}
}
else
if(inicio<0 && fin>0)
{

//Bucle de anlisis NEGATIVOS
for(incremento=Math.abs(inicio);
incremento>=2; incremento--)
{
7

//Inicializamos las variables en
cada bucle
primo = 1;
mod = 2;
//Analizamos mientras mod sea menor
o igual a incremento dividido 2 y la variable primo == a uno.
while(mod<=incremento/2 &&
primo==1)
{
if(incremento % mod == 0)
{
primo = 0;
}
else
{
mod++;
}
}
//Si llegamos hasta aqu con primo
igual a uno muestra el nmero
if(primo == 1)
{
try
{

Thread.currentThread();

Thread.sleep((long)(450));
}catch(InterruptedException
e)
{

System.out.println(e.getMessage());
}

StringBuilder builder=new
StringBuilder(serie);
String
sCadenaInvertida=builder.reverse().toString();

lbl.setText(sCadenaInvertida);
serie=serie+"-"+incremento;
//Aumentamos el contador
final
cuantos++;
}
}



//Bucle de anlisis POSITIVOS
for(incremento=2; incremento<=fin;
incremento++)
{
//Inicializamos las variables en
cada bucle
primo = 1;
mod = 2;
8

//Analizamos mientras mod sea menor
o igual a incremento dividido 2 y la variable primo == a uno.
while(mod<=incremento/2 &&
primo==1)
{
if(incremento % mod == 0)
{
primo = 0;
}
else
{
mod++;
}
}
//Si llegamos hasta aqu con primo
igual a uno muestra el nmero
if(primo == 1)
{
try
{

Thread.currentThread();

Thread.sleep((long)(450));
}catch(InterruptedException
e)
{

System.out.println(e.getMessage());
}

serie=serie+" "+incremento;
lbl.setText(""+serie);
//Aumentamos el contador
final
cuantos++;
}
}

}
}
}


public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
try
{
VentanaPrimos frame = new VentanaPrimos();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
9

});
}


private static boolean isNumber(String n)
{
try
{
Integer.parseInt(n);
return true;
} catch (NumberFormatException nfe) {
return false;
}
}


public VentanaPrimos()
{
setTitle("VENTANA PRIMOS ENTEROS");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 494, 250);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);

JLabel lbl1 = new JLabel("INGRESE EL INICIO DE LA SERIE:");
lbl1.setBounds(20, 11, 199, 34);
contentPane.add(lbl1);

JLabel lbl2 = new JLabel("INGRESE EL FIN DE LA SERIE:");
lbl2.setBounds(20, 62, 177, 34);
contentPane.add(lbl2);

num1 = new JTextField();
num1.setBounds(229, 18, 86, 20);
contentPane.add(num1);
num1.setColumns(10);

num2 = new JTextField();
num2.setBounds(229, 69, 86, 20);
contentPane.add(num2);
num2.setColumns(10);

JLabel lbl3 = new JLabel("RESULTADO:");
lbl3.setBounds(26, 120, 149, 34);
contentPane.add(lbl3);

JButton btnMenu = new JButton("MENU");
btnMenu.setBounds(350, 181, 104, 23);
btnMenu.setIcon(new
ImageIcon(VentanaPrimos.class.getResource("/javax/swing/plaf/metal/icons/ocean/m
enu.gif")));
btnMenu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
VentanaPrincipal regresar=new VentanaPrincipal();
regresar.setVisible(true);
dispose();
10

}
});
contentPane.add(btnMenu);

JButton btnRESULTADO = new JButton("RESULTADO");
btnRESULTADO.setBounds(350, 17, 104, 23);
btnRESULTADO.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {

numero1 = num1.getText();
numero2 = num2.getText();
if(!isNumber(numero1) || !isNumber(numero2))
{
DialogoError error=new DialogoError();
error.setVisible(true);
num1.setText("");
num2.setText("");
}
else
{
numeroint1 = Integer.parseInt(num1.getText());
numeroint2 = Integer.parseInt(num2.getText());

if(numeroint1>=numeroint2)
{
DialogoError error=new DialogoError();
error.setVisible(true);
num1.setText("");
num2.setText("");
}
else
{
Hilo1 h1=new Hilo1(numeroint1,
numeroint2,lblRESULTADO);
Thread t1= new Thread(h1);
t1.start();
}
}

}
});
contentPane.add(btnRESULTADO);

JButton btnBorrar = new JButton("BORRAR");
btnBorrar.setBounds(350, 68, 104, 23);
btnBorrar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
num1.setText("");
num2.setText("");
lblRESULTADO.setText("");
}
});
contentPane.add(btnBorrar);

JButton btnSalir = new JButton("SALIR");
btnSalir.setBounds(226, 181, 89, 23);
btnSalir.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
11

System.exit(0);
}
});
btnSalir.setIcon(new
ImageIcon(VentanaPrimos.class.getResource("/javax/swing/plaf/metal/icons/ocean/p
aletteClose-pressed.gif")));
contentPane.add(btnSalir);

JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(126, 120, 328, 34);
contentPane.add(scrollPane);

lblRESULTADO = new JLabel("");
scrollPane.setViewportView(lblRESULTADO);
}
}

Cdigo Ventana Palndromos
import java.awt.BorderLayout;
import java.awt.Event;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.ImageIcon;
import java.awt.*;
import javax.swing.*;
import java.util.*;

public class VentanaPalindromos extends JFrame
{

private JPanel contentPane;
private JTextField num1;
private JTextField num2;
private JLabel lblRESULTADO;
private String numero1;
private String numero2;
private int numeroint1;
private int numeroint2;


class Hilo2 implements Runnable
{
private int inicio,fin;
private String rs="";
private String rserie="";
private JLabel lbl;

public Hilo2(int num1,int num2,JLabel jlbl)
{
12

inicio=num1;
fin=num2;
lbl=jlbl;
}

public void run()
{

int contador=0;
int i;

int numinverso = 0;
int div_entera;
int resto_div;
String serie="";
if(inicio>=0 && fin>0)
{
if(inicio<fin)
{
for(i=inicio;i<=fin;i++)
{
numinverso = 0;
div_entera = i;
resto_div = 0;
while (div_entera != 0)
{
resto_div = div_entera % 10;
div_entera = div_entera / 10;
numinverso = numinverso * 10 + resto_div;
}
if (i == numinverso)
{
try
{

Thread.currentThread();

Thread.sleep((long)(450));
}catch(InterruptedException
e)
{

System.out.println(e.getMessage());
}
serie=serie+" "+i;
}
lbl.setText(serie);
}

}

}
else
if(inicio<0 && fin<0)
{

if(Math.abs(inicio)>Math.abs(fin))
{
13


for(i=inicio;i<=fin;i++)
{
numinverso = 0;
div_entera = i;
resto_div = 0;
while (div_entera != 0)
{
resto_div = div_entera % 10;
div_entera = div_entera / 10;
numinverso = numinverso * 10 + resto_div;
}
if (i == numinverso)
{
try
{

Thread.currentThread();

Thread.sleep((long)(450));
}catch(InterruptedException
e)
{

System.out.println(e.getMessage());
}
serie=serie+" "+i;
}
lbl.setText(serie);
}


}
}
else
if(inicio<0 && fin>0)
{

for(i=1;i<=Math.abs(inicio);i++)
{
numinverso = 0;
div_entera = i;
resto_div = 0;
while (div_entera != 0)
{
resto_div = div_entera % 10;
div_entera = div_entera / 10;
numinverso = numinverso * 10 + resto_div;
}
if (i == numinverso)
{
try
{
Thread.currentThread();
Thread.sleep((long)(450));
}catch(InterruptedException e)
{
14


System.out.println(e.getMessage());
}
serie=serie+" -"+i;
}
lbl.setText(serie);
}


for(i=1;i<=fin;i++)
{
numinverso = 0;
div_entera = i;
resto_div = 0;
while (div_entera != 0)
{
resto_div = div_entera % 10;
div_entera = div_entera / 10;
numinverso = numinverso * 10 + resto_div;
}
if (i == numinverso)
{
try
{
Thread.currentThread();
Thread.sleep((long)(450));
}catch(InterruptedException e)
{

System.out.println(e.getMessage());
}
serie=serie+" "+i;
}
lbl.setText(serie);
}

}
}
}


public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
try
{
VentanaPalindromos frame = new
VentanaPalindromos();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
15



private static boolean isNumber(String n)
{
try
{
Integer.parseInt(n);
return true;
} catch (NumberFormatException nfe) {
return false;
}
}


public VentanaPalindromos()
{
setTitle("VENTANA PALINDROMOS");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 494, 250);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);

JLabel lbl1 = new JLabel("INGRESE EL INICIO DE LA SERIE:");
lbl1.setBounds(20, 11, 199, 34);
contentPane.add(lbl1);

JLabel lbl2 = new JLabel("INGRESE EL FIN DE LA SERIE:");
lbl2.setBounds(20, 62, 177, 34);
contentPane.add(lbl2);

num1 = new JTextField();
num1.setBounds(229, 18, 86, 20);
contentPane.add(num1);
num1.setColumns(10);

num2 = new JTextField();
num2.setBounds(229, 69, 86, 20);
contentPane.add(num2);
num2.setColumns(10);

JLabel lbl3 = new JLabel("RESULTADO:");
lbl3.setBounds(26, 120, 149, 34);
contentPane.add(lbl3);

JButton btnMenu = new JButton("MENU");
btnMenu.setBounds(350, 181, 104, 23);
btnMenu.setIcon(new
ImageIcon(VentanaPalindromos.class.getResource("/javax/swing/plaf/metal/icons/oc
ean/menu.gif")));
btnMenu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
VentanaPrincipal regresar=new VentanaPrincipal();
regresar.setVisible(true);
dispose();
}
});
16

contentPane.add(btnMenu);

JButton btnRESULTADO = new JButton("RESULTADO");
btnRESULTADO.setBounds(350, 17, 104, 23);
btnRESULTADO.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {

numero1 = num1.getText();
numero2 = num2.getText();
if(!isNumber(numero1) || !isNumber(numero2))
{
DialogoError error=new DialogoError();
error.setVisible(true);
num1.setText("");
num2.setText("");
}
else
{
numeroint1 = Integer.parseInt(num1.getText());
numeroint2 = Integer.parseInt(num2.getText());

if(numeroint1>=numeroint2)
{
DialogoError error=new DialogoError();
error.setVisible(true);
num1.setText("");
num2.setText("");
}
else
{
Hilo2 h2=new Hilo2(numeroint1,
numeroint2,lblRESULTADO);
Thread t2= new Thread(h2);
t2.start();
}
}

}
});
contentPane.add(btnRESULTADO);

JButton btnBorrar = new JButton("BORRAR");
btnBorrar.setBounds(350, 68, 104, 23);
btnBorrar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
num1.setText("");
num2.setText("");
lblRESULTADO.setText("");
}
});
contentPane.add(btnBorrar);

JButton btnSalir = new JButton("SALIR");
btnSalir.setBounds(226, 181, 89, 23);
btnSalir.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
17

});
btnSalir.setIcon(new
ImageIcon(VentanaPalindromos.class.getResource("/javax/swing/plaf/metal/icons/oc
ean/paletteClose-pressed.gif")));
contentPane.add(btnSalir);

JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(126, 120, 328, 34);
contentPane.add(scrollPane);

lblRESULTADO = new JLabel("");
scrollPane.setViewportView(lblRESULTADO);
}
}


Cdigo Panel Imagen.java
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.ImageIcon;
public class PanelImagen extends javax.swing.JPanel {
public PanelImagen(){
this.setSize(400,280);
}
@Override
public void paintComponent (Graphics g){
Dimension tamanio = getSize();
ImageIcon imagenFondo = new
ImageIcon(getClass().getResource("/img/imag.jpg"));
g.drawImage(imagenFondo.getImage(),0,0,tamanio.width,
tamanio.height, null);
setOpaque(false);
super.paintComponent(g);
}
}

Cdigo JFrame con Fondo.java
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Toolkit;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;
import java.awt.SystemColor;
public class JFrameConFondo extends JFrame {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
18

public void run() {
try {
JFrameConFondo frame = new JFrameConFondo();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public JFrameConFondo() {
setForeground(SystemColor.textHighlight);

setIconImage(Toolkit.getDefaultToolkit().getImage(JFrameConFondo.class.ge
tResource("/com/sun/java/swing/plaf/motif/icons/Inform.gif")));
setTitle("Informaci\u00F3n");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 432, 168);
PanelImagen p = new PanelImagen();
p.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(p);
p.setLayout(null);

JLabel lblRealizadoPor = new JLabel("REALIZADO POR:");
lblRealizadoPor.setForeground(Color.RED);
lblRealizadoPor.setFont(new Font("Calisto MT", Font.BOLD, 12));
lblRealizadoPor.setBounds(181, 21, 136, 27);
p.add(lblRealizadoPor);

JLabel lblFreddyAlvarez = new JLabel("FREDDY ALVAREZ");
lblFreddyAlvarez.setForeground(Color.BLUE);
lblFreddyAlvarez.setFont(new Font("Californian FB", Font.ITALIC,
15));
lblFreddyAlvarez.setBounds(210, 59, 196, 27);
p.add(lblFreddyAlvarez);


JButton btnOk = new JButton("OK");
btnOk.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
VentanaPrincipal prin=new VentanaPrincipal();
prin.setVisible(true);
dispose();
}
});
btnOk.setBounds(351, 96, 55, 23);
p.add(btnOk);
}
}

Cdigo Dilogo Error
import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
19

import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Toolkit;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


public class DialogoError extends JDialog {

private final JPanel contentPanel = new JPanel();

/**
* Launch the application.
*/
public static void main(String[] args) {
try {
DialogoError dialog = new DialogoError();
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* Create the dialog.
*/
public DialogoError() {

setIconImage(Toolkit.getDefaultToolkit().getImage(DialogoError.class.getR
esource("/javax/swing/plaf/metal/icons/Warn.gif")));
setTitle("ERROR!!!");
setBounds(100, 100, 310, 116);
getContentPane().setLayout(new BorderLayout());
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.CENTER);
contentPanel.setLayout(null);

JLabel lblIngreseValoresCorrectos = new JLabel("ERROR!!! INGRESE
VALORES CORRECTOS");
lblIngreseValoresCorrectos.setFont(new Font("Tahoma", Font.BOLD,
11));
lblIngreseValoresCorrectos.setForeground(new Color(255, 0, 0));
lblIngreseValoresCorrectos.setBounds(36, 11, 360, 25);
contentPanel.add(lblIngreseValoresCorrectos);
{
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
getContentPane().add(buttonPane, BorderLayout.SOUTH);
{
JButton okButton = new JButton("OK");
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
dispose();
20

}
});
okButton.setActionCommand("OK");
buttonPane.add(okButton);
getRootPane().setDefaultButton(okButton);
}
}
}
}
Ventana Principal

Ventana Primos

21


Ventana Palndromos


Ventana Dilogo Error



22


Ventana JFrame con Fondo

Vista Ejecucin

23

Das könnte Ihnen auch gefallen