public dbfShow(String title, String fname) throws Exception { super(title); String dbname; addWindowListener(this); sp = new ScrollPane(); viewPane = new Panel(); sp.add(viewPane); this.add(sp); if (fname == null || fname.length() == 0) { FileDialog fd = new FileDialog(this, "dbfShow", FileDialog.LOAD); fd.setFile("*.DBF"); fd.pack(); fd.setVisible(true); String DBFname = fd.getFile(); String dirname = fd.getDirectory(); if (DBFname == null) { System.exit(0); } if (DBFname.length() < 1) { System.exit(0); } dbname = new String(dirname + DBFname); } else { dbname = new String(fname); } MenuBar mb = new MenuBar(); this.setMenuBar(mb); Menu file = new Menu("File"); opener = new MenuItem("Open.."); file.add(opener); opener.addActionListener(this); packer = new MenuItem("Pack"); packer.addActionListener(this); file.add(packer); quiter = new MenuItem("Quit"); file.add(quiter); quiter.addActionListener(this); mb.add(file); Menu record = new Menu("Record"); firstRecord = new MenuItem("First"); firstRecord.addActionListener(this); record.add(firstRecord); nextRecord = new MenuItem("Next"); nextRecord.addActionListener(this); record.add(nextRecord); prevRecord = new MenuItem("Prev"); prevRecord.addActionListener(this); record.add(prevRecord); lastRecord = new MenuItem("Last"); lastRecord.addActionListener(this); record.add(lastRecord); addRecord = new MenuItem("Add"); addRecord.addActionListener(this); record.add(addRecord); updateRecord = new MenuItem("Update"); updateRecord.addActionListener(this); record.add(updateRecord); clearRecord = new MenuItem("Clear"); clearRecord.addActionListener(this); record.add(clearRecord); mb.add(record); crl = new Label("Record", Label.RIGHT); trl = new Label(" of ", Label.LEFT); SBrecpos = new Scrollbar(Scrollbar.HORIZONTAL, 1, 1, 0, 0); SBrecpos.addAdjustmentListener(this); delCB = new Checkbox("Deleted"); delCB.addItemListener(this); Prev = new Button("<<Prev"); Prev.addActionListener(this); Next = new Button("Next>>"); Next.addActionListener(this); Add = new Button("Add"); Add.addActionListener(this); Update = new Button("Update"); Update.addActionListener(this); Clear = new Button("Clear"); Clear.addActionListener(this); setupDBFields(dbname); setTitle(dbname + ", org.xBaseJ Version:" + org.xBaseJ.DBF.xBaseJVersion); pack(); setVisible(true); }
public void actionPerformed(ActionEvent event) { if (event.getSource() == firstRecord) { goTo(1); return; } if (event.getSource() == lastRecord) { goTo(db.getRecordCount()); return; } if (event.getSource() == Next || event.getSource() == nextRecord) { if (db.getCurrentRecordNumber() < db.getRecordCount()) { goTo(db.getCurrentRecordNumber() + 1); } return; } if (event.getSource() == Prev || event.getSource() == prevRecord) { if (db.getCurrentRecordNumber() > 1) { goTo(db.getCurrentRecordNumber() - 1); } return; } if (event.getSource() == Add || event.getSource() == addRecord) { addRec(); return; } if (event.getSource() == Update || event.getSource() == updateRecord) { updateRec(); return; } if (event.getSource() == Clear || event.getSource() == clearRecord) { clearFields(); return; } if (event.getSource() == opener) { FileDialog fd = new FileDialog(this, "dbfShow", FileDialog.LOAD); fd.setFile("*.DBF"); fd.pack(); fd.setVisible(true); String DBFname = fd.getFile(); String dirname = fd.getDirectory(); if (DBFname == null) { return; } if (DBFname.length() < 1) { return; } String dbname = new String(dirname + DBFname); try { setupDBFields(dbname); } catch (Exception e1) { System.out.println(e1); System.exit(4); } pack(); setVisible(true); return; } if (event.getSource() == packer) { packer.setEnabled(false); try { db.pack(); trl.setText(" of " + db.getRecordCount()); } catch (Exception e1) { e1.printStackTrace(); } if (db.getRecordCount() == 0) { Update.setEnabled(false); Next.setEnabled(false); updateRecord.setEnabled(false); nextRecord.setEnabled(false); SBrecpos.setValues(0, 1, 0, 0); } else { goTo(1); } packer.setEnabled(true); return; } if (event.getSource() == quiter) { System.exit(0); return; } if (event.getSource() instanceof Button) { int i; Field f; for (i = 1; i <= db.getFieldCount(); i++) { try { f = db.getField(i); if (f.isMemoField()) { if (event.getActionCommand().equals(f.getName())) { md = new memoDialog(this, f); md.setVisible(true); return; } } } catch (Exception e1) { System.out.println(e1); } } } }