Code throwing Null exceptoin - JavaOne

package FinCal; /* * select * from cts_cus select * from cts_shifts drop table cts_cus go CREATE TABLE [dbo].[cts_cus]( [day] [varchar](10) NULL, [fac_name] [varchar](20) NULL, [last_name] [varchar](10) NULL ) ON [PRIMARY] drop table cts_shifts go CREATE TABLE [dbo].[cts_shifts]( [day] [varchar](20) primary key, [fac_name] [varchar](20) NULL, [candi_type] [varchar](10) NULL, [f_7_3] [varchar](10) NULL, [f_3_11] [varchar](10) NULL, [f_11_7] [varchar](10) NULL ) */ import java.awt.Color; import java.awt.Rectangle; import javax.swing.JPanel; import javax.swing.JButton; import javax.swing.UIManager; import javax.swing.border.TitledBorder; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JLabel; import javax.swing.JComboBox; import javax.swing.DefaultComboBoxModel; import javax.swing.JSpinner; import javax.swing.SpinnerDateModel; import com.sun.org.apache.bcel.internal.generic.INSTANCEOF; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeEvent; import java.awt.event.InputMethodListener; import java.awt.event.InputMethodEvent; import javax.swing.event.ChangeListener; import javax.swing.event.ChangeEvent; public class Shifts extends JPanel { JButton btnNewButton = new JButton("Save"); JComboBox comboBox_4 = new JComboBox(); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); String ystr = dateFormat.format(new Date ()); ComboCount combcnt = new ComboCount(); JComboBox comboBox_5 = new JComboBox(); /** * Create the panel. */ public Shifts() { setLayout(null); setEnabled(false); setBounds(new Rectangle(100, 100, 700, 600)); setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Enter Shifts", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0))); setLayout(null); JLabel lblFacility = new JLabel("Facility"); lblFacility.setBounds(42, 84, 69, 14); add(lblFacility); JLabel label = new JLabel("7-3"); label.setBounds(284, 84, 46, 14); add(label); JLabel label_1 = new JLabel("3-11"); label_1.setBounds(377, 84, 46, 14); add(label_1); JLabel label_2 = new JLabel("11-3"); label_2.setBounds(449, 84, 46, 14); add(label_2); JComboBox comboBox = new JComboBox(); // comboBox.setModel(new DefaultComboBoxModel(new String[] {"CNA", "LPN", "RN", "HHA", "CMA"})); comboBox.setModel(CandiPanel.candiTypecomboBox.getModel()); comboBox.setBounds(176, 128, 57, 20); add(comboBox); JComboBox comboBox_1 =  new JComboBox(); comboBox_1.setModel(new DefaultComboBoxModel(new String[] {"0","1", "2", "3", "4", "5", "6", "7", "8", "9", "10"})); comboBox_1.setBounds(271, 128, 46, 20); add(comboBox_1); JComboBox comboBox_2 =  new JComboBox(); comboBox_2.setModel(new DefaultComboBoxModel(new String[] {"0","1", "2", "3", "4", "5", "6", "7", "8", "9"})); comboBox_2.setBounds(364, 128, 46, 20); add(comboBox_2); JComboBox comboBox_3 = combcnt.getComboBox(); comboBox_3.setModel(new DefaultComboBoxModel(new String[] {"0","1", "2", "3", "4", "5", "6", "7", "8", "9"})); comboBox_3.setBounds(434, 128, 46, 20); add(comboBox_3); JLabel lblBook = new JLabel("Book"); lblBook.setBounds(176, 84, 69, 14); add(lblBook); comboBox_4.setModel(new DefaultComboBoxModel(new String[] {"select dept"})); comboBox_4.setBounds(30, 128, 115, 20); add(comboBox_4);     Object js = new Date(); JSpinner spinner = new JSpinner(); spinner.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent arg0) {   System.out.println( " State changed position Shift input --->"+spinner.getValue()); ystr = dateFormat.format(spinner.getValue()); } }); spinner.addInputMethodListener(new InputMethodListener() { public void caretPositionChanged(InputMethodEvent arg0) {   System.out.println( " Caret position Shift input --->"+ystr); } public void inputMethodTextChanged(InputMethodEvent arg0) {   System.out.println( " Input MethodShift input --->"+ystr); } }); spinner.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent arg0) { System.out.println("Property changed --------------->>"+spinner.getValue()); ChangeListener ch; } }); spinner.setModel(new SpinnerDateModel(new Date(), null, null, Calendar.DAY_OF_WEEK_IN_MONTH)); spinner.setBounds(30, 309, 115, 20); //     if  (spinner.getValue().getClass().getName())  ); add(spinner); spinner.addChangeListener(new ChangeListener() {         #Override         public void stateChanged(ChangeEvent e) {             System.out.println("value changed: " + spinner.getValue());         }     }); //// System.out.println(ystr+" <--ddddddddddddddddddd"+spinner.getValue()); btnNewButton.addMouseListener(new MouseAdapter() { #Override public void mouseClicked(MouseEvent arg0) {   String tstr =  comboBox_4.getSelectedItem().toString()+ " , "+comboBox.getSelectedItem().toString()+ " , " + comboBox_1.getSelectedItem().toString()   + " , " + comboBox_2.getSelectedItem().toString()+ " , " + comboBox_3.getSelectedItem().toString()   + " , "+ystr  ;     System.out.println( " Shift input --->"+tstr);           CalendarProgram1.insertShifts(tstr);           } }); btnNewButton.setBounds(137, 386, 89, 23); add(btnNewButton); comboBox_5.setBounds(30, 174, 115, 20); add(comboBox_5); JComboBox comboBox_6 = new JComboBox(); comboBox_6.setModel(new DefaultComboBoxModel(new String[] {"CNA", "LPN"})); comboBox_6.setBounds(176, 174, 57, 20); add(comboBox_6); JComboBox comboBox_7 = new JComboBox(); comboBox_7.setModel(new DefaultComboBoxModel(new String[] {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"})); comboBox_7.setBounds(271, 174, 46, 20); add(comboBox_7); JComboBox comboBox_8 = new JComboBox(); comboBox_8.setModel(new DefaultComboBoxModel(new String[] {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"})); comboBox_8.setBounds(364, 174, 46, 20); add(comboBox_8); JComboBox comboBox_9 = new JComboBox(); comboBox_9.setModel(new DefaultComboBoxModel(new String[] {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"})); comboBox_9.setBounds(434, 174, 46, 20); add(comboBox_9); } } class ComboCount{ JComboBox comboBox_1 = new JComboBox(); ComboCount(){ comboBox_1.setModel(new DefaultComboBoxModel(new String[] {"0","1", "2", "3", "4", "5", "6", "7", "8", "9", "10"})); } JComboBox getComboBox() { return comboBox_1; } }

sorry about the messy code [code]package FinCal;/* * select * from cts_cusselect * from cts_shifts drop table cts_cusgoCREATE TABLE [dbo].[cts_cus]( [day] [varchar](10) NULL, [fac_name] [varchar](20) NULL, [last_name] [varchar](10) NULL) ON [PRIMARY] drop table cts_shifts go CREATE TABLE [dbo].[cts_shifts]( [day] [varchar](20) primary key, [fac_name] [varchar](20) NULL, [candi_type] [varchar](10) NULL, [f_7_3] [varchar](10) NULL, [f_3_11] [varchar](10) NULL, [f_11_7] [varchar](10) NULL) */import java.awt.Color;import java.awt.Rectangle;import javax.swing.JPanel;import javax.swing.JButton;import javax.swing.UIManager;import javax.swing.border.TitledBorder;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import javax.swing.JLabel;import javax.swing.JComboBox;import javax.swing.DefaultComboBoxModel;import javax.swing.JSpinner;import javax.swing.SpinnerDateModel;import com.sun.org.apache.bcel.internal.generic.INSTANCEOF;import java.text.DateFormat;import java.text.SimpleDateFormat;import java.util.Date;import java.util.Calendar;import java.beans.PropertyChangeListener;import java.beans.PropertyChangeEvent;import java.awt.event.InputMethodListener;import java.awt.event.InputMethodEvent;import javax.swing.event.ChangeListener;import javax.swing.event.ChangeEvent;public class Shifts extends JPanel { JButton btnNewButton = new JButton("Save"); JComboBox comboBox_4 = new JComboBox(); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); String ystr = dateFormat.format(new Date ()); ComboCount combcnt = new ComboCount(); JComboBox comboBox_5 = new JComboBox(); /**  * Create the panel.  */ public Shifts() {  setLayout(null);    setEnabled(false);  setBounds(new Rectangle(100, 100, 700, 600));  setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Enter Shifts", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));  setLayout(null);        JLabel lblFacility = new JLabel("Facility");  lblFacility.setBounds(42, 84, 69, 14);  add(lblFacility);    JLabel label = new JLabel("7-3");  label.setBounds(284, 84, 46, 14);  add(label);    JLabel label_1 = new JLabel("3-11");  label_1.setBounds(377, 84, 46, 14);  add(label_1);    JLabel label_2 = new JLabel("11-3");  label_2.setBounds(449, 84, 46, 14);  add(label_2);    JComboBox comboBox = new JComboBox(); // comboBox.setModel(new DefaultComboBoxModel(new String[] {"CNA", "LPN", "RN", "HHA", "CMA"}));  comboBox.setModel(CandiPanel.candiTypecomboBox.getModel());  comboBox.setBounds(176, 128, 57, 20);  add(comboBox);    JComboBox comboBox_1 =  new JComboBox();   comboBox_1.setModel(new DefaultComboBoxModel(new String[] {"0","1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}));  comboBox_1.setBounds(271, 128, 46, 20);  add(comboBox_1);    JComboBox comboBox_2 =  new JComboBox();   comboBox_2.setModel(new DefaultComboBoxModel(new String[] {"0","1", "2", "3", "4", "5", "6", "7", "8", "9"}));  comboBox_2.setBounds(364, 128, 46, 20);  add(comboBox_2);  JComboBox comboBox_3 = combcnt.getComboBox();   comboBox_3.setModel(new DefaultComboBoxModel(new String[] {"0","1", "2", "3", "4", "5", "6", "7", "8", "9"}));  comboBox_3.setBounds(434, 128, 46, 20);  add(comboBox_3);        JLabel lblBook = new JLabel("Book");  lblBook.setBounds(176, 84, 69, 14);  add(lblBook);    comboBox_4.setModel(new DefaultComboBoxModel(new String[] {"select dept"}));  comboBox_4.setBounds(30, 128, 115, 20);    add(comboBox_4);        Object js = new Date();  JSpinner spinner = new JSpinner();  spinner.addChangeListener(new ChangeListener() {   public void stateChanged(ChangeEvent arg0) {       System.out.println( " State changed position Shift input --->"+spinner.getValue());      ystr = dateFormat.format(spinner.getValue());     }  });  spinner.addInputMethodListener(new InputMethodListener() {   public void caretPositionChanged(InputMethodEvent arg0) {       System.out.println( " Caret position Shift input --->"+ystr);      }      public void inputMethodTextChanged(InputMethodEvent arg0) {       System.out.println( " Input MethodShift input --->"+ystr);       }  });  spinner.addPropertyChangeListener(new PropertyChangeListener() {   public void propertyChange(PropertyChangeEvent arg0) {    System.out.println("Property changed --------------->>"+spinner.getValue());       ChangeListener ch;   }  });  spinner.setModel(new SpinnerDateModel(new Date(), null, null, Calendar.DAY_OF_WEEK_IN_MONTH));  spinner.setBounds(30, 309, 115, 20);    //     if  (spinner.getValue().getClass().getName())  );  add(spinner);     spinner.addChangeListener(new ChangeListener() {          #Override          public void stateChanged(ChangeEvent e) {              System.out.println("value changed: " + spinner.getValue());          }      });     //// System.out.println(ystr+" <--ddddddddddddddddddd"+spinner.getValue());  btnNewButton.addMouseListener(new MouseAdapter() {   #Override   public void mouseClicked(MouseEvent arg0) {      String tstr =  comboBox_4.getSelectedItem().toString()+ " , "+comboBox.getSelectedItem().toString()+ " , " + comboBox_1.getSelectedItem().toString()        + " , " + comboBox_2.getSelectedItem().toString()+ " , " + comboBox_3.getSelectedItem().toString()        + " , "+ystr  ;           System.out.println( " Shift input --->"+tstr);           CalendarProgram1.insertShifts(tstr);                    }  });  btnNewButton.setBounds(137, 386, 89, 23);  add(btnNewButton);    comboBox_5.setBounds(30, 174, 115, 20);  add(comboBox_5);    JComboBox comboBox_6 = new JComboBox();  comboBox_6.setModel(new DefaultComboBoxModel(new String[] {"CNA", "LPN"}));  comboBox_6.setBounds(176, 174, 57, 20);  add(comboBox_6);    JComboBox comboBox_7 = new JComboBox();  comboBox_7.setModel(new DefaultComboBoxModel(new String[] {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}));  comboBox_7.setBounds(271, 174, 46, 20);  add(comboBox_7);    JComboBox comboBox_8 = new JComboBox();  comboBox_8.setModel(new DefaultComboBoxModel(new String[] {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}));  comboBox_8.setBounds(364, 174, 46, 20);  add(comboBox_8);    JComboBox comboBox_9 = new JComboBox();  comboBox_9.setModel(new DefaultComboBoxModel(new String[] {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}));  comboBox_9.setBounds(434, 174, 46, 20);  add(comboBox_9);    }}class ComboCount{ JComboBox comboBox_1 = new JComboBox(); ComboCount(){ comboBox_1.setModel(new DefaultComboBoxModel(new String[] {"0","1", "2", "3", "4", "5", "6", "7", "8", "9", "10"})); } JComboBox getComboBox() {  return comboBox_1; }} [/code]

/*Dashboard learning as swing classes excercise.Build a standalone gui to assign task delete from cts_cus delete from cts_shifts delete from assignment select * from cts_cusselect * from cts_shiftsselect * from assignmentselect day,fac_name,candi_type,  f_7_3 ,f_3_11,f_11_7, f1, f2, f3,  f4,  f5,  f6,  f7,  f8, f9,  f10from mytest_vworder by 1,2,3select * from assignment_status select * from  cts_candidrop table cts_candicreate table cts_candi(fname   varchar(10), lname  varchar(10), type   varchar(20) ) drop table cts_shifts go CREATE TABLE [dbo].[cts_shifts](    [Id] int IDENTITY(1,1) NOT NULL PRIMARY KEY, [day] [varchar](20) , [fac_name] [varchar](20) NULL, [candi_type] [varchar](10) NULL, [f_7_3] int NULL, [f_3_11] int NULL, [f_11_7] int NULL, [f_7_3_who] varchar(20) NULL, [f_3_11_who] varchar(20) NULL, [f_11_7_who] varchar(20) NULL, [f_7_3_ti] varchar(20) NULL, [f_7_3_to] varchar(10) NULL, [f_3_11_ti] varchar(10) NULL, [f_3_11_to] varchar(10) NULL, [f_11_7_ti] varchar(10) NULL, [f_11_7_to] varchar(10) NULL,    comments     varchar(30)) drop view assignment_statuscreate view assignment_statusas  select b.day as bday,b.fac_name as bfac_name, b.candi_type as bcandi_type,a.day,a.fac_name,canditype,count(*) as booked  ,whod  from mytest_vw b  LEFT OUTER JOIN assignment a   ON   a.day = b.day  and a.fac_name = b.fac_name  and a.canditype = b.candi_type  group by  b.day,b.fac_name, b.candi_type,a.day,a.fac_name,canditype,whod insert into assignment values('2018-01-31','Hudson','333-222-1111','LPN','7-3','HAWA','777-222-6665','this is a commment',null)insert into assignment values('2017-12-06','sss','333-222-1111','CNA','7-3','HAWA','777-222-6665','this is a commment',null)goinsert into assignment values('2017-12-11','sss','333-222-1111','CNA','7-3','HTRW','777-222-6665','this is a commment',null)goinsert into assignment values('2017-12-11','sss','333-222-1111','CNA','7-3','TTTT','777-222-6665','this is a commment',null)goinsert into assignment values('2018-01-06','BISHOP','333-222-1111','LPN','7-3','HTRW','777-222-6665','this is a commment',null)drop table assignmentgocreate table assignment(day  varchar(10), fac_name varchar(10), fac_ph1 varchar(13), canditype  varchar(10), shift  varchar(10), whod  varchar(10), who_ph  varchar(13), comments varchar(30), cancelled  varchar(10) )    drop view mytest_vwgocreate view mytest_vwasselect day,fac_name,candi_type, f_7_3 as f_7_3 , f_3_11 as f_3_11, f_11_7 as f_11_7  ,'f1' as f1,'f2' as f2,'f3' as f3,'f4' as f4,'f5' as f5,'f6' as f6,'f7' as f7,'f8' as f8,'f9' as f9,'f10' as f10from cts_shifts--group by day,fac_name,candi_type select * from mytest_vwdelete from cts_cusgodelete from cts_shiftsdrop table cts_cusgoCREATE TABLE [dbo].[cts_cus]( [day] [varchar](10) NULL, [fac_name] [varchar](20) NULL, [last_name] [varchar](10) NULL) ON [PRIMARY] drop table cts_shifts go drop table cts_shifts go CREATE TABLE [dbo].[cts_shifts](    [Id] int IDENTITY(1,1) NOT NULL PRIMARY KEY, [day] [varchar](20) , [fac_name] [varchar](20) NULL, [candi_type] [varchar](10) NULL, [f_7_3] int NULL, [f_3_11] int NULL, [f_11_7] int NULL) */package FinCal;import javafx.scene.layout.Border;import javax.swing.*;import javax.swing.border.TitledBorder;import javax.swing.event.*;import javax.swing.table.*;import javax.swing.text.DefaultCaret;import javax.swing.text.SimpleAttributeSet;import javax.swing.text.StyleConstants;import javax.swing.text.StyledDocument;import java.awt.*;import java.util.List;import java.util.*;import java.awt.event.*;import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.*;import java.util.Timer;import java.awt.*;import javax.swing.*; public class CalendarProgram1{ static JTextArea textarea;    static JLabel lblMonth, lblYear;    static JButton btnPrev, btnNext;    static JTable tblCalendar;    static JComboBox cmbYear;    static JFrame frmMain;    static Container pane;    static DefaultTableModel mtblCalendar; //Table model    static JScrollPane stblCalendar; //The scrollpane    static JPanel pnlCalendar;    static int realYear, realMonth, realDay, currentYear, currentMonth;    static String[][][] mytext= new String [4][4][100];   /// static CalPanel calPanel = new CalPanel();    static boolean alreadyOpened = false;    static CalFrame cf = null; //new CalFrame();    static ClientPanel cpanel = null;    static CandiPanel candipanel = null;    static  Assignment  assignment = null ; //new Assignment();   static Shifts shifts = null;       static MiscDatabaseTasks mis = new MiscDatabaseTasks();    static String[][][] allContent = new String[2][3000][3000];    static int I = 2;    static int J = 3;    static HashMap AllShifts = new HashMap();        static Map<String, List<String>> hmShifts = new HashMap<String, List<String>>();    static Map<String, List<String>> assignmentStatus = new HashMap<String, List<String>>();        static int daySize = 11; static String viewingDay = " "; static String selectedPeriod = " "; static boolean seven = false; static boolean three  = false; static boolean eleven = false; static String sftWhere = " ";         public static void printTemp() {     for (int i=0;i<I;i++) {      for (int j=0;j<J;j++) {        System.out.print(" allContent["+i+"]["+j+"]"+allContent[i][j][0]);        }      System.out.println();     }    }    public static void popluateTemp() {        String name = "Har";        String title = "CN";        String hired = "YES";     for (int i=0;i<I;i++) {      for (int j=0;j<J;j++) {        allContent[i][j][0]= name+" "+i+" "+j;        }           }           }    public static void main (String args[]){       candipanel = new CandiPanel();     popluateTemp();     printTemp();     //System.exit(0);          Connection con = null;            mytext[0][0][0] = "har";       mytext[0][0][2] = "Rav";               try {UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());}        catch (ClassNotFoundException e) {}        catch (InstantiationException e) {}        catch (IllegalAccessException e) {}        catch (UnsupportedLookAndFeelException e) {}                //Prepare frame        frmMain = new JFrame ("Gestionnaire de clients"); //Create frame     //   frmMain.setSize(330, 375); //Set size to 400x400 pixels         frmMain.setSize(1050,950); //Set size to 400x400 pixels        frmMain.setResizable(true);        pane = frmMain.getContentPane(); //Get content pane        pane.setLayout(null); //Apply null layout        frmMain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Close when X is clicked                //Create controls        lblMonth = new JLabel ("January");        lblYear = new JLabel ("Change year:");        cmbYear = new JComboBox();       // btnPrev = new JButton ("<<Next");        //btnNext = new JButton (">>");        btnPrev = new JButton ("Prev");        btnNext = new JButton ("Next");                mtblCalendar = new DefaultTableModel(){public boolean isCellEditable(int rowIndex, int mColIndex){return false;}};        tblCalendar = new JTable(mtblCalendar);              //  tblCalendar.getColumn("").setCellRenderer(new TextAreaRenderer());        //tblCalendar.getColumn("FD").setCellRenderer(cellRenderer);        stblCalendar = new JScrollPane(tblCalendar);        pnlCalendar = new JPanel(null);        ClientForm cform = new  ClientForm(" fdsf","ss");           //Set border        pnlCalendar.setBorder(BorderFactory.createTitledBorder("Calendar"));                //Register action listeners        btnPrev.addActionListener(new btnPrev_Action());        btnNext.addActionListener(new btnNext_Action());        cmbYear.addActionListener(new cmbYear_Action());                //Add controls to pane        MainControl mc = new MainControl();       // pane.add(pnlCalendar);    //   mc.setBounds(0, 0, 100, 200);         mc.setVisible(true);       pane.add(mc);  mc.btnNewButton_1.addMouseListener(new MouseAdapter() {   #Override   public void mouseClicked(MouseEvent arg0) {    System.out.println(" Shifts in Calendar");     try {  pane.remove(pnlCalendar);     }catch(Exception e) {}     try {        pane.remove(cpanel);     }catch(Exception e) {}     try {        pane.remove(cpanel);      }catch(Exception e) {}     try {        pane.remove(cpanel);     }catch(Exception e) {}     try {         //pane.remove(shifts);      }catch(Exception e) {}     try {         pane.remove(candipanel);      }catch(Exception e) {}       try {         pane.remove(assignment);      }catch(Exception e) {}        pane.revalidate();      pane.repaint();             shifts = new Shifts();      getFacilities("ssss,fss  ");      // pane.remove(mc);    //  cpanel = new ClientPanel();      shifts.setVisible(true);        pane.add(shifts);      //  System.out.println(" shifti panel added");       pane.revalidate();       pane.repaint();           }  });         mc.btnNewCandidate.addMouseListener(new MouseAdapter() {   #Override   public void mouseClicked(MouseEvent arg0) {        System.out.println(" Enter Candidate button pressed");         try {  pane.remove(pnlCalendar);     }catch(Exception e) {}     try {        pane.remove(cpanel);     }catch(Exception e) {}     try {        pane.remove(cpanel);      }catch(Exception e) {}     try {        pane.remove(cpanel);     }catch(Exception e) {}     try {         pane.remove(shifts);      }catch(Exception e) {}     try {         pane.remove(candipanel);      }catch(Exception e) {}       try {         pane.remove(assignment);      }catch(Exception e) {}        pane.revalidate();      pane.repaint();        candipanel = new CandiPanel();      // pane.remove(mc);    //  cpanel = new ClientPanel();      candipanel.btnNewButton_1.addMouseListener(new MouseAdapter() {      #Override      public void mouseClicked(MouseEvent arg0) {       System.out.println(" Inserting candidate ---------->");       insertCandi();      }     });      candipanel.setVisible(true);        pane.add(candipanel);        System.out.println(" Candi panel added");       pane.revalidate();       pane.repaint();            }  });                        mc.btnAssigments.addMouseListener(new MouseAdapter() {   #Override   public void mouseClicked(MouseEvent arg0) {          getAssignmentStatus();     try {  pane.remove(pnlCalendar);      }catch(Exception e) {}     try {        pane.remove(cpanel);     }catch(Exception e) {}     try {        //pane.remove(cpanel);      }catch(Exception e) {}     try {        pane.remove(cpanel);     }catch(Exception e) {}     try {         pane.remove(shifts);      }catch(Exception e) {}     try {         pane.remove(candipanel);      }catch(Exception e) {}     try {         pane.remove(assignment);            }catch(Exception e) {}        pane.revalidate();      pane.repaint();      //  getFacilities("ssss,fss  ");      assignment = new Assignment();      /*      assignment.faclist.removeAllItems();      for (int t = 0; t <  shifts.comboBox_4.getItemCount(); t++)       {       assignment.faclist.addItem( shifts.comboBox_4.getItemAt(t));            }      */      System.out.println(" ((((((((((((((((((((((((((-->"+assignmentStatus.size());      Set <String> ke=  assignmentStatus.keySet();      for (int t = 0; t <  assignmentStatus.keySet().size(); t++)       {       System.out.println(" ((((((((((((((((((((((((((-->"+assignmentStatus.get(t));    //   System.out.println(" ((((((((((((((((((((((((((-->"+ke.);                      }            assignment.bookDate.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent arg0) {              //System.out.println("  Action listner for book date -------------------->");             System.out.println(" AddItem Listner ss Select ITem is ---->"+ke.size());               selectedPeriod  = (String)assignment.bookDate.getSelectedItem();          System.out.println( " refreshing...: "+  selectedPeriod);           // refreshAssignmentDate(ke);                refreshAssignment(ke);             }     });           assignment.shift_detail.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent arg0) {                                  refreshShiftDetail();        System.out.println( " seven -->"+seven);      }     });                assignment.btnSave.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent arg0) {       System.out.println(" btn save clicked");       updateShift();        refreshShiftDetail();                    }     });           /*          assignment.bookDate.addItemListener(new ItemListener() {      public void itemStateChanged(ItemEvent arg0) {            System.out.println(" AddItem Listner ss Select ITem is ---->"+ke.size());              selectedPeriod  = (String)assignment.bookDate.getSelectedItem();         System.out.println( " refreshing...: "+  selectedPeriod);          // refreshAssignmentDate(ke);               refreshAssignment(ke);      }          });          */             refreshAssignmentDate(ke);    //  refreshAssignment(ke);            /*         Iterator<String> it = ke.iterator();               while(it.hasNext()){          String item = it.next();            System.out.println("KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"+assignmentStatus);            assignment.bookDate.addItem(item);      List ks = assignmentStatus.get(item);          System.out.println(item+"LIST    KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"+ks);                     System.out.println("#########################"+ks.size());                                                Object[] numbers = ks.toArray();          System.out.println("#########################"+numbers[1]);          String tstring = " ";          int itr = ks.size();          for (int y=1;y<ks.size();) {                      System.out.println("*************************"+numbers[y-1]);           System.out.println("*************************"+numbers[y]);           System.out.println("*************************"+numbers[y+1]);           System.out.println("*************************"+numbers[y+2]);           System.out.println("*************************"+numbers[y+3]);           System.out.println("*************************"+numbers[y+4]);           System.out.println("*************************"+numbers[y+5]);           System.out.println("*************************"+numbers[y+6]);           System.out.println("*************************"+numbers[y+7]);           System.out.println("*************************"+numbers[y+8]);                      String this_item=  numbers[y-1]           + " "+numbers[y]            +numbers[y+1] +numbers[y+5];                     System.out.println(item  + " : "+  selectedPeriod);               assignment.shift_detail.addItem(this_item);                  y=y+11;                    }                        assignment.whoD.addItem(ks.get(1)); //           assignment.shift_detail.addItem(ks);                     }                  */          //  cpanel.setVisible(true);    //assignment.faclist.add(  shifts.comboBox_4.getComponents());      // pane.remove(mc);        pane.add(assignment);       pane.revalidate();       pane.repaint();       }  });         mc.btnNewClient.addMouseListener(new MouseAdapter() {   #Override   public void mouseClicked(MouseEvent arg0) {        System.out.println(" Enter Client button pressed");          try {  pane.remove(pnlCalendar);        }catch(Exception e) {}       try {          pane.remove(cpanel);       }catch(Exception e) {}       try {          //pane.remove(cpanel);        }catch(Exception e) {}       try {          pane.remove(cpanel);       }catch(Exception e) {}       try {           pane.remove(shifts);        }catch(Exception e) {}       try {           pane.remove(candipanel);               }catch(Exception e) {}                     try {            pane.remove(assignment);       }catch(Exception e) {}                     pane.revalidate();        pane.repaint();             cpanel = new ClientPanel();        cpanel.setVisible(true);        // pane.remove(mc);          pane.add(cpanel);         pane.revalidate();         pane.repaint();                       }  });    mc.btnNewButton.addMouseListener(new MouseAdapter() {   #Override   public void mouseClicked(MouseEvent arg0) {        System.out.println(" calender is clicked");               getAssignmentStatus();           getAllFac();     try {  pane.remove(pnlCale

Related

Help with Layout

I've got a simple layout but I need to get it looking more like this picture: http://members.lycos.nl/ghanswebsite/Layout.JPG
Now I got a simple GridBag. I tried a few other layouts but they got me errors so until now I evaded them .. :-(.
// Fig. 12.26: GridLayoutDemo.java
// Demonstrating GridLayout.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import java.awt.Color.*;
public class GridLayoutDemo extends JFrame implements ActionListener {
     private boolean toggle = true;
     private Container c;
     private GridLayout grid1;
     private JButton zoek;
     private Connection connection;
     private JTextField vDag, aDatum, vTijd, aTijd, vlucht;
     Statement opdracht = null;
    boolean inAnApplet = true;
    final boolean shouldFill = true;
    final boolean shouldWeightX = true;
     Color myPink1 = new Color(254,224,192);
    private JComboBox vertrek, naar, vdag, vmaand, volwassenen, kinderen, babys;
     // vertrekdag
     private String dag[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18","19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"};
     // vetrekmaand+jaar
     private String maand[] = { "April 2003" , "Mei 2003"};
     // volwassenen
     private String volwassen[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };
     // kinderen
     private String kind[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };
     // baby's.
     private String baby[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };
     //vetrekplaatsen-combobox
     private String vPlaatsen[] = { "Amsterdam", "Rotterdam" };
     private String[] plaats = null;
     // aangeven wat in het combobox van Rotterdam mag staan
     private String raPlaatsen[] = { "Alicante", "Faro" };
     // aangeven wat in het combobox van Amsterdam
     private String aaPlaatsen[] = { "Bacelona", "Antalya", "Arrecife", "Alicante", "Bodrun" };
     //thread-safe gui changing with swingUtilities.invokeLater( Runnable )
     private Runnable run = new Runnable(){
     public void run(){
          getContentPane().invalidate();
          getContentPane().removeAll();
          getContentPane().add(vertrek);
          getContentPane().add(naar = new JComboBox( plaats ));
          getContentPane().add(vdag);
          getContentPane().add(vmaand);
          getContentPane().add(volwassenen);
          getContentPane().add(kinderen);
          getContentPane().add(babys);
          getContentPane().add(zoek);
          getContentPane().add(vDag);
          getContentPane().add(aDatum);
          getContentPane().add(vTijd);
          getContentPane().add(aTijd);
          getContentPane().add(vlucht);
          getContentPane().validate();
          }
     };
   public GridLayoutDemo()
   {
     super( "GridLayout Demo" );
          // The URL specifying the Books database to which
            // this program connects using JDBC to connect to a
            // Microsoft ODBC database.
            String url = "jdbc:odbc:vluchtinformatie";
            // Load the driver to allow connection to the database
            try {
               Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
               connection = DriverManager.getConnection( url );
                 opdracht = connection.createStatement();
            }
            catch ( ClassNotFoundException cnfex ) {
               System.err.println(
                  "Failed to load JDBC/ODBC driver." );
               cnfex.printStackTrace();
               System.exit( 1 );  // terminate program
            }
            catch ( SQLException sqlex ) {
               System.err.println( "Unable to connect" );
               sqlex.printStackTrace();
               System.exit( 1 );  // terminate program
      }
    grid1 = new GridLayout( 4, 3, 10, 10 );
     Container c = getContentPane();
     c.setLayout( grid1 );
     setSize(500,200);
     vertrek = new JComboBox(vPlaatsen);
     vertrek.setName("vertrek");
     vertrek.setMaximumRowCount(2);
     vertrek.addActionListener( this );
     c.add(vertrek);
    show();
     vdag = new JComboBox(dag);
     vdag.setName("dag");
     vdag.setMaximumRowCount(5);
     vdag.addActionListener( this );
     c.add(vdag);
     show();
     vmaand = new JComboBox(maand);
     vmaand.setName("maand");
     vmaand.setMaximumRowCount(5);
     vmaand.addActionListener( this );
     c.add(vmaand);
     show();
     volwassenen = new JComboBox(volwassen);
     volwassenen.setName("volwassen");
     volwassenen.setMaximumRowCount(5);
     volwassenen.addActionListener( this );
     c.add(volwassenen);
     show();
     kinderen = new JComboBox(kind);
     kinderen.setName("kind");
     kinderen.setMaximumRowCount(5);
     kinderen.addActionListener( this );
     c.add(kinderen);
     show();
     babys = new JComboBox(baby);
     babys.setName("baby");
     babys.setMaximumRowCount(5);
     babys.addActionListener( this );
     c.add(babys);
     show();
     zoek = new JButton( "Zoek vlucht" );
     zoek.addActionListener( this );
     c.add(zoek);
     show();
     vDag = new JTextField( "Vertrekdatum" );
     c.add(vDag);
     show();
     aDatum = new JTextField( "Aankomstdatum" );
     c.add(aDatum);
     show();
     vTijd = new JTextField( "Vertrektijd" );
     c.add(vTijd);
     show();
     aTijd = new JTextField( "Aankomsttijd" );
     c.add(aTijd);
     show();
     vlucht = new JTextField("Vluchtnummer" );
     c.add(vlucht);
     show();
}
public void actionPerformed(ActionEvent e)     {
   Object source = e.getSource();
        if (source instanceof JComboBox)
        {
             JComboBox combo = (JComboBox) source;
             if (combo.getName().equals("vertrek"))
             {
                  if (((String) combo.getSelectedItem()).equals(vPlaatsen[0]))
                  {
                       plaats = aaPlaatsen;
                       SwingUtilities.invokeLater( run );
                  }
                       else if (((String) combo.getSelectedItem()).equals(vPlaatsen[1]))
                       {
                            plaats = raPlaatsen;
                            SwingUtilities.invokeLater( run );
                       }
             }
        }
   Object source1 = e.getSource();
        if (source1 instanceof JComboBox)
        {
             JComboBox combo1 = (JComboBox) source1;
             if (combo1.getName().equals("vertrek"))
             {
                  if (((String) combo1.getSelectedItem()).equals(vPlaatsen[0]))
                  {
                    String gebruikersVertrekplaats = "Amsterdam";
                  }
                       else if (((String) combo1.getSelectedItem()).equals(vPlaatsen[1]))
                       {
                    String gebruikersVertrekplaats = "Rotterdam";
                       }
          }
        }
                  try
                    {
                    ResultSet gegevens;
                    gegevens = opdracht.executeQuery("SELECT * FROM vluchtinformatie WHERE vertrekplaats LIKE '"+ gebruikersVertrekplaats +"' AND aankomstplaats LIKE '"+gebruikersAankomstplaats+"';");
                    }
               catch (Exception e)
                    {
                    e.printStackTrace();
                    }
}
   public static void main( String args[] )
   {
                  try {
                        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel" );
                      }
                 catch (Exception e) { }
      GridLayoutDemo app = new GridLayoutDemo();
      app.addWindowListener(
         new WindowAdapter() {
            public void windowClosing( WindowEvent e )
            {
               System.exit( 0 );
            }
         }
      );
   }
}

label layout managers

im trying to add numbered labels to an image. The image is broken up into a 6x4 grid and want to add a number to each piece. I have been using the FlowLayoutManager and set the numbers up as strings as I would if using buttons but they are not displaying.
String [] Label = {"13", "1", "2", "15", "8", "21", "17", "6", "18", "24", "12", "10",                               "13", "9", "16", "4", "20", "5", "19", "7", "23", "14", "22", "11"}; 
How can you add components to an Image? It is not a subclass of java.awt.Container. 
Like this?
import java.awt.*;
import java.net.*;
import javax.swing.*;
public class ImageLayoutExample implements Runnable {
    public void run() {
        try {
            URL url = new URL("http://blogs.sun.com/roller/resources/jag/SouthParkJAG-small.png");
            JLabel label = new JLabel(new ImageIcon(url));
            label.setLayout(new GridLayout(3,3));
            Font font = new Font("serif", Font.PLAIN, 32);
            for(int i=0; i < 9; ++i) {
                JLabel l = new JLabel(String.valueOf(i), SwingConstants.CENTER);
                l.setBorder(BorderFactory.createEtchedBorder());
                l.setFont(font);
                l.setForeground(Color.GREEN);
                label.add(l);
            }
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(label);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args) {
        EventQueue.invokeLater(new ImageLayoutExample());
    }
}

JOptionPane

Hi,
I am having a hard time figuring out the error in the code below. please help if you can. The error message is that an identifier is expected. I dont know what or which identifier i need to put it.
Regards.
import javax.swing.*;
//import javax.swing.text;
import java.awt.*;
import java.awt.event.*;
public class trailBlazer extends JFrame
{
  public trailBlazer()
  {
    super("MasterMind Version S.1");
    JLabel label1, label2, label3, label4, label5, label6, label7;
    JComboBox difficultyLevel, target1, target2;
    JTextField guessText;
    String range = " ";
    String levels[] = {"1", "2", "3", "4"};
    String targetPoints[] = {"a", "b", "c", "d", "e", "f", "g", "h","i", "j", "k", "l", "m","n", "o", "p", "q", "r", "s", "t", "u", "v","w", "x", "y", "z"};
     
        JFrame f1 = new JFrame();
        JPanel p1 = new JPanel();
        p1.setLayout(new FlowLayout());
        JButton b1 = new JButton("OK");
       
        label1 = new JLabel("Choose difficulty level to play!");
        p1.add(label1);
        difficultyLevel = new JComboBox(levels);
        difficultyLevel.setMaximumRowCount(4);
        p1.add(difficultyLevel);
        label2 = new JLabel("Pick 2 target points for your guess range");
        p1.add(label2);
        target1 = new JComboBox(targetPoints);
        target1.setMaximumRowCount(26);
        p1.add(target1);
        target2 = new JComboBox(targetPoints);
        target2.setMaximumRowCount(26);
        p1.add(target2);
        label4 = new JLabel("This is your target range " + range);
        label5 = new JLabel(
                "You can now begin guessing the computers target string");
        p1.add(label5);
        label6 = new JLabel("Enter your guess below and click OK");
        guessText = new JTextField(4);
        p1.add(guessText);
        //label7 = new JLabel("Click the button after guessing");
        p1.add (label7);
        p1.add(b1);
      
   
    f1.getContentPane().add(p1);
    f1.setSize(400,300);
    f1.setVisible(true);
  
    b1.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        JOptionPane.showMessageDialog(null,"You guessed: " );
      }
    }
    );
  
    guessText.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        String guessX ="";
       
         if(e.getSource()== guessText)
          guessX += e.getActionCommand();
        //else
          //guessX = "Please enter valid guess" + e.getActionCommand();
       }
        JOptionPane.showMessageDialog( null, guessX );
    }
    );
                    
}
  
  public static void main(String args[])
  {
    trailBlazer t =new trailBlazer();
  }
} 
public void actionPerformed(ActionEvent e)
{
String guessX ="";
if(e.getSource()== guessText)
guessX += e.getActionCommand();
//else
//guessX = "Please enter valid guess" +
d guess" + e.getActionCommand();
}
JOptionPane.showMessageDialog( null, guessX
, guessX );Did you mean to put the JOptionPane line inside the actionPerformed method?
Next time, it would be helpful if you indicated which line the error was referring to. 
Hi,
thank you for your reply,
I did mean for it to be part of the actionPerformed method. The error is referring to the JOptionPane. 
    guessText.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        String guessX ="";
         if(e.getSource() == guessText)
            guessX += e.getActionCommand();
       }  // <<== Move this brace after JOptionPane call
        // ==>> OUTSIDE OF METHOD actionPerformed, should be inside method
        JOptionPane.showMessageDialog( null, guessX );
    }
    );� {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
PS. I realize that Phillip Ross was pointing out the same thing. It was just not clear from OP's reply that OP understood what PR was pointing out.
� {�                                                                                                                                                                                                                                                                                                                       

jtable

i have implemented a jtable and sent my sql result to it now i need to be able to click a row and get the cell no 2 of that row's value sent to another sql statement.
here is the class
plese note the actual table is been sent from another class to this one i will put this class underneath this one. plz help i am desparate. thanks
//Title: Your Product Name
//Version:
//Copyright: Copyright (c) 1999
//Author: DB
//Company: UEL
//Description: Your description
//package Newton;
import java.awt.*;
import com.borland.jbcl.layout.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
import java.io.*;
import java.text.*;
import javax.swing.border.*;
import javax.swing.event.*;
import javax.swing.table.*;
public class Drawing extends JFrame {
Index index;
XYLayout xYLayout1 = new XYLayout();
JPanel jPanel1 = new JPanel();
XYLayout xYLayout2 = new XYLayout();
JPanel jPanel2 = new JPanel();
XYLayout xYLayout3 = new XYLayout();
JPanel jPanel3 = new JPanel();
XYLayout xYLayout4 = new XYLayout();
JPanel jPanel4 = new JPanel();
XYLayout xYLayout5 = new XYLayout();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JButton jButton3 = new JButton();
JButton jButton4 = new JButton();
JPanel jPanel5 = new JPanel();
XYLayout xYLayout6 = new XYLayout();
JLabel jLabel2 = new JLabel();
JLabel nameLabel = new JLabel();
JTextArea jTextArea2 = new JTextArea();
JLabel jLabel3 = new JLabel();
JLabel jLabel8 = new JLabel();
int i;
String choice;
String sql="";
ResultSet rset;
JButton jButton5 = new JButton();
JScrollPane jScrollPane1 = new JScrollPane();
JTable jTable1;
private boolean DEBUG = true;
Component component1;
public Drawing() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
component1 = Box.createGlue();
this.getContentPane().setLayout(xYLayout1);
jPanel1.setBackground(SystemColor.desktop);
jPanel1.setBorder(BorderFactory.createEtchedBorder());
jPanel1.setLayout(xYLayout2);
jPanel2.setLayout(xYLayout3);
jPanel2.setBackground(SystemColor.desktop);
jPanel2.setBorder(BorderFactory.createEtchedBorder());
jPanel3.setBackground(SystemColor.desktop);
jPanel3.setBorder(BorderFactory.createEtchedBorder());
jPanel3.setLayout(xYLayout4);
xYLayout1.setHeight(599);
xYLayout1.setWidth(1034);
jPanel4.setBackground(new java.awt.Color(80, 175, 233));
jPanel4.setBorder(BorderFactory.createEtchedBorder());
jPanel4.setLayout(xYLayout5);
jButton1.setBackground(SystemColor.desktop);
jButton1.setFont(new java.awt.Font("Serif", 1, 22));
jButton1.setForeground(Color.cyan);
jButton1.setBorder(BorderFactory.createEtchedBorder());
jButton1.setText("Insert Reminder");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
jButton2.setBackground(SystemColor.desktop);
jButton2.setFont(new java.awt.Font("Serif", 1, 22));
jButton2.setForeground(Color.cyan);
jButton2.setBorder(BorderFactory.createEtchedBorder());
jButton2.setText("Image");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton2_actionPerformed(e);
}
});
jButton3.setBackground(SystemColor.desktop);
jButton3.setFont(new java.awt.Font("Serif", 1, 22));
jButton3.setForeground(Color.cyan);
jButton3.setBorder(BorderFactory.createEtchedBorder());
jButton3.setText("Drawing History");
jButton3.addActionListener(new ActionListener(this));
jButton3.addActionListener(new ActionListener(this));
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton3_actionPerformed(e);
}
});
jButton4.setBackground(SystemColor.desktop);
jButton4.setFont(new java.awt.Font("Serif", 1, 22));
jButton4.setForeground(Color.cyan);
jButton4.setBorder(BorderFactory.createEtchedBorder());
jButton4.setText("Update");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton4_actionPerformed(e);
}
});
jPanel5.setBackground(SystemColor.desktop);
jPanel5.setFont(new java.awt.Font("Serif", 1, 16));
jPanel5.setBorder(BorderFactory.createEtchedBorder());
jPanel5.setLayout(xYLayout6);
this.getContentPane().setBackground(new java.awt.Color(80, 175, 233));
jLabel2.setFont(new java.awt.Font("Serif", 1, 20));
jLabel2.setForeground(Color.cyan);
jLabel2.setText("Drawing Category");
nameLabel.setBackground(Color.pink);
nameLabel.setFont(new java.awt.Font("Serif", 1, 35));
nameLabel.setText("Newton Equipments");
jLabel8.setFont(new java.awt.Font("Serif", 1, 16));
jLabel8.setForeground(Color.cyan);
jLabel3.setFont(new java.awt.Font("Serif", 1, 18));
jButton5.setText("Find Supplier");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton5_actionPerformed(e);
}
});
jButton5.setBorder(BorderFactory.createEtchedBorder());
jButton5.setForeground(Color.cyan);
jButton5.setBackground(SystemColor.desktop);
jButton5.setFont(new java.awt.Font("Serif", 1, 22));
jTextArea2.setBorder(BorderFactory.createLineBorder(Color.black));
this.getContentPane().add(jPanel1, new XYConstraints(8, 65, 1004, 487));
jPanel1.add(jPanel3, new XYConstraints(3, 41, 992, 437));
jPanel3.add(jPanel4, new XYConstraints(18, 294, -1, 129));
jPanel4.add(jButton3, new XYConstraints(392, 2, 187, 122));
jPanel4.add(jButton2, new XYConstraints(195, 2, 195, 122));
jPanel4.add(jButton5, new XYConstraints(0, 2, 193, 122));
jPanel4.add(jButton4, new XYConstraints(581, 2, 184, 122));
jPanel4.add(jButton1, new XYConstraints(767, 2, 180, 122));
jPanel3.add(jScrollPane1, new XYConstraints(12, 49, 961, 168));
jPanel3.add(jPanel2, new XYConstraints(12, 0, 961, 44));
jPanel2.add(jLabel2, new XYConstraints(9, 2, 166, 28));
jPanel2.add(jLabel3, new XYConstraints(876, 1, 75, 38));
jPanel3.add(jTextArea2, new XYConstraints(19, 229, 948, 56));
jPanel3.add(component1, new XYConstraints(218, 259, -1, -1));
jPanel1.add(jPanel5, new XYConstraints(4, 2, 990, 36));
jPanel5.add(jLabel8, new XYConstraints(170, 6, -1, -1));
this.getContentPane().add(nameLabel, new XYConstraints(361, 11, 312, 40));
jScrollPane1.getViewport().add(jTable1, null);
}
private String printDebugData(JTable table) {
int numRows = table.getRowCount();
int numCols = table.getColumnCount();
javax.swing.table.TableModel model = table.getModel();
int j=1;
for (int i=0; i < numRows; i++) {
// for (int j=3; j < numCols; j++) {
System.out.println(""+model.getValueAt(i,j));
// }
}
return (String)model.getValueAt(i,j);
}
void jButton1_actionPerformed(ActionEvent e)
{
}
void jButton3_actionPerformed(ActionEvent e)
{
if (e.getSource() == jButton3)
{
if (DEBUG)
{
index.jTable1.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
choice = printDebugData(index.jTable1);
}
});
}
// int chice =index.jTable1.getSelectedRow();
// String choice = index.printDebugData(index.jTable1);
if(choice.length()==0)
{
JOptionPane.showMessageDialog(this,"You havent enter your choice",null,JOptionPane.INFORMATION_MESSAGE);
}
else
{
Statement stmt1;
String sql;
try
{
JDBCConnection myConnection = new JDBCConnection();
stmt1 = myConnection.myConn.createStatement();
sql="SELECT * FROM DRAWING where DRAWINGTITLE ="+"'"+choice+"'";
rset = stmt1.executeQuery(sql);
System.out.println(sql);
if(rset.next())
{
DrawingHistory d= new DrawingHistory();
d.setSize(1024,590);
d.setVisible(true);
d.setLocation(0,142);
int i=0;
Object[][] data= new Object[50][4];
do {
String surname = rset.getString("DrawNo");
String firstname = rset.getString("DrawingTitle");
String staffid = rset.getString("StaffNo");
String details = (surname + " "+firstname+" "+staffid);
// d.jList1.addItem(details);
data[0]= surname;
data[i][1] = firstname;
data[i][2] = staffid ;
data[i][3] = "";
          i++;
String[] columnNames = {"Drawing Title",
"Drawing Number",
"Part Number",
"Date Issued"};
jTable1 = new JTable(data, columnNames);
jTable1.setPreferredScrollableViewportSize(new Dimension(500, 170));
if (DEBUG)
{
jTable1.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
printDebugData(jTable1);
}
});
}
//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(jTable1);
//Add the scroll pane to this window.
d.getContentPane().add(scrollPane, BorderLayout.CENTER);
d.jPanel3.add(scrollPane, new XYConstraints(17,28, 966, 210));
}
while (rset.next()==true);
}
else
{
JOptionPane.showMessageDialog(this,"it worked",null,JOptionPane.INFORMATION_MESSAGE);
}
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(this,"HERE"+ex.toString(),null,JOptionPane.INFORMATION_MESSAGE);
}
}
}
}
void jButton2_actionPerformed(ActionEvent e) {
}
void jButton4_actionPerformed(ActionEvent e) {
}
void jButton5_actionPerformed(ActionEvent e) {
}
}
//the index class refered from above class
//written by dula
import java.awt.*;
import com.borland.jbcl.layout.*;
import javax.swing.*;
import com.borland.jbcl.control.*;
import java.awt.event.*;
import java.util.*;
import java.sql.*;
import javax.swing.border.*;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Index extends JFrame
{
private boolean DEBUG = true;
XYLayout xYLayout1 = new XYLayout();
JMenuBar menuBar = new JMenuBar();
//menuBar.
JTable jTable1;
JMenu jMenu1 = new JMenu("File");
JMenuItem jMenuItem1 = new JMenuItem("Save");
JMenuItem jMenuItem2 = new JMenuItem("Delete");
JMenuItem jMenuItem3 = new JMenuItem("Print");
JMenu jMenu2 = new JMenu("View");
JMenuItem jMenuItem4 = new JMenuItem("");
JPanel jPanel1 = new JPanel();
JPanel jPanelsec = new JPanel();
JPanel jPanel3 = new JPanel();
Border border1;
TitledBorder titledBorder1;
XYLayout xYLayout2 = new XYLayout();
JLabel userAreaLabel = new JLabel();
JTextPane userArea = new JTextPane();
JToolBar toolBar = new JToolBar();
JLabel dateLabel = new JLabel();
String user="";
XYLayout xYLayout3 = new XYLayout();
JRadioButton jRadioButton6 = new JRadioButton();
JRadioButton jRadioButton5 = new JRadioButton();
XYLayout xYLayout4 = new XYLayout();
JRadioButton jRadioButton1 = new JRadioButton();
JRadioButton jRadioButton2 = new JRadioButton();
JRadioButton jRadioButton3 = new JRadioButton();
JRadioButton jRadioButton4 = new JRadioButton();
JPanel jPanel4 = new JPanel();
JRadioButton jRadioButton7 = new JRadioButton();
JButton entBut = new JButton();
JButton quitBut = new JButton();
ButtonGroup bg = new ButtonGroup();
int i;
String sql="";
ResultSet rset;
//Statement stmt;
JTextField jTextField1 = new JTextField();
JButton insertButton = new JButton();
public Index()
{
//user=userNameIn;
try
{
jbInit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
private void jbInit() throws Exception
{
border1 = new MatteBorder(null);
titledBorder1 = new TitledBorder("");
xYLayout1.setWidth(1026);
xYLayout1.setHeight(125);
this.setTitle("Newton Equipments System");
this.getContentPane().setLayout(xYLayout1);
jPanel1.setBackground(Color.yellow);
jPanelsec.setBackground(SystemColor.desktop);
toolBar.setBackground(new Color(0, 233, 216));
jPanelsec.setBorder(BorderFactory.createRaisedBevelBorder());
jPanelsec.setLayout(xYLayout3);
jPanel3.setBackground(new java.awt.Color(80, 178, 233));
jPanel3.setBorder(BorderFactory.createRaisedBevelBorder());
jPanel3.setLayout(xYLayout2);
userAreaLabel.setBackground(new java.awt.Color(80, 178, 233));
userAreaLabel.setText("User Loged On");
userArea.setBackground(new java.awt.Color(80, 178, 233));
userArea.setFont(new java.awt.Font("Serif", 1, 16));
jRadioButton6.setBackground(SystemColor.desktop);
jRadioButton6.setText("Drawing Category");
jRadioButton6.setForeground(Color.cyan);
jRadioButton5.setForeground(Color.cyan);
jRadioButton5.setText("Product Category");
jRadioButton5.setBackground(SystemColor.desktop);
jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
jRadioButton1.setForeground(Color.cyan);
jRadioButton1.setText("Drawing Tittle");
jRadioButton1.setBackground(SystemColor.desktop);
jRadioButton2.setForeground(Color.cyan);
jRadioButton2.setText("Drawing No.");
jRadioButton2.setBackground(SystemColor.desktop);
jRadioButton3.setForeground(Color.cyan);
jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
// jRadioButton3_actionPerformed(e);
}
});
jRadioButton3.setText("Part No.");
jRadioButton3.setBackground(SystemColor.desktop);
jRadioButton4.setBackground(SystemColor.desktop);
jRadioButton4.setText("Product No.");
jRadioButton4.setForeground(Color.cyan);
jPanel4.setLayout(xYLayout4);
jPanel4.setBorder(BorderFactory.createRaisedBevelBorder());
jPanel4.setBackground(SystemColor.desktop);
jRadioButton7.setForeground(Color.cyan);
jRadioButton7.setText("Supplier Category");
jRadioButton7.setBackground(SystemColor.desktop);
dateLabel.setBackground(new java.awt.Color(80, 178, 233));
entBut.setBackground(SystemColor.desktop);
entBut.setFont(new java.awt.Font("Serif", 1, 18));
entBut.setForeground(Color.cyan);
entBut.setBorder(BorderFactory.createEtchedBorder());
entBut.setText("Enter");
entBut.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
entBut_actionPerformed(e);
}
});
quitBut.setBackground(SystemColor.desktop);
quitBut.setFont(new java.awt.Font("Serif", 1, 18));
quitBut.setForeground(Color.cyan);
quitBut.setBorder(BorderFactory.createEtchedBorder());
quitBut.setSelected(true);
quitBut.setText("Quit");
quitBut.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
quitBut_actionPerformed(e);
}
});
jTextField1.setBorder(BorderFactory.createLineBorder(Color.black));
insertButton.setBackground(SystemColor.desktop);
insertButton.setForeground(Color.cyan);
insertButton.setBorder(BorderFactory.createEtchedBorder());
insertButton.setToolTipText("Click this button to get to the choice screen of insert a record " +
"to the data base");
insertButton.setText("Insert new Record to DATABASE");
insertButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
insertButton_actionPerformed(e);
}
});
menuBar.add(jMenu1);
menuBar.add(jMenu2);
jMenu1.add(jMenuItem1);
jMenu2.addSeparator();
jMenu2.add(jMenuItem2);
jMenu2.add(jMenuItem3);
jMenuItem3.add(jMenuItem4);
// jMenuItem3.add(jMenuItem3);
this.getContentPane().add(jPanelsec, new XYConstraints(-4, 31, 1028, 31));
jPanelsec.add(jRadioButton7, new XYConstraints(289, 2, -1, -1));
jPanelsec.add(jRadioButton5, new XYConstraints(146, 2, -1, -1));
jPanelsec.add(jRadioButton6, new XYConstraints(11, 2, -1, -1));
jPanelsec.add(quitBut, new XYConstraints(791, 0, 224, 27));
jPanelsec.add(insertButton, new XYConstraints(554, 1, 234, 26));
this.getContentPane().add(jPanel4, new XYConstraints(-3, 0, 1027, -1));
jPanel4.add(jRadioButton1, new XYConstraints(11, 3, -1, -1));
jPanel4.add(jRadioButton2, new XYConstraints(145, 3, -1, -1));
jPanel4.add(jRadioButton3, new XYConstraints(289, 3, -1, -1));
jPanel4.add(jRadioButton4, new XYConstraints(429, 3, -1, -1));
jPanel4.add(entBut, new XYConstraints(790, 0, 224, 28));
jPanel4.add(jTextField1, new XYConstraints(553, 2, 234, 25));
this.getContentPane().add(jPanel3, new XYConstraints(-3, 62, 1027, 29));
jPanel3.add(dateLabel, new XYConstraints(830, 0, 183, 29));
jPanel3.add(userAreaLabel, new XYConstraints(8, 3, 96, 18));
jPanel3.add(userArea, new XYConstraints(95, 0, 201, 18));
setJMenuBar(menuBar);
bg.add(jRadioButton1);
bg.add(jRadioButton2);
bg.add(jRadioButton3);
bg.add(jRadioButton4);
bg.add(jRadioButton5);
bg.add(jRadioButton6);
bg.add(jRadioButton7);
userArea.setText(user);
// addButtonsToToolBar();
dateLabel.setText(setCurrentDate());
}
private void addButtonsToToolBar()
{
jPanelsec.setLayout(new BorderLayout());
jPanelsec.add(toolBar, BorderLayout.NORTH);
}
private String setCurrentDate()
{
SimpleDateFormat sdf=new SimpleDateFormat("EEEE-MMMM-dd-yyyy");
Date date = new Date();
return sdf.format(date);
}
public String printDebugData(JTable table) {
int numRows = table.getRowCount();
int numCols = table.getColumnCount();
javax.swing.table.TableModel model = table.getModel();
// System.out.println("Value of data: ");
// for (int i=0; i < numRows; i++) {
// System.out.print(" row " + i + ":");
// for (int j=3; j < numCols; j++) {
int j=1;
String z = ""+model.getValueAt(i,j);
System.out.println(z);
return (String)model.getValueAt(1,j);
// }
// System.out.println();
// }
// System.out.println("--------------------------");
}
public static void main(String[] args)
{
Index menu = new Index();
menu.setSize(1024,142);
menu.setVisible(true);
// this.dispose();
}
void quitBut_actionPerformed(ActionEvent e) {
System.exit(0);
}
public void entBut_actionPerformed(ActionEvent e) {
if (jRadioButton1.isSelected())
{
String choice =jTextField1.getText();
if(choice.length()==0)
{
JOptionPane.showMessageDialog(this,"You havent enter your choice",null,JOptionPane.INFORMATION_MESSAGE);
}
else
{
Statement stmt1;
try
{
JDBCConnection myConnection = new JDBCConnection();
stmt1 = myConnection.myConn.createStatement();
//sql="SELECT * FROM DRAWING where DRAWINGTITLE ="+"'"+choice+"'";
String sql;
sql = " SELECT Drawing.DrawNo, Drawing.DrawingTitle, Drawing.Stage, Drawing.Priority,";
sql = sql + " Drawing.DrCatagory, Drawing.DateIssued, Part.PartNo, Product.ProdNo, Supplier.SuppID";
sql = sql + " FROM Supplier INNER JOIN ((Drawing INNER JOIN Part ON Drawing.DrawNo = Part.DrawingNo)";
sql = sql + " INNER JOIN Product ON (Drawing.DrawNo = Product.DrawingNo) AND (Part.ProdNo = Product.ProdNo))";
sql = sql + " ON Supplier.SuppID = Part.SupplierID WHERE (((Drawing.DrawingTitle)="+"'"+choice+"'))" ;
rset = stmt1.executeQuery(sql);
System.out.println(sql);
if(rset.next())
{
Drawing d= new Drawing();
d.setSize(1025,600);
d.setVisible(true);
d.setLocation(0,145);
String staffid1 = rset.getString("DrCatagory");
d.jLabel3.setText(staffid1.toUpperCase());
d.jLabel3.setForeground(Color.cyan);
int i=0;
Object[][] data= new Object[50][6];
do {
String surname = rset.getString("DrawingTitle");
String firstname = rset.getString("DrawNo");
String details1 = rset.getString("PartNo");
String staffid = rset.getString("ProdNo");
String details = rset.getString("DateIssued");
String firstname1 = rset.getString("Stage");
data[i][0] = surname;
data[i][1] = firstname;
data[i][2] = details1;
data[i][3] = staffid;
data[i][4] = firstname1;
data[i][5] = details;
// data[i][6] = staffid1;
     i++;
String[] columnNames = {"DRAWING TITLE",
"DRAWING NUMBER",
"PART NUMBER",
"PRODUCT NUMBER",
"DATE ISSUED",
"STATUS"};
jTable1 = new JTable(data, columnNames);
jTable1.setPreferredScrollableViewportSize(new Dimension(500, 170));
if (DEBUG)
{
jTable1.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
printDebugData(jTable1);
}
});
}
//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(jTable1);
//Add the scroll pane to this window.
d.getContentPane().add(scrollPane, BorderLayout.CENTER);
d.jPanel3.add(scrollPane, new XYConstraints(12,50, 961, 167));
}
while (rset.next()==true);
}
else
{
JOptionPane.showMessageDialog(this," There is NO such Tiltle\n Can you Please try another Title",null,JOptionPane.INFORMATION_MESSAGE);
}
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(this,"HERE"+ex.toString(),null,JOptionPane.INFORMATION_MESSAGE);
}
}
}
else if (jRadioButton2.isSelected()){
String choice =jTextField1.getText();
if(choice.length()==0)
{
JOptionPane.showMessageDialog(this,"You havent enter your choice",null,JOptionPane.INFORMATION_MESSAGE);
}
else
{
Statement stmt1;
try
{
JDBCConnection myConnection = new JDBCConnection();
stmt1 = myConnection.myConn.createStatement();
//sql="SELECT * FROM DRAWING where DRAWINGTITLE ="+"'"+choice+"'";
String sql;
sql = " SELECT Drawing.DrawNo, Drawing.DrawingTitle, Drawing.Stage, Drawing.Priority,";
sql = sql + " Drawing.DrCatagory, Drawing.DateIssued, Part.PartNo, Product.ProdNo, Supplier.SuppID";
sql = sql + " FROM Supplier INNER JOIN ((Drawing INNER JOIN Part ON Drawing.DrawNo = Part.DrawingNo)";
sql = sql + " INNER JOIN Product ON (Drawing.DrawNo = Product.DrawingNo) AND (Part.ProdNo = Product.ProdNo))";
sql = sql + " ON Supplier.SuppID = Part.SupplierID WHERE (((Drawing.DrawNo)="+"'"+choice+"'))" ;
rset = stmt1.executeQuery(sql);
System.out.println(sql);
if(rset.next())
{
Drawing d= new Drawing();
d.setSize(1024,590);
d.setVisible(true);
d.setLocation(0,142);
String staffid1 = rset.getString("DrCatagory");
// staffid1.toUpperCase();
d.jLabel3.setText(staffid1.toUpperCase());
d.jLabel3.setForeground(Color.cyan);
int i=0;
Object[][] data= new Object[50][6];
do {
String surname = rset.getString("DrawingTitle");
String firstname = rset.getString("DrawNo");
String details1 = rset.getString("PartNo");
String staffid = rset.getString("ProdNo");
String details = rset.getString("DateIssued");
String firstname1 = rset.getString("Stage");
data[i][0] = surname;
data[i][1] = firstname;
data[i][2] = details1;
data[i][3] = staffid;
data[i][4] = firstname1;
data[i][5] = details;
// data[i][6] = staffid1;
     i++;
String[] columnNames = {"DRAWING TITLE",
"DRAWING NUMBER",
"PART NUMBER",
"PRODUCT NUMBER",
"DATE ISSUED",
"STATUS"};
jTable1 = new JTable(data, columnNames);
jTable1.setPreferredScrollableViewportSize(new Dimension(500, 170));
if (DEBUG)
{
jTable1.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
// printDebugData(jTable1);
}
});
}
//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(jTable1);
//Add the scroll pane to this window.
d.getContentPane().add(scrollPane, BorderLayout.CENTER);
d.jPanel3.add(scrollPane, new XYConstraints(12,50, 961, 167));
}
while (rset.next()==true);
}
else
{
JOptionPane.showMessageDialog(this," There is NO such Tiltle\n Can you Please try another Title",null,JOptionPane.INFORMATION_MESSAGE);
}
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(this,"HERE"+ex.toString(),null,JOptionPane.INFORMATION_MESSAGE);
}
}
}
else if (jRadioButton3.isSelected()){
String choice =jTextField1.getText();
if(choice.length()==0)
{
JOptionPane.showMessageDialog(this,"You havent enter your choice",null,JOptionPane.INFORMATION_MESSAGE);
}
else
{
Statement stmt1;
try
{
JDBCConnection myConnection = new JDBCConnection();
stmt1 = myConnection.myConn.createStatement();
//sql="SELECT * FROM DRAWING where DRAWINGTITLE ="+"'"+choice+"'";
String sql;
sql = " SELECT Drawing.DrawNo, Drawing.DrawingTitle, Drawing.Stage, Drawing.Priority,";
sql = sql + " Drawing.DrCatagory, Drawing.DateIssued, Part.PartNo, Product.ProdNo, Supplier.SuppID";
sql = sql +" FROM Supplier INNER JOIN ((Drawing INNER JOIN Part ON Drawing.DrawNo = Part.DrawingNo)";
sql = sql +" INNER JOIN Product ON (Product.ProdNo = Part.ProdNo) AND (Drawing.DrawNo = Product.DrawingNo))";
sql = sql +" ON Supplier.SuppID = Part.SupplierID WHERE (((Part.PartNo)="+"'"+choice+"'))" ;
rset = stmt1.executeQuery(sql);
System.out.println(sql);
if(rset.next())
{
Drawing d= new Drawing();
d.setSize(1024,590);
d.setVisible(true);
d.setLocation(0,142);
String staffid1 = rset.getString("DrCatagory");
// staffid1.toUpperCase();
d.jLabel3.setText(staffid1.toUpperCase());
d.jLabel3.setForeground(Color.cyan);
int i=0;
Object[][] data= new Object[50][6];
do {
String surname = rset.getString("DrawingTitle");
String firstname = rset.getString("DrawNo");
String details1 = rset.getString("PartNo");
String staffid = rset.getString("ProdNo");
String details = rset.getString("DateIssued");
String firstname1 = rset.getString("Stage");
data[i][0] = surname;
data[i][1] = firstname;
data[i][2] = details1;
data[i][3] = staffid;
data[i][4] = firstname1;
data[i][5] = details;
// data[i][6] = staffid1;
     i++;
String[] columnNames = {"DRAWING TITLE",
"DRAWING NUMBER",
"PART NUMBER",
"PRODUCT NUMBER",
"DATE ISSUED",
"STATUS"};
jTable1 = new JTable(data, columnNames);
jTable1.setPreferredScrollableViewportSize(new Dimension(500, 170));
if (DEBUG)
{
jTable1.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
printDebugData(jTable1);
}
});
}
//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(jTable1);
//Add the scroll pane to this window.
d.getContentPane().add(scrollPane, BorderLayout.CENTER);
d.jPanel3.add(scrollPane, new XYConstra 
hi by the way i have figured out that by using this method i constructed i can actually get the value that i want displayed on a back black screen but the return string wont set the value (choice) into the sql. this class comiles and run but when i press the button to run this method it gives nullpointer exception.
the method that print the value at:
private String printDebugData(JTable table) {
int numRows = table.getRowCount();
int numCols = table.getColumnCount();
javax.swing.table.TableModel model = table.getModel();
int j=1;
for (int i=0; i < numRows; i++) {
// for (int j=3; j < numCols; j++) {
System.out.println(""+model.getValueAt(i,j));
// }
}
return (String)model.getValueAt(i,j);
}
This is a lot of code to just look at but here are my 2-cents:
Altho it can be done but it is generally difficult to try to trap a mouseevent in a JTable yourself. What you should do is to tap into (i.e., override) JTable's editCellAt method, like so:
   public boolean editCellAt(int row, int col, EventObject e) {
      if (e instanceof MouseEvent) {
         if (((MouseEvent)e).getClickCount()<2) {  // should probably leave this alone to treat it as a simple cell selection
            return false;
         }
System.out.println("double click on "+row+" "+col);
         return fause;   // if you don't want JTable to start a cell editing session
      }
      return super.editCellAt(row,col,e);
   };o)
V.V.
PS: There are probably numerous other ways to solve the problem, but this will work.
thanks for the tip bro i am working on the code u gave nowits all good
dula 
i tried the codes i received but i couldnot find out how exactly to use the can u have alook at this code and c what i can do.
as you say my code is lengthy i have specify here where i want to detect the mouse even and send the value from the cell as choice to the sql statement
void jButton3_actionPerformed(ActionEvent e)
{
if (e.getSource() == jButton3)
{
Index index = new Index();
// int chice =index.jTable1.getSelectedRow();
String choice = index.printDebugData(index.jTable1);
if(choice.length()==0)
{
JOptionPane.showMessageDialog(this,"You havent enter your choice",null,JOptionPane.INFORMATION_MESSAGE);
}
else
{
Statement stmt1;
String sql;
try
{
JDBCConnection myConnection = new JDBCConnection();
stmt1 = myConnection.myConn.createStatement();
sql="SELECT * FROM DRAWING where DRAWINGTITLE ="+"'"+choice+"'";
rset = stmt1.executeQuery(sql);
System.out.println(sql);
if(rset.next())
{
DrawingHistory d= new DrawingHistory();
d.setSize(1024,590);
d.setVisible(true);
d.setLocation(0,142);
int i=0;
Object[][] data= new Object[50][4];
do {
String surname = rset.getString("DrawNo");
String firstname = rset.getString("DrawingTitle");
String staffid = rset.getString("StaffNo");
String details = (surname + " "+firstname+" "+staffid);
// d.jList1.addItem(details);
data[0]= surname;
data[i][1] = firstname;
data[i][2] = staffid ;
data[i][3] = "";
          i++;
String[] columnNames = {"Drawing Title",
"Drawing Number",
"Part Number",
"Date Issued"};
jTable1 = new JTable(data, columnNames);
jTable1.setPreferredScrollableViewportSize(new Dimension(500, 170));
if (DEBUG)
{
jTable1.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
printDebugData(jTable1);
}
});
}
//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(jTable1);
//Add the scroll pane to this window.
d.getContentPane().add(scrollPane, BorderLayout.CENTER);
d.jPanel3.add(scrollPane, new XYConstraints(17,28, 966, 210));
}
while (rset.next()==true);
}
else
{
JOptionPane.showMessageDialog(this,"it worked",null,JOptionPane.INFORMATION_MESSAGE);
}
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(this,"HERE"+ex.toString(),null,JOptionPane.INFORMATION_MESSAGE);
}
}
}
}
try this:
jTable1 = new JTable(data, columnNames) {
   public boolean editCellAt(int row, int col, EventObject e) {
      if (e instanceof MouseEvent) {
         System.out.println("mouse clicked on "+row+" "+col);
// do whatever you want here
         return false;
      }
      return super.editCellAt(row,col,e);   }
};;o)
V.V.
bro thanks alot man but my actual problem is to actually pass the string from the cell to the sql statement. i have tried this method and it works fine thanks but i have similer method that i have constructed and works and can actually get the value at the cell i am selecting the only problem is to send that value as string variable choice to this sql:
sql="SELECT * FROM DRAWING where DRAWINGTITLE ="+"'"+choice+"'";
that method i used to get the value:
private String printDebugData(JTable table) {
int numRows = table.getRowCount();
int numCols = table.getColumnCount();
javax.swing.table.TableModel model = table.getModel();
int j=1;
for (int i=0; i < numRows; i++) {
System.out.println(""+model.getValueAt(i,j));
}
return (String)model.getValueAt(i,j);
}
and i call it like this:
jTable1.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
printDebugData(jTable1);
}
});
have a quik look at my class u will get what i mean
and plz note this table have been passes from another class called index
Frankly your posted code is too long to read....what is not clear to me is that your sql statement seems to expect just a single string value for DRAWINGTITLE, but your example seems to indidate that the values can be coming from multiple rows???
Assuming that the value is from a single cell, you can try this:
private String printDebugData(JTable table) {
   return (String)table.getValueAt(table.getSelectedRow(),table.getSelectedColumn());
};o)
V.V. 
hi there
thanks alot u r like my guardian angel at the moment and really sorry to bug you. but ay way i have tried several methods but the problem seem to be that the actual string returned does not get to be set as choice and when i press the button it returns null pointer exceprion at printdebugdata(drawing.java) massege but all the methods u have sent me or even the one i constructed my self return this value on the black scree if i use system.out.printlin()and ask the message to be return it retur the value that is in the cell i clicked but if i press the button after that it gives me the massege above. also to not that this table that the cell is being clicked comes from anothr table. it seem i am close to the answer but i cant figure it out where axactly i need to fix
here i tried to pin point where i think is the problem as u know how the print debug method work:
void jButton3_actionPerformed(ActionEvent e)
{
if (e.getSource() == jButton3){
Index index = new Index();
String choice = this.printDebugData(index.jTable1);
if(choice.length()==0)
{
JOptionPane.showMessageDialog(this,"You havent enter your choice",null,JOptionPane.INFORMATION_MESSAGE);
}
else
{
Statement stmt1;
String sql="SELECT * FROM DRAWING where DRAWINGTITLE ="+"'"+choice+"'";
try
{
JDBCConnection myConnection = new JDBCConnection();
stmt1 = myConnection.myConn.createStatement();
rset = stmt1.executeQuery(sql);
System.out.println(sql);
if(rset.next())
{
DrawingHistory d= new DrawingHistory();
d.setSize(1024,590);
d.setVisible(true);
d.setLocation(0,142);
int i=0;
Object[][] data= new Object[30][4];
do {
String surname = rset.getString("DrawNo");
String firstname = rset.getString("DrawingTitle");
String staffid = rset.getString("StaffNo");
data[0]= surname;
data[i][1] = firstname;
data[i][2] = staffid ;
data[i][3] = "";
          i++;
String[] columnNames = {"Drawing Title",
"Drawing Number",
"Part Number",
"Date Issued"};
jTable1 = new JTable(d

Creating Properties file

Hi!
Does anybody know how I can create properties file for my clientsStr and db.
public class ProjectPanel extends JFrame {
JPanel contentPane;
int index1 = 0;
int index2 = 0;
int index3 = 0;
String[] clientsStr = { " Klient1", " Klient2", "Klient3" };
String[][] db =
{
{
"2010",
"2020",
"2220",
"2240",
"2260",
"2290",
"2475",
"2550",
"2925"
},
{
"4270",
"4290",
"4380",
"4390",
"4475",
"4550",
"6475" },
{
"2020", "2475", "4475", "6475" }
};
String[] debugStr = { "0", "1", "2", "3", "4", "L" };
JComboBox jComboBox1 = new JComboBox(clientsStr);
JComboBox jComboBox2 = new JComboBox(db[0]);
JComboBox jComboBox3 = new JComboBox(debugStr);
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
//Construct the frame
public ProjectPanel() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(null);
this.setSize(new Dimension(312, 150));
this.setTitle("V�lg System");
JButton OK = new JButton();
OK.setBounds(new Rectangle(215, 10, 80, 25));
OK.setMnemonic('O');
OK.setText("Ok");
OK.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
OK_actionPerformed(e);
}
});
JButton jButton1 = new JButton();
jButton1.setBounds(new Rectangle(215, 39, 80, 25));
jButton1.setMnemonic('A');
jButton1.setText("Annuller");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent evt) {
handleRemoveLine();
}
});
jComboBox1.setBackground(Color.yellow);
jComboBox1.setRequestFocusEnabled(false);
jComboBox1.setMaximumRowCount(6);
jComboBox1.setBounds(new Rectangle(75, 22, 129, 25));
jComboBox1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jComboBox1_actionPerformed(e);
}
});
jComboBox2.setBackground(Color.yellow);
jComboBox2.setRequestFocusEnabled(false);
jComboBox2.setMaximumRowCount(6);
jComboBox2.setBounds(new Rectangle(75, 51, 129, 25));
jComboBox2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jComboBox2_actionPerformed(e);
}
});
jComboBox3.setBackground(Color.yellow);
jComboBox3.setMaximumRowCount(6);
jComboBox3.setRequestFocusEnabled(false);
jComboBox3.setBounds(new Rectangle(75, 80, 129, 25));
jComboBox3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jComboBox3_actionPerformed(e);
}
});
jLabel1.setText("Java Klient");
jLabel1.setBounds(new Rectangle(7, 24, 70, 20));
jLabel2.setText("DB");
jLabel2.setBounds(new Rectangle(7, 56, 70, 17));
jLabel3.setText("Debug");
jLabel3.setBounds(new Rectangle(7, 82, 70, 20));
contentPane.add(jComboBox1, null);
contentPane.add(jComboBox2, null);
contentPane.add(jComboBox3, null);
contentPane.add(jButton1, null);
contentPane.add(OK, null);
contentPane.add(jLabel1, null);
contentPane.add(jLabel2, null);
contentPane.add(jLabel3, null);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
private void handleRemoveLine() {
System.exit(0);
}
void jComboBox1_actionPerformed(ActionEvent e) {
index1 = jComboBox1.getSelectedIndex();
if (jComboBox2.getItemCount() > 0)
jComboBox2.removeAllItems();
for (int k = 0; k < db[index1].length; k++)
jComboBox2.addItem(db[index1][k]);
}
void jComboBox2_actionPerformed(ActionEvent e) {
index2 = jComboBox2.getSelectedIndex();
}
void jComboBox3_actionPerformed(ActionEvent e) {
index3 = jComboBox3.getSelectedIndex();
}
void OK_actionPerformed(ActionEvent e) {
Exec myexec = new Exec();
StringBuffer commandLine = new StringBuffer();
switch (index1) {
case 0 :
commandLine.append("C:\\jec.cmd ");
break;
case 1 :
commandLine.append("\\K22\\jec.cmd ");
break;
case 2 :
commandLine.append("\\K23\\jec.cmd ");
break;
}
//commandLine.append("cmd.exe c start/MIN");
commandLine.append(db[index1][index2]);
commandLine.append(" ");
commandLine.append(debugStr[index3]);
myexec.run(commandLine.toString(),true,false);
System.exit(0);
}
} 
At it's simplest a properties file is just an ordinary text file, each line of which is
<name>=<value>
and which can be put anwhere a class file would be found, on the classpath including inside a jar.
The filename must end in .properties
You retrive it with ResourceBundle.getResource("name") and
Where name is the first part of the file.
access the entries with
resource.getString("name");
Hi,
a Properties file contains key-value-pairs, like:
client1=Klient1
client2=Klient2
client3=Klient3Assuming you created a text file containing all the key-value-pairs you need,
you can create a Properties Object as follows:
// loading properties
FileInputStream in = new FileInputStream("yourFile.properties");
Properties props = new Properties();
props.load(in);
in.close();
// now retrieving properties:
String[] clientStr = { props.getProperty("client1"), props.getProperty("client2"), props.getProperty("client3") };You can do this for all properties. Remember it's all about key-value-pairs, and they are both Strings. Therefore, instead of having 3 distinct properties for the 3 clients, you could have just one in the file, like
clients=Klient1,Klient2,Klient3then, when retrieving the clients:
String clients = props.getProperty("clients"); // Which would return "Klient1,Klient2,Klient3"
// Now you would use a StringTokenizer to get the distinct clients, since they are separated by a comma....
// You'd create a StringTokenizer, set the comma a the separator, get the Tokens (client) and put them into a String[]
...// your code ;)Check the Properties javadoc. (And perhaps StringTokenizer javadoc.)
;) Patrick
Thank you .

Categories

Resources