Advertisement
Guest User

ReNcOoR

a guest
Nov 30th, 2010
744
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.64 KB | None | 0 0
  1. import java.awt.Dimension;
  2. import java.awt.Toolkit;
  3. import java.awt.event.*;
  4. import java.awt.*;
  5.  
  6. import javax.swing.*;
  7.  
  8.  
  9.  
  10. public class pruebalaptop extends JFrame implements ActionListener{
  11.    
  12.        
  13.         private JLabel label;
  14.         private JButton boton, boton2;
  15.         private lap2 f = new lap2();
  16.         private lap3 g = new lap3();
  17.        
  18.         public pruebalaptop (){
  19.            
  20.             super("Example_Class");
  21.             this.setSize(450, 200);
  22.             centrarventana();
  23.             this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  24.             this.setResizable(true);
  25.             this.setLayout(null);
  26.            
  27.             creargui();
  28.                
  29.            
  30.         }
  31.        
  32.         private void creargui (){
  33.            
  34.             label = new JLabel("Bienvenido selecciona un boton");
  35.             boton = new JButton("Crear objetos laptop");
  36.             boton2 = new JButton("Modificar objetos laptop");
  37.            
  38.             this.add(label);
  39.             label.setBounds(140, 40, 200, 25);
  40.             this.add(boton);
  41.             boton.setBounds(10, 90, 200, 25);
  42.             this.add(boton2);
  43.             boton2.setBounds(230, 90, 200, 25);
  44.            
  45.             boton.addActionListener(this);
  46.             boton2.addActionListener(this);
  47.            
  48.            
  49.            
  50.         }
  51.        
  52.         private void centrarventana (){
  53.            
  54.             Dimension pantalla = Toolkit.getDefaultToolkit().getScreenSize();
  55.            
  56.             Dimension ventana = getSize();
  57.            
  58.             setLocation((pantalla.width - ventana.width) /2, (pantalla.height - ventana.height) /2);
  59.         }
  60.        
  61.        
  62.         public static void main(String[] args) {
  63.            
  64.            
  65.             pruebalaptop vp = new pruebalaptop();
  66.             vp.setVisible(true);
  67.            
  68.            
  69.            
  70.            
  71.  
  72.         }
  73.        
  74.        
  75.  
  76.        
  77.         public void actionPerformed(ActionEvent e) {
  78.            
  79.             if (e.getSource() == boton)
  80.                 f.setVisible(true);
  81.             else if (e.getSource() == boton2)
  82.                 g.setVisible(true);
  83.         }
  84.  
  85.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement