carlos0722

Untitled

Mar 18th, 2021
647
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.71 KB | None | 0 0
  1. import java.awt.EventQueue;
  2. import javax.swing.JFrame;
  3. import javax.swing.JMenu;
  4. import javax.swing.JMenuBar;
  5. import javax.swing.JMenuItem;
  6. import javax.swing.JScrollPane;
  7. import javax.swing.JTextField;
  8. import javax.swing.table.DefaultTableModel;
  9. import javax.swing.JSeparator;
  10. import javax.swing.JTable;
  11. import javax.swing.JLabel;
  12. import java.awt.event.ActionListener;
  13. import java.awt.event.ActionEvent;
  14.  
  15. public class problemaAgen {
  16.  
  17.     private JTable table;
  18.     private JFrame frmAgenda;
  19.     JMenuBar menubar =new JMenuBar();
  20.     JMenu file;
  21.     JMenuItem Borrar,Guardar,Buscar,Modificar;
  22.     private JTextField textNom;
  23.     private JTextField textmatri;
  24.     private JTextField textApe;
  25.    
  26.     /**
  27.      * Launch the application.
  28.      */
  29.     public static void main(String[] args) {
  30.         EventQueue.invokeLater(new Runnable() {
  31.             public void run() {
  32.                 try {
  33.                     problemaAgen window = new problemaAgen();
  34.                     window.frmAgenda.setVisible(true);
  35.                 } catch (Exception e) {
  36.                     e.printStackTrace();
  37.                 }
  38.             }
  39.         });
  40.     }
  41.  
  42.     /**
  43.      * Create the application.
  44.      */
  45.     public problemaAgen() {
  46.         initialize();
  47.     }
  48.  
  49.     /**
  50.      * Initialize the contents of the frame.
  51.      */
  52.     private void initialize() {
  53.         crearmenu();
  54.        
  55.         frmAgenda = new JFrame();
  56.         frmAgenda.setTitle("Agenda");
  57.         frmAgenda.setBounds(100, 100, 450, 300);
  58.         frmAgenda.setJMenuBar(menubar);
  59.         frmAgenda.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  60.         frmAgenda.getContentPane().setLayout(null);
  61.        
  62.         textNom = new JTextField();
  63.         textNom.setBounds(10, 38, 100, 20);
  64.         frmAgenda.getContentPane().add(textNom);
  65.         textNom.setColumns(10);
  66.        
  67.         textmatri = new JTextField();
  68.         textmatri.setBounds(140, 38, 100, 20);
  69.         frmAgenda.getContentPane().add(textmatri);
  70.         textmatri.setColumns(10);
  71.        
  72.         textApe = new JTextField();
  73.         textApe.setBounds(10, 90, 100, 20);
  74.         frmAgenda.getContentPane().add(textApe);
  75.         textApe.setColumns(10);
  76.        
  77.         JSeparator separator = new JSeparator();
  78.         separator.setBounds(10, 121, 424, 2);
  79.         frmAgenda.getContentPane().add(separator);
  80.        
  81.         JLabel lblNewLabel = new JLabel("nombre");
  82.         lblNewLabel.setBounds(10, 13, 100, 14);
  83.         frmAgenda.getContentPane().add(lblNewLabel);
  84.        
  85.         JLabel lblNewLabel_1 = new JLabel("matricula ");
  86.         lblNewLabel_1.setBounds(140, 13, 100, 14);
  87.         frmAgenda.getContentPane().add(lblNewLabel_1);
  88.        
  89.         JLabel lblNewLabel_2 = new JLabel("apellido");
  90.         lblNewLabel_2.setBounds(10, 65, 46, 14);
  91.         frmAgenda.getContentPane().add(lblNewLabel_2);
  92.    
  93.  
  94.         String[][] filas= {};
  95.         String[] columnas= {"Matricula","Nombre","Apellido"};
  96.         DefaultTableModel mod= new DefaultTableModel(filas,columnas);
  97.          table = new JTable(mod);  
  98.         JScrollPane scroll = new JScrollPane(table);
  99.         scroll.setBounds(10, 130, 400, 200);
  100.         frmAgenda.getContentPane().add(scroll);
  101.        
  102.        
  103.     }
  104.  
  105.     void crearmenu() {
  106.         // TODO Auto-generated method stub..
  107.        
  108.         file=new JMenu("File");
  109.         menubar.add(file);
  110.        
  111.         Borrar=new JMenuItem("Borrar");
  112.         Borrar.addActionListener(new ActionListener() {
  113.             public void actionPerformed(ActionEvent e) {
  114.                 DefaultTableModel mid =(DefaultTableModel) table.getModel ();
  115.                 mid.removeRow(table.getSelectedRow());
  116.                
  117.             }
  118.         });
  119.         file.add(Borrar);
  120.        
  121.         Buscar=new JMenuItem("Buscar");
  122.         file.add(Buscar);
  123.        
  124.         Guardar=new JMenuItem("Guardar");
  125.         Guardar.addActionListener(new ActionListener() {
  126.             public void actionPerformed(ActionEvent e) {
  127.                 DefaultTableModel midd =(DefaultTableModel) table.getModel ();
  128.                 int matri=Integer.parseInt(textmatri.getText());
  129.                 String nom=textNom.getText();
  130.                 String ape=textApe.getText();
  131.                 Object nombre[]= {matri,nom,ape};
  132.                 midd.addRow(nombre);
  133.                
  134.             }
  135.         });
  136.         file.add(Guardar);
  137.        
  138.         Modificar=new JMenuItem("Modificar");
  139.         file.add(Modificar);
  140.        
  141.     }
  142. }
  143.  
Advertisement
Add Comment
Please, Sign In to add comment