Results 1 to 3 of 3
  1. #1
    Hikari is offline Member
    Join Date
    Dec 2008
    Posts
    8
    Rep Power
    0

    Default Timed alerts in JTable

    I was wondering if anyone could help me out with this. Basically, I have a JTable with a column of times in it. How would I go about having a sort of reminder alert a minute before each allocated time, containing the name and other info from the rest of that row? And then being able to either snooze it for a minute or cancel it?

    Another question, is there any way to have the format type of the column as time format?

    I posted my code in another thread already, but since I've amended it somewhat, here it is.

    Thank you in advance. :D Sorry for any mistakes I may have made.

    Java Code:
    package coursework;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.awt.Dialog.*;
    import javax.swing.JOptionPane.*;
    
    class Enquiry {
        private int number;
        private int time;
        private String name;
        private String branch;
        private String enquiry;
        public Enquiry(int m, int t, String n, String b, String q) {
            number = m;
            name = n;
            branch = b;
            time = t;
            enquiry = q;
        }
    
        public Enquiry() {
            this(0, 0, "", "", "");
        }
        public int getNumber() {
            return number;
        }
         public int getTime()  {
            return time;
        }
        public String getName() {
            return name;   
        }
        public String getBranch() {
            return branch;
        }
        public String getEnquiry() {
            return enquiry;
        }
        
          }
    
    public class GUI2 extends JFrame  {
    
        ArrayList enquiries = new ArrayList();
        JTextField txtName = new JTextField(12);
        JTextField txtBranch = new JTextField(20);
        JTextField txtEnquiry = new JTextField(30);
        JTextField txtNumber = new JTextField(8);
        JTextField txtTime = new JTextField(4);
        JButton btnAdd = new JButton("Add"),
        btnDelete = new JButton("Delete");
        JTable tab = new JTable();
    
        DefaultTableModel tabMod = new DefaultTableModel();
    
        public GUI2() {
            super("Stock Enquiries Log");
            tab.setModel(tabMod);
            tabMod.addColumn("Name");
            tabMod.addColumn("Telephone number");
            tabMod.addColumn("Branch");
            tabMod.addColumn("Callback time");
            tabMod.addColumn("Enquiry");
            tabMod.addColumn("Dealt with");
            TableColumn tc = tab.getColumnModel().getColumn(5);
            tc.setCellRenderer(tab.getDefaultRenderer(Boolean.class));
            tc.setCellEditor(tab.getDefaultEditor(Boolean.class));
            tab.setAutoCreateRowSorter(true);
    
    
            TableColumn column = null;
            for (int i = 0; i < 5; i++) {
        column = tab.getColumnModel().getColumn(i);
        if (i == 4) {
            column.setPreferredWidth(550);
        }
        else if (i == 3) {
            column.setPreferredWidth(100);
        }
        else if (i == 2) {
            column.setPreferredWidth(300);
        }
        else {
            column.setPreferredWidth(190);
        }
    }
    
            loadInitialEnquiries();
    
            btnAdd.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                  
                 try  {addEnquiry();
                 }
                   catch (NumberFormatException nfe) {
                {
                        JOptionPane.showMessageDialog(null, "Please input all the information required correctly");
                }
                
                    }
                }
           
            });
    
            btnDelete.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    deleteEnquiry();
                }
            });
    
            
            JPanel top = new JPanel();
            top.add(btnAdd);
            top.add(new JLabel("Name"));
            top.add(txtName);
            top.add(new JLabel("Telehpone number"));
            top.add(txtNumber);
            top.add(new JLabel("Branch"));
            top.add(txtBranch);
            top.add(new JLabel("Callback Time"));
            top.add(txtTime);
            top.add(new JLabel("Enquiry"));
            top.add(txtEnquiry);
            add ("North", top);
            JPanel bottom = new JPanel();
            bottom.add(btnDelete);
            add ("South", bottom);
            setVisible(true);
            getContentPane().add(new JScrollPane(tab));
         
        }
        
        public void deleteEnquiry() {
    
            int response;
    
            response = JOptionPane.showConfirmDialog(null, "Delete selected record(s)?");
          if (response == JOptionPane.YES_OPTION)
          {
              
            int [] rows = tab.getSelectedRows();
            for (int i = 0; i < rows.length; i++) {
                tabMod.removeRow(rows[i] - i); 
                enquiries.remove(rows[i] - i);
            }
          }
            
            else System.out.println("");
        }
    
    
        public void addEnquiry() {
            String [] row = new String [5];
            Enquiry newEnq = new Enquiry
                    (Integer.parseInt(txtNumber.getText()), (Integer.parseInt(txtTime.getText())),
                    txtName.getText(),
                    txtBranch.getText(), txtEnquiry.getText()
                    );
    
            enquiries.add(newEnq);
            row[0] = newEnq.getName();
            row[1] = Integer.toString(newEnq.getNumber());
            row[2] = newEnq.getBranch();
            row[3] = Integer.toString(newEnq.getTime());
            row[4] = newEnq.getEnquiry();
            tabMod.addRow(row);
        }
        
        public void loadInitialEnquiries() {
            BufferedReader br = null;
            try {
                    br = new BufferedReader(
                     new FileReader("stockEnquiryLog.txt"));
    
                    String s;
                    int colCount = tab.getColumnCount();
                    String[] row = new String[colCount];
    
                    while ((s = br.readLine()) != null) {
                    if(s.equals("<stock_enquiry>")) {
                        row[0] = br.readLine();  
                        row[1] = br.readLine();  
                        row[2] = br.readLine(); 
                        row[3] = br.readLine();  
                        row[4] = br.readLine(); 
                        tabMod.addRow(row);
                    }
        }
                br.close();
                    }            
                    catch(IOException e) {
                    System.out.println("I/O error: " +
                                    e.getMessage());
                        }
        }
           
        public void loadProductsIntoTable() {
            tabMod.setRowCount(0);
    
            String [] row = new String [5];
            for (Iterator i = enquiries.iterator(); i.hasNext();) {
                Enquiry temp = (Enquiry) i.next();
                row[0] = temp.getName();
                row[1] = Integer.toString(temp.getNumber());
                row[2] = temp.getBranch();
                row[3] = Integer.toString(temp.getTime());
                row[4] = temp.getEnquiry();
                tabMod.addRow(row);
            }
        }
    
        public void Alerts(java.lang.String text, int time) {
    
        }
    
    
    
      
        public static void main(String [] a){
            GUI2 me = new GUI2();
            PopAlert myFrame = new PopAlert();
    
            me.addWindowListener(new WindowAdapter() {
                @Override
                public void windowClosing(WindowEvent e) {
                    System.exit(0) ;
                }
    
            });
            myFrame.addWindowListener(new WindowAdapter(){
                public void windowClosing(WindowEvent e) {
                    System.exit(0) ;
                }
            });
    
            me.pack();
            me.setVisible(true);
        }
    }

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default links ...

    Never done it before, but here are some links that might help...

    Swing timer API (6.0)
    Timer (Java Platform SE 6)

    How to use swing timers:
    How to Use Swing Timers (The Java™ Tutorials > Creating a GUI with JFC/Swing > Using Other Swing Features)

    Using timers in swing applications:
    Using Timers in Swing Applications

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    Hikari is offline Member
    Join Date
    Dec 2008
    Posts
    8
    Rep Power
    0

    Default

    Thank you, but I feel I still need some pointers, or someone who can guide me to the right direction.

    I'll keep trying, but anyone with any suggestions would be well appreciated.

Similar Threads

  1. Raising alerts based on query result across the network
    By srinivasan.sr in forum Networking
    Replies: 2
    Last Post: 07-22-2008, 06:47 AM
  2. Replies: 1
    Last Post: 06-30-2008, 07:14 AM
  3. Replies: 2
    Last Post: 05-15-2008, 10:15 AM
  4. how to display the alerts in table
    By geeta_ravikanti in forum JDBC
    Replies: 4
    Last Post: 04-04-2008, 06:45 AM
  5. Replies: 1
    Last Post: 08-07-2007, 06:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •