进销存管理系统研发

 

1.Date类:Date jhsjDate = new Date();

       System.out.println(jhsjDate);//Wed Aug 10 10:42:02 CST 2011//它相当于jhsjDate.toString()

       System.out.println(jhsjDate.toLocaleString());//2011-8-10 10:43:55

       System.out.println(jhsjDate.getTime());//1312944122612//得到一个长整型long

       Date date = new Date(jhsjDate.getTime());//对于这来说,基本无用

       System.out.println(date.toLocaleString());//2011-8-10 10:42:02

       String dateStr =date.toLocaleString().substring(0, 9);

       System.out.println(dateStr);//2011-8-10

       String dateStr1 = dateStr.toString().replace("-", "");

       System.out.println(dateStr1);//2011810

2.模糊查询包含4567

Where id like ‘%4567%’ 这是在程序中的正确写法

Where id like ‘*4567*’ 这是在access数据库中的正确写法

3.在程序中查询数据库中的第一列写法:set.getString(1);是1而不是0,而集合当中却相反。

4.DefaultTableModel dtm = new DefaultTableModel();

  table.getRowCount()这是显示行的总行数

dtm.removeRow(i);这是第i-1行,行跟列都是从0开始

TableModel是根接口,AbStractTableModel是其实现的抽象类,DefaultTableModel是完全实现类

TableModel 接口指定了 JTable 用于询问表格式数据模型的方法

TableModel myData = new MyTableModel(); 
JTable table = new JTable(myData);
5.TableCellEditor接口 其完全实现类是:DefaultCellEditor
此接口定义了要成为组件(如 JListBoxJComboBoxJTreeJTable)的值编辑器的任意对象需要实现的方法,table.getCellEditor()表格中此方法可以得到此接口
cell.StopCellEditing();停止单元格编辑
6.new Thread(new Runnable(){
       Public void run(){
       
          }
    }
);定义了多线程
7.在model模型中声明private Set<TbRuKuDetail> rukudetails = new HashSet<TbRuKuDetail>();
类似表连接。

8. // 设置组件位置并添加到容器中

    private void setupComponet(JComponent component,int gridx, int gridy,

           int gridwidth, int ipadx,boolean fill) {

       final GridBagConstraints gridBagConstrains =new GridBagConstraints();

       gridBagConstrains.gridx = gridx;

       gridBagConstrains.gridy = gridy;

       if (gridwidth > 1)

           gridBagConstrains.gridwidth = gridwidth;

       if (ipadx > 0)

           gridBagConstrains.ipadx = ipadx;

       gridBagConstrains.insets = new Insets(5, 1, 3, 1);

       if (fill)

           gridBagConstrains.fill = GridBagConstraints.HORIZONTAL;

       getContentPane().add(component, gridBagConstrains);

9.Calendar类的介绍

       Calendar c = Calendar.getInstance();

       System.out.println(Calendar.YEAR);//显示1

       System.out.println(Calendar.MONTH);//2

       System.out.println(Calendar.DAY_OF_MONTH);//5

       System.out.println(c.get(Calendar.YEAR));//2011

       System.out.println(c.get(Calendar.MONTH)+1);//8,月份一定要加1

       System.out.println(c.get(Calendar.DAY_OF_MONTH));//10号

       System.out.println(c.get(Calendar.DAY_OF_WEEK)-1);//3,星期一定要减1

10.Sql语句:排序语句 select sum(count) from table where id = ‘id’ order by name asc 或者是desc

11.Derby.jar数据库javaDB驱动的程序在C:\Program Files\Sun\JavaDB\lib目录下

12.创建表格

JTable 方法setAutoResizeMode(JTable.AUTO_RESIZE_OFF) //不自动调整列的宽度;使用滚动条

DefaultTableModel  table.getModel()返回这个类,然后setColumnIdentifiers(headers);

ScrollPane

GridBagConstraints grid2 = new GridBagConstraints();

       grid2.weighty=1;//   指定如何分布额外的垂直空间。weightx

       grid2.gridwidth=5; gridheight

       grid2.fill= GridBagConstraints.BOTH;VERTICAL,HORIZONTAL

       grid2.insets = new Insets(5,5,5,5);

       grid2.gridx=0;

       grid2.gridy=2;

        grid2.ipax=0; 组件的最小宽度添加多大的空间 ipdy是高度

       this.getContentPane().add(scrollPane,grid2);

另外GridBagConstraints还有其它静态属性gridBagConstraints_11.anchor = GridBagConstraints.WEST;

EAST ,NORTH,SOUTH,CENTER

13字符串格式化

String.format(“%03d”,str);将字符串格式化成三位数

14.JComboBox的setEditable(true)可以将下拉列表框设置文本框一样,可以编辑的

Combo.setModel(new DefaultComboBoxModel(

              new String[]{"升序排列", "降序排列"}));

gys.removeAllItems();移除所有项

15.在access中,一样可以创建视图表,点击查询,设计,就可以了

16.if(items.contains(item)){}这个方法很常用的,在判断JComboBox时

17. TableColumnModel columnModel = table.getColumnModel();// 返回列模型

       TableColumn tableColumn = columnModel.getColumn(0);

       final DefaultCellEditor editor = new DefaultCellEditor(sp);// 构造商品组合框的编辑器

        editor.setClickCountToStart(2);//双击两下才开始

       tableColumn.setCellEditor(editor);//将sp、tableColumn、editor连在一起

18.    if(!(sp.getSelectedItem() instanceof TbSpInfo)){

           return;

       }这条代码很重要,有时没有它会出错

19. table.getSelectedRow();// 选择当前行

20、int rowCount =dftm.getRowCount();//清空所有行

       for(int i=0;i<rowCount;i++){

           dftm.removeRow(0);

       }

       for(Iterator iter = list.iterator();iter.hasNext();){//用vector添加每行数据到表格

           Vector vector = new Vector();

           List view =(List) iter.next();

           vector.addAll(view);//添加视图表格中一行的每个元素到vector

           dftm.addRow(vector);//将vector添加到行中

       }

21. this.setIconifiable(true);//最小化

       this.setClosable(true);//关闭

       this.setTitle("客户信息查询");

       this.getContentPane().setLayout(new GridBagLayout());

new BoxLayout(jpanel,BoxLayout.X_XAIS)//按顺序编排

       this.setMaximizable(true);//最大化

       this.setBounds(50, 50, 650, 380);//定位和定大小

22. // 按钮事件的监听

       Action action = new openFrameAction(fName, cName, icon);自定义类,Action是接口

       JButton button = new JButton(action);

       button.setHideActionText(true);// 隐藏图标按钮旁边的文本

       button.setBorderPainted(false);// 取消图标细小的边框

       button.setFocusPainted(false);// 取消点击时出现的边框焦点

       button.setContentAreaFilled(false);// 取消背景内容的颜色

       button.setMargin(new Insets(0, 0, 0, 0));// 设置每个图标之间的间距,从上,左,下,右的顺序出发。

       button.setRolloverIcon(icon_roll);// 图标被选中调用

       button.setPressedIcon(icon_down);// 图标被单击调用

23. Class fClass = Class.forName("com.meilun.internalFrame."+ cName);//反射一个类回来

                  Constructor constructor = fClass.getConstructor(null);//反射这个类的构造方法

                  jf = (JInternalFrame) constructor.newInstance(null);//实例化这个构造方法

                  ifs.put(cName, jf);

//得到一个子窗体

private JInternalFrame getIFrame(String cName) { 

           JInternalFrame jf = new JInternalFrame();

           if (!ifs.containsKey(cName)) {//这判断必须的

              try {

                  Class fClass = Class.forName("com.meilun.internalFrame."+ cName);

                  Constructor constructor = fClass.getConstructor(null);

                  jf = (JInternalFrame) constructor.newInstance(null);

                  ifs.put(cName, jf);

              } catch (Exception e) {

                  // TODO Auto-generated catch block

                  e.printStackTrace();

              }

           } else {

              jf = ifs.get(cName);

           }

           return jf;

       }

@Override

       public void actionPerformed(ActionEvent e) {

      

           //调用子窗体

           JInternalFrame jf = this.getIFrame(cName);

           // 子窗体关闭后

           jf.addInternalFrameListener(new InternalFrameAdapter() {

              public void internalFrameClosed(InternalFrameEvent e) {

                  ifs.remove(cName);//移除在hashmap集合中的名字

              }

           });

//将jf添加到desktopPane中

           if (jf.getDesktopPane() == null) {

              desktopPane.add(jf);

              jf.setVisible(true);

           }

           try {

              jf.setSelected(true);

           } catch (PropertyVetoException e1) {

              // TODO Auto-generated catch block

              e1.printStackTrace();

           }// 内部窗口选取时

 

       }

24设置系统外观风格

static {

       try {

           UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

       } catch (Exception e) {

       }

 

25.

// 添加背景图片

       BackPanel bp = new BackPanel();

       desktopPane.add(bp);

        desktopPane.setLayer(bp, -1);//这条代码是关键,必须是-1,其它数字都不行,这是我自己经过多次测试发现的。

       frame.getContentPane().add(desktopPane,BorderLayout.CENTER);

 

26. for(int i=1981,j=0;i<=date.get(Calendar.YEAR)+1;i++,j++){//for语句可以两个变量,这是从1981到2012年的选择

           year.addItem(i);

           if(i== date.get(Calendar.YEAR)){

              year.setSelectedIndex(j);

           }

       }

27.在access中没有convert转换函数和substring函数,但在sql2005h中有,access的截取函数不是substring,而是mid(str,start,length),注意start是从1开始,而不是0

28.字符串中包含双引号,System.out.println("welcome\"hacker\"");输出:welcome"hacker"

29. sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

                     jhsj.setText(sdf.format(jhsjDate));

SimpleDateFormat类是专门格式化日期时间的

2011/8/14

30. String key="-0123456789"+(char)8; 

if(key.indexOf(e.getKeyChar())<0){ e.consume();}

它的作用是使你的键盘输入只能为数字,

首先第一行的key是定义了键盘一共能输入哪些按键.前面的-~9应该很好理解,(char)8就是ASCII码的第8个char.也就是BS(退格键)

然后,第二行的e.getKeyChar()就是获得当前按键的对应的ASCII码的char形式.然后通过key.indexOf()方法来检查该按键是否在key列表里,如果不在的话,返回的index是-1,则-1 < 0为true,执行e.consume();//这是相反的操作

31. pzs = new JTextField("0");//此处必须是加引号的0,否者会空指针错误

32.lable.setFont(new Font(null,Font.BOLD,14));这个可以设置label字体的大小,同样可以设置其它组件的文字属性。

32.获得系统托盘:

SystemTray systray = SystemTray.getSystemTray();

       if(systray.isSupported()){

           System.out.println(systray);

       }

       ImageIcon icon = new ImageIcon("res\\ActionIcon\\操作员管理.png");

       Image img = icon.getImage();

       TrayIcon trayIcon = new TrayIcon(img,"这是操作员管理");

       PopupMenu pop = new PopupMenu();

       MenuItem item1 = new MenuItem("显示窗体");

       MenuItem item2 = new MenuItem("退出");

       pop.add(item1);

       pop.add(item2);

trayIcon.setPopupMenu(pop);

       try {

           systray.add(trayIcon);

       } catch (AWTException e) {

           e.printStackTrace();

       }

33.

Final JLabel title = new JLabel();

title.setForeground(Color.RED);//设置字体颜色

34.Dao中设置ResultSet rs 使用后,必须rs.close()这样关闭它,这是种规范。

35.icon = new ImageIcon("res/welcome.jpg");字符串也可以是res\\welcome.jpg

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章