Results 1 to 8 of 8
  1. #1
    JPCP13 is offline Member
    Join Date
    Aug 2011
    Posts
    4
    Rep Power
    0

    Default Planner Application

    Hello. I'm creating a program that finds the
    common free time of 2 people and determine a schedule when they can meet and
    discuss. I have a problem on my GUI part. The program should feature that user can enter their weekly schedules into the program, the input
    must take the schedule that represents their busy times, program must also ask for the name of user, earliest possible time to arrive at school, and latest time possible to leave school. The Program creates a detailed schedule of their common free time. The following are the list of computations that the program must do:
    a. Summarize the time periods that are available
    b. Round up to either --:30 or --:00 periods.
    c. Calculate the duration (in hours and minutes)

    Here's the codes of my logic:
    Java Code:
    package logic;
    
    public class Logic
    {
        public String[][] initSched(String eta, String etl) {
    	String[][] empty = new String[48][7];
    	int ETA = Integer.parseInt(eta);
    	int ETL = Integer.parseInt(etl);
    	int starter = 0;
    	for (int i = 0; i < 48; i++) {
    	    if (i < 20) {
    		empty[i][0] = new StringBuilder().append("0").append
    				  (starter).toString();
    		if (i == 0)
    		    empty[i][0] = "0000";
    		else if (i == 1)
    		    empty[i][0] = "0030";
    	    } else
    		empty[i][0] = new StringBuilder().append(starter).append
    				  ("").toString();
    	    starter += 30;
    	    if (starter % 100 == 60) {
    		starter -= 60;
    		starter += 100;
    	    }
    	}
    	for (int i = 0; i < 48; i++) {
    	    for (int j = 1; j < 7; j++)
    		empty[i][j] = "FREE";
    	}
    	int ETAIndex = (ETA / 100 * 60 + ETA % 100) / 30;
    	if (ETA % 100 > 30)
    	    ETAIndex++;
    	else if (ETA % 100 < 30 && ETA % 100 > 0)
    	    ETAIndex++;
    	int ETLIndex = (ETL / 100 * 60 + ETL % 100) / 30;
    	if (ETL % 100 > 30)
    	    ETLIndex++;
    	else if (ETL % 100 < 30 && ETL % 100 > 0)
    	    ETLIndex++;
    	ETLIndex++;
    	for (int i = ETAIndex - 1; i >= 0; i--) {
    	    for (int j = 1; j < 7; j++)
    		empty[i][j] = "-";
    	}
    	for (int i = ETLIndex; i < 48; i++) {
    	    for (int j = 1; j < 7; j++)
    		empty[i][j] = "-";
    	}
    	return empty;
        }
    
        public boolean IsValidSched(String in, String out) {
    	if (Integer.parseInt(in) < Integer.parseInt(out))
    	    return true;
    	return false;
        }
    
        public String[][] addSched(String[][] input, String sTime, String eTime,
    			       int Day) {
    	String[][] output = input;
    	int iStart = Integer.parseInt(sTime);
    	int iEnd = Integer.parseInt(eTime);
    	int StartIndex = iStart / 100 * 2;
    	int EndIndex = iEnd / 100 * 2;
    	StartIndex = (iStart / 100 * 60 + iStart % 100) / 30;
    	if (iStart % 100 > 30)
    	    StartIndex++;
    	else if (iStart % 100 < 30 && iStart % 100 > 0)
    	    StartIndex++;
    	EndIndex = (iEnd / 100 * 60 + iEnd % 100) / 30;
    	if (iEnd % 100 > 30)
    	    EndIndex++;
    	else if (iEnd % 100 < 30 && iEnd % 100 > 0)
    	    EndIndex++;
    	for (int i = StartIndex; i <= EndIndex; i++) {
    	    if (!input[i][Day].equals("-"))
    		input[i][Day] = "XXXXXX";
    	}
    	return output;
        }
    
        public String[][] FreeTime(String[][] sched1, String[][] sched2) {
    	String[][] empty = new String[48][7];
    	int starter = 0;
    	for (int i = 0; i < 48; i++) {
    	    if (i < 20) {
    		empty[i][0] = new StringBuilder().append("0").append
    				  (starter).toString();
    		if (i == 0)
    		    empty[i][0] = "0000";
    		else if (i == 1)
    		    empty[i][0] = "0030";
    	    } else
    		empty[i][0] = new StringBuilder().append(starter).append
    				  ("").toString();
    	    starter += 30;
    	    if (starter % 100 == 60) {
    		starter -= 60;
    		starter += 100;
    	    }
    	}
    	for (int i = 0; i < 48; i++) {
    	    for (int j = 1; j < 7; j++) {
    		if (sched1[i][j].equals("FREE") && sched2[i][j].equals("FREE"))
    		    empty[i][j] = "FREE";
    		else
    		    empty[i][j] = "";
    	    }
    	}
    	return empty;
        }
    
        public String FreeTime(String[][] freesched1) {
    	String message = "";
    	String tempMessage = "";
    	int StartFree = 0;
    	int EndFree = 0;
    	for (int j = 1; j < 7; j++) {
    	    switch (j) {
    	    case 1:
    		message = new StringBuilder().append(message).append
    			      ("Monday:\n").toString();
    		break;
    	    case 2:
    		message = new StringBuilder().append(message).append
    			      ("Tuesday:\n").toString();
    		break;
    	    case 3:
    		message = new StringBuilder().append(message).append
    			      ("Wednesday:\n").toString();
    		break;
    	    case 4:
    		message = new StringBuilder().append(message).append
    			      ("Thursday:\n").toString();
    		break;
    	    case 5:
    		message = new StringBuilder().append(message).append
    			      ("Friday:\n").toString();
    		break;
    	    case 6:
    		message = new StringBuilder().append(message).append
    			      ("Saturday:\n").toString();
    		break;
    	    }
    	    for (int i = 0; i < 48; i++) {
    		if (freesched1[i][j].equals("FREE")) {
    		    if (StartFree == 0) {
    			StartFree = i;
    			StartFree++;
    		    }
    		    EndFree = i;
    		} else {
    		    StartFree = 0;
    		    EndFree = 0;
    		    message = new StringBuilder().append(message).append
    				  (tempMessage).toString();
    		    tempMessage = "";
    		}
    		if (StartFree != 0 && EndFree != 0) {
    		    int FreeTimeFrom;
    		    if (StartFree % 2 == 0)
    			FreeTimeFrom = (StartFree - 1) / 2 * 100 + 30;
    		    else
    			FreeTimeFrom = StartFree / 2 * 100;
    		    int FreeTimeTo;
    		    if (EndFree % 2 != 0)
    			FreeTimeTo = (EndFree - 1) / 2 * 100 + 30;
    		    else
    			FreeTimeTo = EndFree / 2 * 100;
    		    tempMessage
    			= new StringBuilder().append(FreeTimeFrom).append
    			      (" - ").append
    			      (FreeTimeTo).append
    			      (" (").append
    			      (Math.abs(computeForDiff(FreeTimeFrom,
    						       FreeTimeTo) / 100))
    			      .append
    			      ("hrs and ").append
    			      (Math.abs(computeForDiff(FreeTimeTo,
    						       FreeTimeFrom) % 100))
    			      .append
    			      ("mins)\n").toString();
    		}
    	    }
    	}
    	return message;
        }
    
        private int computeForDiff(int one, int two) {
    	int answer = two - one;
    	if (answer % 100 == 70)
    	    answer -= 40;
    	return answer;
        }
    
        public void PrintSched(String[][] sched) {
    	for (int i = 0; i < 48; i++) {
    	    for (int j = 0; j < 7; j++)
    		System.out.print(new StringBuilder().append(sched[i][j]).append
    				     (" ").toString());
    	    System.out.println("");
    	}
        }
    }
    while my GUI part code is my problem.

    Java Code:
    package logic;
    
    
    import java.awt.Container;
    import java.awt.event.*;
    import java.io.PrintStream;
    import javax.swing.*;
    import javax.swing.table.DefaultTableModel;
    import logic.Logic;
    
    public class GUI extends JFrame
    {
    
        public GUI()
        {
            Logic logic = new Logic();
            String name1 = JOptionPane.showInputDialog("Name of First User");
            String ETA1 = JOptionPane.showInputDialog("ETA of First User Military Time (HHMM)");
            String ETL1 = JOptionPane.showInputDialog("ETL of First User Military Time (HHMM)");
            String name2 = JOptionPane.showInputDialog("Name of Second User");
            String ETA2 = JOptionPane.showInputDialog("ETA of Second User Military Time (HHMM)");
            String ETL2 = JOptionPane.showInputDialog("ETL of Second User Military Time (HHMM)");
            initComponents();
            jPanel2.setBorder(BorderFactory.createTitledBorder((new StringBuilder()).append(name1).append("'s Schedule").toString()));
            jPanel3.setBorder(BorderFactory.createTitledBorder((new StringBuilder()).append(name2).append("'s Schedule").toString()));
            jComboBox1.setModel(new DefaultComboBoxModel(new String[] {
                name1, name2
            }));
            sched1 = logic.initSched(ETA1, ETL1);
            jTable1.setModel(new DefaultTableModel(sched1, new String[] {
                "Time", "M", "T", "W", "H", "F", "S"
            }));
            sched2 = logic.initSched(ETA2, ETL2);
            jTable2.setModel(new DefaultTableModel(sched2, new String[] {
                "Time", "M", "T", "W", "H", "F", "S"
            }));
            setVisible(true);
        }
    
        private void initComponents()
        {
            jPanel2 = new JPanel();
            jScrollPane1 = new JScrollPane();
            jTable1 = new JTable();
            jPanel1 = new JPanel();
            jTextField2 = new JTextField();
            jTextField1 = new JTextField();
            jComboBox1 = new JComboBox();
            jButton1 = new JButton();
            jLabel1 = new JLabel();
            jLabel2 = new JLabel();
            jLabel3 = new JLabel();
            jComboBox2 = new JComboBox();
            jLabel4 = new JLabel();
            jPanel3 = new JPanel();
            jScrollPane2 = new JScrollPane();
            jTable2 = new JTable();
            jButton2 = new JButton();
            setDefaultCloseOperation(3);
            jPanel2.setBorder(BorderFactory.createTitledBorder("XXX"));
            jPanel2.setName("");
            jPanel2.setLayout(new BoxLayout(jPanel2, 2));
            jTable1.setModel(new DefaultTableModel(new Object[][] {
                new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }
            }, new String[] {
                "Time", "M", "T", "W", "H", "F", "S"
            }) {
    
                public Class getColumnClass(int columnIndex)
                {
                    return types[columnIndex];
                }
    
                public boolean isCellEditable(int rowIndex, int columnIndex)
                {
                    return canEdit[columnIndex];
                }
    
                Class types[] = {
                    java/lang/String, java/lang/String, java/lang/String, java/lang/String, java/lang/String, java/lang/String, java/lang/String
                };
                boolean canEdit[] = {
                    false, false, false, false, false, false, false
                };
                final GUI this$0;
    
                
                {
                    this$0 = GUI.this;
                    super(x0, x1);
                }
            }
    );
            jScrollPane1.setViewportView(jTable1);
            jPanel2.add(jScrollPane1);
            jPanel1.setBorder(BorderFactory.createTitledBorder("Add Schedule"));
            jPanel1.setLayout(null);
            jTextField2.setText("Format should be HHMM (Military Time) (e.g. 0900)");
            jTextField2.addFocusListener(new FocusAdapter() {
    
                public void focusGained(FocusEvent evt)
                {
                    jTextField2FocusGained(evt);
                }
    
                final GUI this$0;
    
                
                {
                    this$0 = GUI.this;
                    super();
                }
            }
    );
            jPanel1.add(jTextField2);
            jTextField2.setBounds(100, 80, 300, 20);
            jTextField1.setText("Format should be HHMM (Military Time) (e.g. 0800)");
            jTextField1.addFocusListener(new FocusAdapter() {
    
                public void focusGained(FocusEvent evt)
                {
                    jTextField1FocusGained(evt);
                }
    
                final GUI this$0;
    
                
                {
                    this$0 = GUI.this;
                    super();
                }
            }
    );
            jPanel1.add(jTextField1);
            jTextField1.setBounds(100, 50, 300, 20);
            jPanel1.add(jComboBox1);
            jComboBox1.setBounds(100, 20, 120, 20);
            jButton1.setText("Add Schedule");
            jButton1.addActionListener(new ActionListener() {
    
                public void actionPerformed(ActionEvent evt)
                {
                    jButton1ActionPerformed(evt);
                }
    
                final GUI this$0;
    
                
                {
                    this$0 = GUI.this;
                    super();
                }
            }
    );
            jPanel1.add(jButton1);
            jButton1.setBounds(100, 110, 170, 23);
            jLabel1.setText("To:");
            jPanel1.add(jLabel1);
            jLabel1.setBounds(10, 80, 80, 14);
            jLabel2.setText("User:");
            jPanel1.add(jLabel2);
            jLabel2.setBounds(10, 20, 80, 14);
            jLabel3.setText("From:");
            jPanel1.add(jLabel3);
            jLabel3.setBounds(10, 50, 80, 14);
            jComboBox2.setModel(new DefaultComboBoxModel(new String[] {
                "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
            }));
            jPanel1.add(jComboBox2);
            jComboBox2.setBounds(280, 20, 120, 20);
            jLabel4.setText("Day:");
            jPanel1.add(jLabel4);
            jLabel4.setBounds(230, 20, 80, 14);
            jPanel3.setBorder(BorderFactory.createTitledBorder("XXX"));
            jPanel3.setName("");
            jPanel3.setLayout(new BoxLayout(jPanel3, 2));
            jTable2.setModel(new DefaultTableModel(new Object[][] {
                new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }
            }, new String[] {
                "Time", "M", "T", "W", "H", "F", "S"
            }) {
    
                public Class getColumnClass(int columnIndex)
                {
                    return types[columnIndex];
                }
    
                public boolean isCellEditable(int rowIndex, int columnIndex)
                {
                    return canEdit[columnIndex];
                }
    
                Class types[] = {
                    java/lang/String, java/lang/String, java/lang/String, java/lang/String, java/lang/String, java/lang/String, java/lang/String
                };
                boolean canEdit[] = {
                    false, false, false, false, false, false, false
                };
                final GUI this$0;
    
                
                {
                    this$0 = GUI.this;
                    super(x0, x1);
                }
            }
    );
            jScrollPane2.setViewportView(jTable2);
            jPanel3.add(jScrollPane2);
            jButton2.setText("Compute for Free Time");
            jButton2.addActionListener(new ActionListener() {
    
                public void actionPerformed(ActionEvent evt)
                {
                    jButton2ActionPerformed(evt);
                }
    
                final GUI this$0;
    
                
                {
                    this$0 = GUI.this;
                    super();
                }
            }
    );
            GroupLayout layout = new GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(jPanel2, -2, -1, -2).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jPanel3, -2, -1, -2)).addGroup(layout.createSequentialGroup().addComponent(jPanel1, -2, 420, -2).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(jButton2, -2, 274, -2))).addContainerGap(-1, 32767)));
            layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jPanel1, -2, 147, -2).addGroup(layout.createSequentialGroup().addGap(11, 11, 11).addComponent(jButton2))).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, -1, 32767).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, -2, 637, -2).addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, -2, 637, -2)).addContainerGap()));
            pack();
        }
    
        private void jButton1ActionPerformed(ActionEvent evt)
        {
            Logic logic = new Logic();
            if(logic.IsValidSched(jTextField1.getText(), jTextField2.getText()))
            {
                if(jComboBox1.getSelectedIndex() == 0)
                {
                    sched1 = logic.addSched(sched1, jTextField1.getText(), jTextField2.getText(), jComboBox2.getSelectedIndex() + 1);
                    jTable1.setModel(new DefaultTableModel(sched1, new String[] {
                        "Time", "M", "T", "W", "H", "F", "S"
                    }));
                } else
                if(jComboBox1.getSelectedIndex() == 1)
                {
                    sched2 = logic.addSched(sched2, jTextField1.getText(), jTextField2.getText(), jComboBox2.getSelectedIndex() + 1);
                    jTable2.setModel(new DefaultTableModel(sched2, new String[] {
                        "Time", "M", "T", "W", "H", "F", "S"
                    }));
                } else
                {
                    System.out.println("ALKJSDLAs");
                }
            } else
            {
                new JOptionPane();
                JOptionPane.showMessageDialog(null, "Please make sure that From is bigger than To");
            }
        }
    
        private void jTextField1FocusGained(FocusEvent evt)
        {
            jTextField1.selectAll();
        }
    
        private void jTextField2FocusGained(FocusEvent evt)
        {
            jTextField2.selectAll();
        }
    
        private void jButton2ActionPerformed(ActionEvent evt)
        {
            Logic logic = new Logic();
            new JOptionPane();
            JOptionPane.showMessageDialog(null, logic.FreeTime(logic.FreeTime(sched1, sched2)));
        }
    
        String name1;
        String name2;
        String sched1[][];
        String sched2[][];
        private JButton jButton1;
        private JButton jButton2;
        private JComboBox jComboBox1;
        private JComboBox jComboBox2;
        private JLabel jLabel1;
        private JLabel jLabel2;
        private JLabel jLabel3;
        private JLabel jLabel4;
        private JPanel jPanel1;
        private JPanel jPanel2;
        private JPanel jPanel3;
        private JScrollPane jScrollPane1;
        private JScrollPane jScrollPane2;
        private JTable jTable1;
        private JTable jTable2;
        private JTextField jTextField1;
        private JTextField jTextField2;
    }
    Thanks in advance.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Do you have any questions about your program?
    Please explain with details.

  3. #3
    JPCP13 is offline Member
    Join Date
    Aug 2011
    Posts
    4
    Rep Power
    0

    Default

    Oh, I already make it to function. Now what I need is to make a Clear Button the will reset the fields in the 2 JTables. How can I do that? o.O

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    How can I do that?
    Add a button,
    add an actionListener to the button,
    add code in the actionlistener to clear the tables.

  5. #5
    JPCP13 is offline Member
    Join Date
    Aug 2011
    Posts
    4
    Rep Power
    0

    Default

    Here's the code of my JTable with a mix of arrays. How do I reset it?

    Java Code:
    jTable2.setModel(new DefaultTableModel(new Object[][] {
                new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }, new Object[] {
                    null, null, null, null, null, null, null
                }

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Use a loop to set the values to null.

  7. #7
    JPCP13 is offline Member
    Join Date
    Aug 2011
    Posts
    4
    Rep Power
    0

    Default

    What if I want that if I press the button, it will immediately exit the program and re-run the main method again. Example is after I pressed it, it will close and an Option pane will pop out that asks for the input. Thanks in advance.

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    if I press the button, it will immediately exit the program and re-run
    I don't know how you can do anything once the program has exited. To do that you would need another program running separately that could start your program after your program has exited.

    Could you explain? Do you mean you want to change what window is showing?

Similar Threads

  1. Replies: 3
    Last Post: 12-04-2009, 12:10 PM
  2. Java Calendar Planner
    By Alex04 in forum New To Java
    Replies: 0
    Last Post: 09-18-2009, 02:44 PM
  3. im a newbie creating a calendar planner
    By abbotjava in forum New To Java
    Replies: 3
    Last Post: 08-23-2009, 03:28 PM
  4. Replies: 1
    Last Post: 08-05-2009, 02:43 AM
  5. Replies: 0
    Last Post: 02-16-2008, 09:31 PM

Posting Permissions

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