Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JMenu;
- import javax.swing.JMenuBar;
- import javax.swing.JMenuItem;
- import javax.swing.JScrollPane;
- import javax.swing.JTextField;
- import javax.swing.table.DefaultTableModel;
- import javax.swing.JSeparator;
- import javax.swing.JTable;
- import javax.swing.JLabel;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- public class problemaAgen {
- private JTable table;
- private JFrame frmAgenda;
- JMenuBar menubar =new JMenuBar();
- JMenu file;
- JMenuItem Borrar,Guardar,Buscar,Modificar;
- private JTextField textNom;
- private JTextField textmatri;
- private JTextField textApe;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- problemaAgen window = new problemaAgen();
- window.frmAgenda.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the application.
- */
- public problemaAgen() {
- initialize();
- }
- /**
- * Initialize the contents of the frame.
- */
- private void initialize() {
- crearmenu();
- frmAgenda = new JFrame();
- frmAgenda.setTitle("Agenda");
- frmAgenda.setBounds(100, 100, 450, 300);
- frmAgenda.setJMenuBar(menubar);
- frmAgenda.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frmAgenda.getContentPane().setLayout(null);
- textNom = new JTextField();
- textNom.setBounds(10, 38, 100, 20);
- frmAgenda.getContentPane().add(textNom);
- textNom.setColumns(10);
- textmatri = new JTextField();
- textmatri.setBounds(140, 38, 100, 20);
- frmAgenda.getContentPane().add(textmatri);
- textmatri.setColumns(10);
- textApe = new JTextField();
- textApe.setBounds(10, 90, 100, 20);
- frmAgenda.getContentPane().add(textApe);
- textApe.setColumns(10);
- JSeparator separator = new JSeparator();
- separator.setBounds(10, 121, 424, 2);
- frmAgenda.getContentPane().add(separator);
- JLabel lblNewLabel = new JLabel("nombre");
- lblNewLabel.setBounds(10, 13, 100, 14);
- frmAgenda.getContentPane().add(lblNewLabel);
- JLabel lblNewLabel_1 = new JLabel("matricula ");
- lblNewLabel_1.setBounds(140, 13, 100, 14);
- frmAgenda.getContentPane().add(lblNewLabel_1);
- JLabel lblNewLabel_2 = new JLabel("apellido");
- lblNewLabel_2.setBounds(10, 65, 46, 14);
- frmAgenda.getContentPane().add(lblNewLabel_2);
- String[][] filas= {};
- String[] columnas= {"Matricula","Nombre","Apellido"};
- DefaultTableModel mod= new DefaultTableModel(filas,columnas);
- table = new JTable(mod);
- JScrollPane scroll = new JScrollPane(table);
- scroll.setBounds(10, 130, 400, 200);
- frmAgenda.getContentPane().add(scroll);
- }
- void crearmenu() {
- // TODO Auto-generated method stub..
- file=new JMenu("File");
- menubar.add(file);
- Borrar=new JMenuItem("Borrar");
- Borrar.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- DefaultTableModel mid =(DefaultTableModel) table.getModel ();
- mid.removeRow(table.getSelectedRow());
- }
- });
- file.add(Borrar);
- Buscar=new JMenuItem("Buscar");
- file.add(Buscar);
- Guardar=new JMenuItem("Guardar");
- Guardar.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- DefaultTableModel midd =(DefaultTableModel) table.getModel ();
- int matri=Integer.parseInt(textmatri.getText());
- String nom=textNom.getText();
- String ape=textApe.getText();
- Object nombre[]= {matri,nom,ape};
- midd.addRow(nombre);
- }
- });
- file.add(Guardar);
- Modificar=new JMenuItem("Modificar");
- file.add(Modificar);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment