コード例 #1
0
  //
  //  Initialize the GUI (application and applet)
  //
  public void initialize(String[] args) {
    // Initialize the window, menubar, etc.
    super.initialize(args);
    exampleFrame.setTitle("Java 3D Light Scoping Example");

    //
    //  Add a menubar menu to change node parameters
    //    Use bounding leaf
    //

    Menu m = new Menu("DirectionalLights");

    light1OnOffMenu = new CheckboxMenuItem("Red light with sphere set 1 scope", light1OnOff);
    light1OnOffMenu.addItemListener(this);
    m.add(light1OnOffMenu);

    light2OnOffMenu = new CheckboxMenuItem("Blue light with sphere set 2 scope", light2OnOff);
    light2OnOffMenu.addItemListener(this);
    m.add(light2OnOffMenu);

    light3OnOffMenu = new CheckboxMenuItem("White light with universal scope", light3OnOff);
    light3OnOffMenu.addItemListener(this);
    m.add(light3OnOffMenu);

    exampleMenuBar.add(m);
  }
コード例 #2
0
  /**
   * Method declaration
   *
   * @param s
   */
  private void addToRecent(String s) {

    for (int i = 0; i < iMaxRecent; i++) {
      if (s.equals(sRecent[i])) {
        return;
      }
    }

    if (sRecent[iRecent] != null) {
      mRecent.remove(iRecent);
    }

    sRecent[iRecent] = s;

    if (s.length() > 43) {
      s = s.substring(0, 40) + "...";
    }

    MenuItem item = new MenuItem(s);

    item.setActionCommand("#" + iRecent);
    item.addActionListener(this);
    mRecent.insert(item, iRecent);

    iRecent = (iRecent + 1) % iMaxRecent;
  }
コード例 #3
0
  public SplashDemo() throws NullPointerException, IllegalStateException, IOException {
    super("SplashScreen demo");
    setSize(300, 200);
    setLayout(new BorderLayout());
    Menu m1 = new Menu("File");
    MenuItem mi1 = new MenuItem("Exit");
    m1.add(mi1);
    mi1.addActionListener(this);
    this.addWindowListener(closeWindow);

    MenuBar mb = new MenuBar();
    setMenuBar(mb);
    mb.add(m1);
    final SplashScreen splash = SplashScreen.getSplashScreen();
    if (splash == null) {
      System.out.println("SplashScreen.getSplashScreen() returned null");
      return;
    }
    Graphics2D g = splash.createGraphics();
    if (g == null) {
      System.out.println("g is null");
      return;
    }
    for (int i = 0; i < 100; i++) {
      renderSplashFrame(g, i);
      splash.update();
      try {
        Thread.sleep(90);
      } catch (InterruptedException e) {
      }
    }
    splash.close();
    setVisible(true);
    toFront();
  }
コード例 #4
0
 private void paintMenu(Graphics2D g2d) {
   if (showMenu == true) {
     if (c.getPoints() > c.getHighscore().getLowestPointsInTable() && c.getLifes() == 0) {
       menu.setState(4);
     }
     menu.draw(g2d);
   }
 }
コード例 #5
0
ファイル: CutAndPaste.java プロジェクト: haomen/refs
 public CutAndPaste() {
   cut.addActionListener(new CutL());
   copy.addActionListener(new CopyL());
   paste.addActionListener(new PasteL());
   edit.add(cut);
   edit.add(copy);
   edit.add(paste);
   mb.add(edit);
   setMenuBar(mb);
   add(text, BorderLayout.CENTER);
 }
コード例 #6
0
ファイル: CascadingTest.java プロジェクト: alannet/example
  private Menu createFileMenu() {
    Menu fileMenu = new Menu("File");
    fileMenu.add(quitItem = new MenuItem("Quit"));

    quitItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            dispose();
            System.exit(0);
          }
        });
    return fileMenu;
  }
コード例 #7
0
ファイル: MagicRobot.java プロジェクト: anuvall/Java
  public MagicRobot(
      double first,
      double second,
      EasyFrame frameIn) // this is constructor as it has the same name as the class
      {

    frameIn.setMenuBar(menu);
    menu.add(functions);
    menu.add(colors);

    parentFrame = frameIn;
    add(colorButton);
    colorButton.addActionListener(this);

    number1 = first;
    number2 = second;
    // add visual components
    functions.add(addButton);
    functions.add(subtractButton);
    functions.add(multButton);
    functions.add(divideButton);
    functions.add(remButton);
    colors.add(blueButton);
    colors.add(greenButton);
    subtractButton.addActionListener(this);
    addButton.addActionListener(this);
    multButton.addActionListener(this);
    divideButton.addActionListener(this);
    remButton.addActionListener(this);
    blueButton.addActionListener(this);
    greenButton.addActionListener(this);
  }
コード例 #8
0
ファイル: Gray.java プロジェクト: zqyhellen/graph
    public void setMenu()
    {
        Menu fileMenu = new Menu("File");
        openItem = new MenuItem("Open");
        openItem.addActionListener(this);
        fileMenu.add(openItem);

        exitItem = new MenuItem("Exit");
        exitItem.addActionListener(this);
        fileMenu.add(exitItem);        
        
        Menu processMenu = new Menu("PictureTreatment");
        grayItem = new MenuItem("gray level treatment");
        grayItem.addActionListener(this);
        processMenu.add(grayItem);
        
        processMenu.addSeparator();        
        contrastItem = new MenuItem("contrast level treatment");
        contrastItem.addActionListener(this);
        processMenu.add(contrastItem);        
            
        MenuBar menuBar = new MenuBar();
        menuBar.add(fileMenu);
        menuBar.add(processMenu);
        setMenuBar(menuBar);      
    }
コード例 #9
0
  public static void startApplet(
      Applet applet, String title, Hashtable params, int width, int height) {

    applet1 = applet;
    // setup so as getParameter, etc, will work
    OurAppletContext newAppletContext = new OurAppletContext(applet.getToolkit());
    OurAppletStub newAppletStub = new OurAppletStub(newAppletContext, params);
    applet.setStub(newAppletStub);

    // create new application frame window
    AppletFrame f = new AppletFrame(title + extraTitle);

    // add applet to frame window
    f.add("Center", applet);

    // add a quit menu item
    MenuBar menubar = new MenuBar();
    Menu file = new Menu("File", true);
    MenuItem item = new MenuItem("Quit");
    menubar.add(file);
    file.add(item);
    f.setMenuBar(menubar);
    item.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // At this point, we simply leave.
            java.lang.Runtime.getRuntime().exit(0);
          }
        });

    // resize frame window to fit applet
    f.pack();
    f.setSize(width, height);
    applet.setSize(width, height);

    // initialize the applet
    applet.init();
    applet.start();

    // show the window
    f.show();

    f.repaint();
  } // end startApplet()
コード例 #10
0
ファイル: MenuItem.java プロジェクト: vickyqi/StudyBuddy
 /*
  * Returns true if the item and all its ancestors are
  * enabled, false otherwise
  */
 private final boolean isItemEnabled() {
   // Fix For 6185151: Menu shortcuts of all menuitems within a menu
   // should be disabled when the menu itself is disabled
   if (!isEnabled()) {
     return false;
   }
   MenuContainer container = getParent_NoClientCode();
   do {
     if (!(container instanceof Menu)) {
       return true;
     }
     Menu menu = (Menu) container;
     if (!menu.isEnabled()) {
       return false;
     }
     container = menu.getParent_NoClientCode();
   } while (container != null);
   return true;
 }
コード例 #11
0
  /**
   * Method declaration
   *
   * @param f
   * @param m
   */
  void addMenuItems(Menu f, String m[]) {

    for (int i = 0; i < m.length; i++) {
      MenuItem item = new MenuItem(m[i].substring(1));
      char c = m[i].charAt(0);

      if (c != '-') {
        item.setShortcut(new MenuShortcut(c));
      }

      item.addActionListener(this);
      f.add(item);
    }
  }
コード例 #12
0
ファイル: Newt.java プロジェクト: xrisjc/newt
    public NewtMenuBar() {
      fileMenu = new Menu(FILE_MENU_TEXT);
      fileMenu.add(new MenuItem(QUIT_MENUITEM_TEXT));
      add(fileMenu);

      fractalMenu = new Menu(FRACTAL_MENU_TEXT);
      fractalMenu.add(new MenuItem(MANDELBROT_MENUITEM_TEXT));
      fractalMenu.add(new MenuItem(JULIA_MENUITEM_TEXT));
      fractalMenu.add(new MenuItem(NEWTON_MENUITEM_TEXT));
      fractalMenu.add(new MenuItem(AMSJULIA_MENUITEM_TEXT));
      add(fractalMenu);

      settingsMenu = new Menu(SETTINGS_MENU_TEXT);
      settingsMenu.add(new MenuItem(FRACTALGENERATORSETTINGS_MENUITEM_TEXT));
      add(settingsMenu);

      fileMenu.addActionListener(this);
      fractalMenu.addActionListener(this);
      settingsMenu.addActionListener(this);
    }
コード例 #13
0
ファイル: ExLinearFog.java プロジェクト: citrit/ECSE4750
  //
  //  Initialize the GUI (application and applet)
  //
  public void initialize(String[] args) {
    // Initialize the window, menubar, etc.
    super.initialize(args);
    exampleFrame.setTitle("Java 3D LinearFog Example");

    //
    //  Add a menubar menu to change node parameters
    //    Coupled background color
    //    Background color -->
    //    Fog color -->
    //    Fog front distance -->
    //    Fog back distance -->
    //

    Menu m = new Menu("LinearFog");

    coupledBackgroundOnOffMenu =
        new CheckboxMenuItem("Couple background color", coupledBackgroundOnOff);
    coupledBackgroundOnOffMenu.addItemListener(this);
    m.add(coupledBackgroundOnOffMenu);

    backgroundColorMenu =
        new CheckboxMenu("Background color", colors, currentBackgroundColor, this);
    m.add(backgroundColorMenu);
    backgroundColorMenu.setEnabled(!coupledBackgroundOnOff);

    colorMenu = new CheckboxMenu("Fog color", colors, currentColor, this);
    m.add(colorMenu);

    frontMenu = new CheckboxMenu("Fog front distance", fronts, currentFront, this);
    m.add(frontMenu);

    backMenu = new CheckboxMenu("Fog back distance", backs, currentBack, this);
    m.add(backMenu);

    exampleMenuBar.add(m);
  }
コード例 #14
0
ファイル: Menu.java プロジェクト: GUTY517/Parqueadero
 /** El main es el encargado de iniciar la ejecucion del sistema. */
 public static void main(String[] args) {
   Menu menu = new Menu();
   menu.setVisible(true);
 }
コード例 #15
0
  public DaylightTracker2() {
    // This code is automatically generated by Visual Cafe when you add
    // components to the visual environment. It instantiates and initializes
    // the components. To modify the code, only use code syntax that matches
    // what Visual Cafe can generate, or Visual Cafe may be unable to back
    // parse your Java file into its visual environment.
    // {{INIT_CONTROLS
    getContentPane().setLayout(new BorderLayout());
    setSize(560, 300);
    setTitle("Day and Night");
    // }}

    // setResizable(false);

    JPanel theRealBasePanel = new JPanel();
    theRealBasePanel.setLayout(new MultiCompBorderLayout());
    getContentPane().add(theRealBasePanel);

    MenuBar theMenuBar = new MenuBar();
    setMenuBar(theMenuBar);

    theMenuBar.add(fileMenu = new Menu("File"));
    fileMenu.add(file_quitItem = new MenuItem("Quit"));

    theMenuBar.add(editMenu = new Menu("Edit"));
    editMenu.add(edit_undoItem = new MenuItem("Undo"));
    edit_undoItem.setEnabled(false);
    editMenu.add(new MenuItem("-"));
    editMenu.add(edit_cutItem = new MenuItem("Cut"));
    edit_cutItem.setEnabled(false);
    editMenu.add(edit_copyItem = new MenuItem("Copy"));
    edit_copyItem.setEnabled(false);
    editMenu.add(edit_pasteItem = new MenuItem("Paste"));
    edit_pasteItem.setEnabled(false);
    editMenu.add(edit_clearItem = new MenuItem("Clear"));
    edit_clearItem.setEnabled(false);
    editMenu.add(new MenuItem("-"));
    editMenu.add(edit_prefsItem = new MenuItem("Preferences..."));

    theMenuBar.add(layersMenu = new Menu("Layers"));

    theMenuBar.setHelpMenu(helpMenu = new Menu("Help"));
    helpMenu.add(help_aboutItem = new MenuItem("About JSunTool..."));

    allMapLayers.addElement(new OverlayedTimeLayer());
    allMapLayers.addElement(new NightDay());
    allMapLayers.addElement(new GeographicalMap());
    allMapLayers.addElement(new TopographicalMap());

    menuMapLayers = new CheckboxMenuItem[allMapLayers.size()];

    CheckboxMenuActionListener theCheckboxMenuActionListener = new CheckboxMenuActionListener();

    for (int i = 0; i < allMapLayers.size(); i++) {

      visibleMapLayers.addElement(allMapLayers.elementAt(i));
      theRealBasePanel.add((Component) (visibleMapLayers.elementAt(i)));

      // CheckboxMenuItem tempMenuItem
      menuMapLayers[i] =
          new CheckboxMenuItem(((MapLayer) (allMapLayers.elementAt(i))).getShortName(), true);
      menuMapLayers[i].setActionCommand(new String("MapLayer." + i));
      menuMapLayers[i].addItemListener(theCheckboxMenuActionListener);
      layersMenu.add(menuMapLayers[i]);
    }

    // {{INIT_MENUS
    // }}

    // {{REGISTER_LISTENERS
    SymWindow aSymWindow = new SymWindow();
    this.addWindowListener(aSymWindow);
    // }}

    // Timer theTimer = new Timer ( 1800000, new TimerActionListener() );
    //		Timer theTimer = new Timer ( 1000, new TimerActionListener() );
    //		theTimer.start();
    (new Thread(this)).start();

    MenuActionListener theMenuActionListener = new MenuActionListener();
    file_quitItem.addActionListener(theMenuActionListener);
    help_aboutItem.addActionListener(theMenuActionListener);
  }
コード例 #16
0
  public MenuFrame(String title) {
    super(title);
    this.m_file = new Menu("File");
    this.m_edit = new Menu("Edit");
    this.cm_debug = new CheckboxMenuItem("Debug");
    this.cm_test = new CheckboxMenuItem("Test");
    this.p_debug = new Panel();

    MenuFrameListener listener = new MenuFrameListener();

    Menu m_sub = new Menu("Additional");
    MenuItem mi_new = new MenuItem("New...");
    MenuItem mi_open = new MenuItem("Open...");
    MenuItem mi_close = new MenuItem("Close...");
    MenuItem mi_cut = new MenuItem("Cut");
    MenuItem mi_copy = new MenuItem("Copy");
    MenuItem mi_paste = new MenuItem("Paste");
    MenuItem mi_one = new MenuItem("One!");
    MenuItem mi_two = new MenuItem("Two!");
    MenuItem mi_three = new MenuItem("Three!");

    mi_new.addActionListener(listener);
    mi_open.addActionListener(listener);
    mi_close.addActionListener(listener);
    mi_cut.addActionListener(listener);
    mi_copy.addActionListener(listener);
    mi_paste.addActionListener(listener);
    mi_one.addActionListener(listener);
    mi_two.addActionListener(listener);
    mi_three.addActionListener(listener);
    cm_debug.addItemListener(listener);
    cm_test.addItemListener(listener);

    m_sub.add(mi_one);
    m_sub.add(mi_two);
    m_sub.add(mi_three);
    m_file.add(mi_open);
    m_file.add(mi_new);
    m_file.add(mi_close);
    m_edit.add(mi_cut);
    m_edit.add(mi_copy);
    m_edit.add(mi_paste);
    m_edit.add(m_sub);
    m_edit.add(cm_test);
    m_edit.add(cm_debug);

    initWindow();
  }
コード例 #17
0
  private static void createAndShowGUI() {
    // Check the SystemTray support
    if (!SystemTray.isSupported()) {
      System.out.println("SystemTray is not supported");
      return;
    }
    final PopupMenu popup = new PopupMenu();
    final TrayIcon trayIcon =
        new TrayIcon(ImageHelper.loadImage("/images/splash.jpg", "tray icon"));
    final SystemTray tray = SystemTray.getSystemTray();

    // Create a popup menu components
    MenuItem aboutItem = new MenuItem("About");
    CheckboxMenuItem cb1 = new CheckboxMenuItem("Set auto size");
    CheckboxMenuItem cb2 = new CheckboxMenuItem("Set tooltip");
    Menu displayMenu = new Menu("Display");
    MenuItem errorItem = new MenuItem("Error");
    MenuItem warningItem = new MenuItem("Warning");
    MenuItem infoItem = new MenuItem("Info");
    MenuItem noneItem = new MenuItem("None");
    MenuItem exitItem = new MenuItem("Exit");

    // Add components to popup menu
    popup.add(aboutItem);
    popup.addSeparator();
    popup.add(cb1);
    popup.add(cb2);
    popup.addSeparator();
    popup.add(displayMenu);
    displayMenu.add(errorItem);
    displayMenu.add(warningItem);
    displayMenu.add(infoItem);
    displayMenu.add(noneItem);
    popup.add(exitItem);

    trayIcon.setPopupMenu(popup);

    try {
      tray.add(trayIcon);
    } catch (AWTException e) {
      System.out.println("TrayIcon could not be added.");
      return;
    }

    trayIcon.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(null, "This dialog box is run from System Tray");
          }
        });

    aboutItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(null, "This dialog box is run from the About menu item");
          }
        });

    cb1.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            int cb1Id = e.getStateChange();
            if (cb1Id == ItemEvent.SELECTED) {
              trayIcon.setImageAutoSize(true);
            } else {
              trayIcon.setImageAutoSize(false);
            }
          }
        });

    cb2.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            int cb2Id = e.getStateChange();
            if (cb2Id == ItemEvent.SELECTED) {
              trayIcon.setToolTip("Sun TrayIcon");
            } else {
              trayIcon.setToolTip(null);
            }
          }
        });

    ActionListener listener =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            MenuItem item = (MenuItem) e.getSource();
            // TrayIcon.MessageType type = null;
            System.out.println(item.getLabel());
            if ("Error".equals(item.getLabel())) {
              // type = TrayIcon.MessageType.ERROR;
              trayIcon.displayMessage(
                  "Sun TrayIcon Demo", "This is an error message", TrayIcon.MessageType.ERROR);

            } else if ("Warning".equals(item.getLabel())) {
              // type = TrayIcon.MessageType.WARNING;
              trayIcon.displayMessage(
                  "Sun TrayIcon Demo", "This is a warning message", TrayIcon.MessageType.WARNING);

            } else if ("Info".equals(item.getLabel())) {
              // type = TrayIcon.MessageType.INFO;
              trayIcon.displayMessage(
                  "Sun TrayIcon Demo", "This is an info message", TrayIcon.MessageType.INFO);

            } else if ("None".equals(item.getLabel())) {
              // type = TrayIcon.MessageType.NONE;
              trayIcon.displayMessage(
                  "Sun TrayIcon Demo", "This is an ordinary message", TrayIcon.MessageType.NONE);
            }
          }
        };

    errorItem.addActionListener(listener);
    warningItem.addActionListener(listener);
    infoItem.addActionListener(listener);
    noneItem.addActionListener(listener);

    exitItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            tray.remove(trayIcon);
            System.exit(0);
          }
        });
  }
コード例 #18
0
  public void setMenu() {
    // 菜单界面
    Menu fileMenu = new Menu("文件");
    openItem = new MenuItem("打开");
    openItem.addActionListener(this);
    fileMenu.add(openItem);

    exitItem = new MenuItem("退出");
    exitItem.addActionListener(this);
    fileMenu.add(exitItem);

    Menu affineMenu = new Menu("内置变换");
    rotateItem = new MenuItem("内置旋转");
    rotateItem.addActionListener(this);
    affineMenu.add(rotateItem);

    affineMenu.addSeparator();
    scaleItem = new MenuItem("内置缩放");
    scaleItem.addActionListener(this);
    affineMenu.add(scaleItem);

    affineMenu.addSeparator();
    shearItem = new MenuItem("内置错切");
    shearItem.addActionListener(this);
    affineMenu.add(shearItem);

    affineMenu.addSeparator();
    transItem = new MenuItem("内置平移");
    transItem.addActionListener(this);
    affineMenu.add(transItem);

    Menu affin2Menu = new Menu("仿射变换");
    rotItem = new MenuItem("旋转算法");
    rotItem.addActionListener(this);
    affin2Menu.add(rotItem);

    affin2Menu.addSeparator();
    mirItem = new MenuItem("镜象算法");
    mirItem.addActionListener(this);
    affin2Menu.add(mirItem);

    affin2Menu.addSeparator();
    shrItem = new MenuItem("错切算法");
    shrItem.addActionListener(this);
    affin2Menu.add(shrItem);

    affin2Menu.addSeparator();
    trnItem = new MenuItem("平移算法");
    trnItem.addActionListener(this);
    affin2Menu.add(trnItem);

    Menu interpMenu = new Menu("图像插值");
    nearItem = new MenuItem("最邻近插值");
    nearItem.addActionListener(this);
    interpMenu.add(nearItem);

    interpMenu.addSeparator();
    linrItem = new MenuItem("双线性插值");
    linrItem.addActionListener(this);
    interpMenu.add(linrItem);

    interpMenu.addSeparator();
    cubicItem = new MenuItem("三次卷积插值");
    cubicItem.addActionListener(this);
    interpMenu.add(cubicItem);

    MenuBar menuBar = new MenuBar();
    menuBar.add(fileMenu);
    menuBar.add(affineMenu);
    menuBar.add(affin2Menu);
    menuBar.add(interpMenu);
    setMenuBar(menuBar);
  }
コード例 #19
0
ファイル: CascadingTest.java プロジェクト: alannet/example
  private Menu createCascadingMenu() {
    Menu cascading = new Menu("Cascading", true);
    Menu submenu = new Menu("more", true);
    Menu subsubmenu = new Menu("yet more", true);

    submenu.add("submenu item 1");
    submenu.add("submenu item 2");
    submenu.add("submenu item 3");
    submenu.add("submenu item 4");
    submenu.add("submenu item 5");

    subsubmenu.add("subsubmenu item 1");
    subsubmenu.add("subsubmenu item 2");
    subsubmenu.add("subsubmenu item 3");
    subsubmenu.add("subsubmenu item 4");
    subsubmenu.add("subsubmenu item 5");

    submenu.add(subsubmenu);
    cascading.add(submenu);

    return cascading;
  }
コード例 #20
0
ファイル: AllComponents.java プロジェクト: olexy/RealJava
  /** Create the whole GUI, and set up event listeners */
  public AllComponents(String title) {
    super(title); // set frame title.

    // Arrange to detect window close events
    this.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });

    // Set a default font
    this.setFont(new Font("SansSerif", Font.PLAIN, 12));

    // Create the menubar.  Tell the frame about it.
    MenuBar menubar = new MenuBar();
    this.setMenuBar(menubar);

    // Create the file menu.  Add to menubar.
    Menu file = new Menu("File");
    menubar.add(file);

    // Create two items for the file menu, setting their label, shortcut,
    // action command and listener.  Add them to File menu.
    // Note that we use the frame itself as the action listener
    MenuItem open = new MenuItem("Open", new MenuShortcut(KeyEvent.VK_O));
    open.setActionCommand("open");
    open.addActionListener(this);
    file.add(open);
    MenuItem quit = new MenuItem("Quit", new MenuShortcut(KeyEvent.VK_Q));
    quit.setActionCommand("quit");
    quit.addActionListener(this);
    file.add(quit);

    // Create Help menu; add an item; add to menubar
    // Display the help menu in a special reserved place.
    Menu help = new Menu("Help");
    menubar.add(help);
    menubar.setHelpMenu(help);

    // Create and add an item to the Help menu
    MenuItem about = new MenuItem("About", new MenuShortcut(KeyEvent.VK_A));
    about.setActionCommand("about");
    about.addActionListener(this);
    help.add(about);

    // Now that we've done the menu, we can begin work on the contents of
    // the frame.  Assign a BorderLayout manager with margins for this frame.
    this.setLayout(new BorderLayout(10, 10));

    // Create two panels to contain two columns of components.  Use our custom
    // ColumnLayout layout manager for each.  Add them on the west and
    // center of the frame's border layout
    Panel column1 = new Panel();
    column1.setLayout(new ColumnLayout(5, 10, 2, ColumnLayout.LEFT));
    this.add(column1, "West");
    Panel column2 = new Panel();
    column2.setLayout(new ColumnLayout(5, 10, 2, ColumnLayout.LEFT));
    this.add(column2, "Center");

    // Create a panel to contain the buttons at the bottom of the window
    // Give it a FlowLayout layout manager, and add it along the south border
    Panel buttonbox = new Panel();
    buttonbox.setLayout(new FlowLayout(FlowLayout.CENTER, 100, 10));
    this.add(buttonbox, "South");

    // Create pushbuttons and add them to the buttonbox
    Button okay = new Button("Okay");
    Button cancel = new Button("Cancel");
    buttonbox.add(okay);
    buttonbox.add(cancel);

    // Handle events on the buttons
    ActionListener buttonlistener =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            textarea.append("You clicked: " + ((Button) e.getSource()).getLabel() + "\n");
          }
        };
    okay.addActionListener(buttonlistener);
    cancel.addActionListener(buttonlistener);

    // Now start filling the left column.
    // Create a 1-line text field and add to left column, with a label
    TextField textfield = new TextField(15);
    column1.add(new Label("Name:"));
    column1.add(textfield);

    // Handle events on the TextField
    textfield.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            textarea.append("Your name is: " + ((TextField) e.getSource()).getText() + "\n");
          }
        });
    textfield.addTextListener(
        new TextListener() {
          public void textValueChanged(TextEvent e) {
            textarea.append("You have typed: " + ((TextField) e.getSource()).getText() + "\n");
          }
        });

    // Create a dropdown list or option menu of choices
    Choice choice = new Choice();
    choice.addItem("red");
    choice.addItem("green");
    choice.addItem("blue");
    column1.add(new Label("Favorite color:"));
    column1.add(choice);

    // Handle events on this choice
    choice.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            textarea.append("Your favorite color is: " + e.getItem() + "\n");
          }
        });

    // Create checkboxes, and group them in a CheckboxGroup to give them
    // "radio button" behavior.
    CheckboxGroup checkbox_group = new CheckboxGroup();
    Checkbox[] checkboxes = new Checkbox[3];
    checkboxes[0] = new Checkbox("vanilla", checkbox_group, false);
    checkboxes[1] = new Checkbox("chocolate", checkbox_group, true);
    checkboxes[2] = new Checkbox("strawberry", checkbox_group, false);
    column1.add(new Label("Favorite flavor:"));
    for (int i = 0; i < checkboxes.length; i++) column1.add(checkboxes[i]);

    // Handle events on the checkboxes
    ItemListener checkbox_listener =
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            textarea.append(
                "Your favorite flavor is: " + ((Checkbox) e.getItemSelectable()).getLabel() + "\n");
          }
        };
    for (int i = 0; i < checkboxes.length; i++) checkboxes[i].addItemListener(checkbox_listener);

    // Create a list of choices.
    List list = new List(4, true);
    list.addItem("Java");
    list.addItem("C");
    list.addItem("C++");
    list.addItem("Smalltalk");
    list.addItem("Lisp");
    list.addItem("Modula-3");
    list.addItem("Forth");
    column1.add(new Label("Favorite languages:"));
    column1.add(list);
    // Handle events on this list
    list.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            textarea.append("Your favorite languages are: ");
            String[] languages = ((List) e.getItemSelectable()).getSelectedItems();
            for (int i = 0; i < languages.length; i++) {
              if (i > 0) textarea.append(",");
              textarea.append(languages[i]);
            }
            textarea.append("\n");
          }
        });

    // Create a multi-line text area in column 2
    textarea = new TextArea(6, 40);
    textarea.setEditable(false);
    column2.add(new Label("Messages"));
    column2.add(textarea);

    // Create a scrollpane that displays portions of a larger component
    ScrollPane scrollpane = new ScrollPane();
    scrollpane.setSize(300, 150);
    column2.add(new Label("Scrolling Window"));
    column2.add(scrollpane);

    // Create a custom MultiLineLabel with a really big font and make it
    // a child of the ScrollPane container
    String message =
        "/*************************************************\n"
            + " * AllComponents.java                            *\n"
            + " * Written by David Flanagan                     *\n"
            + " * Copyright (c) 1997 by O'Reilly & Associates   *\n"
            + " *                                               *\n"
            + " *************************************************/\n";
    MultiLineLabel biglabel = new MultiLineLabel(message);
    biglabel.setFont(new Font("Monospaced", Font.BOLD + Font.ITALIC, 24));
    scrollpane.add(biglabel);
  }
コード例 #21
0
  Library() {
    super("Library Management");
    frame = this;
    try {
      UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception de) {
    }

    cp = getContentPane();
    cp.setLayout(null);

    // Adding TextArea in Panel
    jp1 = new JPanel(null, true);
    // t1=new
    // JTextField("|Name    "+"\t\t"+"  |Author"+"\t\t "+" |Publication   "+"\t"+"|Issue
    // "+"\t"+"|Return    "+"\t"+"|  Cutm. Id");
    // t1.setEditable(false);
    // t1.setBounds(0,0,600,20);
    // jp1.add(t1);

    MenuBar mb = new MenuBar();
    setMenuBar(mb);
    Menu menu2 = new Menu("Skins");
    MenuItem item4 = new MenuItem("Defualt Skin");
    MenuItem item5 = new MenuItem("Metal Skin");
    MenuItem item6 = new MenuItem("Modified Skin");
    // item5.setSelected(true);
    menu2.add(item4);
    menu2.add(item5);
    menu2.add(item6);
    mb.add(menu2);

    Menu menu21 = new Menu("Backup");
    MenuItem item61 = new MenuItem("Create Database Backup");
    menu21.add(item61);
    mb.add(menu21);

    // Menu menu1=new Menu("About");
    // MenuItem item1=new MenuItem("Help ?");
    // MenuItem item2=new MenuItem("Support ?");
    // MenuItem item3=new MenuItem("About Us ?");
    // menu1.add(item1);menu1.add(item2);menu1.add(item3);
    // mb.add(menu1);

    Menu menu212 = new Menu("Exit");
    MenuItem item612 = new MenuItem("Exit Form Library");
    menu212.add(item612);
    mb.add(menu212);

    int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS;
    int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;

    Color re = new Color(122, 145, 201);

    mo1 = new DefaultListModel();
    list1 = new JList(mo1);
    ml1 = new JLabel("    Book's Name");
    ml1.setForeground(Color.red);
    ml1.setBounds(15, 0, 154, 20);
    list1.setBounds(15, 20, 154, 500);
    list1.setToolTipText("NAme of Book's Present in Database");
    jp1.add(ml1);
    jp1.add(list1);

    mo2 = new DefaultListModel();
    list2 = new JList(mo2);
    ml2 = new JLabel("   Author");
    ml2.setForeground(re);
    ml2.setBounds(140 + 30, 0, 99, 20);
    list2.setToolTipText("Name of Book Author's Present in Database");
    list2.setBounds(140 + 30, 20, 99, 900);
    jp1.add(ml2);
    jp1.add(list2);

    mo3 = new DefaultListModel();
    list3 = new JList(mo3);
    ml3 = new JLabel("   Publication");
    ml3.setForeground(re);
    ml3.setBounds(240 + 30, 0, 99, 20);
    list3.setToolTipText("Name of Book's Publication Present in Database");
    list3.setBounds(240 + 30, 20, 99, 500);
    jp1.add(ml3);
    jp1.add(list3);

    mo4 = new DefaultListModel();
    list4 = new JList(mo4);
    ml4 = new JLabel("  Issue Date");
    ml4.setForeground(re);
    ml4.setBounds(340 + 30, 0, 70, 20);
    list4.setToolTipText("Date of Issue Present in Database");
    list4.setBounds(340 + 30, 20, 70, 500);
    jp1.add(ml4);
    jp1.add(list4);

    mo5 = new DefaultListModel();
    list5 = new JList(mo5);
    ml5 = new JLabel("   Return Date");
    ml5.setForeground(re);
    ml5.setBounds(411 + 30, 0, 70, 20);
    list5.setToolTipText("Date of Return Present in Database");
    list5.setBounds(411 + 30, 20, 70, 500);
    jp1.add(ml5);
    jp1.add(list5);

    mo6 = new DefaultListModel();
    list6 = new JList(mo6);
    ml6 = new JLabel("   Cust. ID");
    ml6.setForeground(re);
    ml6.setBounds(482 + 30, 0, 60, 20);
    list6.setToolTipText("ID of customer that purchase the book last time ");
    list6.setBounds(482 + 30, 20, 60, 500);
    jp1.add(ml6);
    jp1.add(list6);

    // a1=new JTextArea();
    // a1.setText("|Name    "+"\t\t\t"+"  |Author"+"\t\t\t"+" |Publication   "+"\t\t"+"|Issue
    // "+"\t\t"+"|Return    "+"\t\t"+"|  Cutm. Id");
    // a1.setEditable(false);
    // JScrollPane scroll=new JScrollPane(a1,v,h);
    // scroll.setBounds(0,20,600,578);
    // jp1.add(scroll);

    for (int x = 1; x < 100; x++) {
      sr = new JLabel(x + "\n");
      sr.setForeground(re);
      sr.setBounds(0, 20, 10, 500);
      jp1.add(sr);
    }

    // jp1.setBackground(Color.black);
    JScrollPane nm = new JScrollPane(jp1, v, h);
    nm.setBounds(10, 20, 600, 500);
    cp.add(nm);

    jp2 = new JPanel(null, true);

    b1 = new JButton("Add Book");
    b1.setBounds(10, 10, 120, 25);
    jp2.add(b1);

    b2 = new JButton("Delete Book");
    b2.setBounds(10, 45, 120, 25);
    jp2.add(b2);

    b3 = new JButton("View Book Details");
    b3.setBounds(10, 80, 120, 25);
    jp2.add(b3);

    b4 = new JButton("View All Book's");
    b4.setBounds(10, 115, 120, 25);
    jp2.add(b4);

    Color r = new Color(122, 145, 201);
    jp2.setBackground(r);
    jp2.setBounds(630, 20, 160, 145);
    cp.add(jp2);

    jp3 = new JPanel(null, true);

    t1 = new JTextField();
    t1.setBounds(10, 10, 120, 20);
    jp3.add(t1);
    t1.setToolTipText("Find The Book By Book Name. It is Advaced Search System");

    b5 = new JButton("Search Book Name");
    b5.setBounds(05, 35, 130, 20);
    jp3.add(b5);
    // b5.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,Event.CTRL_MASK));
    b5.setMnemonic(KeyEvent.VK_N);

    JLabel lk = new JLabel("__________________________________");
    lk.setForeground(Color.black);
    lk.setBounds(0, 50, 160, 6);
    jp3.add(lk);

    t14 = new JTextField();
    t14.setBounds(10, 60, 120, 20);
    jp3.add(t14);
    t14.setToolTipText("Find The Book By Author Name. It is Advaced Search System");

    b10 = new JButton("Search Author");
    b10.setBounds(05, 85, 130, 20);
    jp3.add(b10);

    // b10.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_a,Event.CTRL_MASK));
    b10.setMnemonic(KeyEvent.VK_N);

    Color r1 = new Color(122, 145, 201);
    jp3.setBackground(r1);
    jp3.setBounds(630, 180, 160, 115);
    cp.add(jp3);

    jp4 = new JPanel(null, true);

    b15 = new JButton("Add Customer");
    b15.setBounds(10, 05, 120, 25);
    jp4.add(b15);

    b6 = new JButton("View all Cotumers");
    b6.setBounds(10, 35, 120, 25);
    jp4.add(b6);

    t2 = new JTextField();
    t2.setBounds(10, 65, 120, 20);
    t2.setToolTipText("Find The Customer Information. It is Advaced Search System");
    jp4.add(t2);

    b7 = new JButton("Search");
    b7.setBounds(05, 90, 130, 20);
    jp4.add(b7);

    b8 = new JButton("Delete Costumer");
    b8.setBounds(10, 115, 120, 25);
    jp4.add(b8);

    b9 = new JButton("View Cust. Details");
    b9.setBounds(10, 150, 120, 25);
    jp4.add(b9);

    Color r3 = new Color(122, 145, 201);
    jp4.setBackground(r3);
    jp4.setBounds(630, 305, 160, 180);
    cp.add(jp4);

    b_no = new JLabel();
    b_no.setForeground(Color.red);
    b_no.setBounds(150, 0, 150, 20);
    cp.add(b_no);

    progress1 = new JProgressBar();
    progress1.setBackground(re);
    progress1.setBounds(630, 490, 150, 25);
    cp.add(progress1);

    try {
      rd1 = new FileReader("Database/pointer.mmm");
      read1 = new JTextField();
      read1.read(rd1, null);
      int count = Integer.parseInt(read1.getText());
      int total = count - 1;
      int blk = 0;
      rd1.close();

      for (int i = 1; i < count; i++) {
        rd1 = new FileReader("Database/" + i + ".name");
        read1 = new JTextField();
        read1.read(rd1, null);
        if (!read1.getText().equals("")) {
          blk++;
          b_no.setText("Total Books = " + blk + " (Book's)");
          mo1.addElement(read1.getText() + "");
          rd1.close();

          int per = i * 100 / total;
          progress1.setValue(per);

          rd1 = new FileReader("Database/" + i + ".author");
          read1 = new JTextField();
          read1.read(rd1, null);
          mo2.addElement(read1.getText() + "");
          rd1.close();

          rd1 = new FileReader("Database/" + i + ".publication");
          read1 = new JTextField();
          read1.read(rd1, null);
          mo3.addElement(read1.getText() + "");
          rd1.close();

          rd1 = new FileReader("Database/" + i + ".issue");
          read1 = new JTextField();
          read1.read(rd1, null);
          if (!read1.getText().equals("")) {
            mo4.addElement(read1.getText() + "");
          } else {
            mo4.addElement(read1.getText() + "   -");
          }
          rd1.close();

          rd1 = new FileReader("Database/" + i + ".return");
          read1 = new JTextField();
          read1.read(rd1, null);
          mo5.addElement(read1.getText() + "");
          rd1.close();

          rd1 = new FileReader("Database/" + i + ".id");
          read1 = new JTextField();
          read1.read(rd1, null);
          mo6.addElement(read1.getText() + "");
          rd1.close();
        }
      }
    } catch (Exception der) {
      a1.setText("Error Occurs: \n" + der);
    }

    // Source code for searching the book's from Database
    // it search book by name of book,author,publication
    // it work when you don't know about any thing than press any
    // keyword to find book/
    // eg: if you have book name that publish by that publication which
    // starts from "c"
    // then you press only "c" in search it show you all Books that start
    // with "c" ,Author "c" and publication that start "c" .

    // Warning:
    // Don't Modify the code without knowledge of full source code
    // Author : Pravin Rane

    b5.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              int bs1 = 0;
              progress1.setValue(0);
              mo1.removeAllElements();
              mo2.removeAllElements();
              mo3.removeAllElements();
              mo4.removeAllElements();
              mo5.removeAllElements();
              mo6.removeAllElements();

              ml1.setText("Book Name");
              ml2.setText("Author");
              ml3.setText("Publication");
              ml4.setText("Issue Date");
              ml5.setText("Return Date");
              ml6.setText("Cust. ID.");

              if (!t1.getText().equals("")) {
                rd1 = new FileReader("Database/pointer.mmm");
                read1 = new JTextField();
                read1.read(rd1, null);
                int no = Integer.parseInt(read1.getText());
                rd1.close();

                int len = t1.getText().length();
                for (int k = 0; k < len; k++) {
                  char ch = t1.getText().charAt(k);
                  stra1 = stra1 + ch;
                  // System.out.println(stra1+"");
                }

                for (int v = 1; v < no; v++) {
                  name11 = "";
                  author11 = "";
                  publication11 = "";
                  progress1.setMaximum(no);

                  int per = v * 100 / no;
                  progress1.updateUI();
                  progress1.setValue(per);

                  FileReader re1 = new FileReader("Database/" + v + ".name");
                  JTextField jt1 = new JTextField();
                  jt1.read(re1, null);
                  String name = jt1.getText();
                  re1.close();

                  FileReader re2 = new FileReader("Database/" + v + ".author");
                  JTextField jt2 = new JTextField();
                  jt2.read(re2, null);
                  String author = jt2.getText();
                  re2.close();

                  FileReader re3 = new FileReader("Database/" + v + ".publication");
                  JTextField jt3 = new JTextField();
                  jt3.read(re3, null);
                  String publication = jt3.getText();
                  re3.close();
                  find = v;

                  try {
                    for (int z = 0; z < len; z++) {

                      name11 = name11 + name.charAt(z);

                      // author11=author11+author.charAt(z);
                      // System.out.println(author11+"");
                      publication11 = publication11 + publication.charAt(z);
                      if (z == (len - 1)) {
                        // System.out.println(name11+"");
                        // System.out.println(publication11+"");
                      }
                    }

                  } catch (Exception def) {
                  }

                  if (name.toLowerCase().equals(t1.getText())
                      || name.toUpperCase().equals(t1.getText())
                      || author.toLowerCase().equals(t1.getText())
                      || author.toUpperCase().equals(t1.getText())
                      || publication.toLowerCase().equals(t1.getText())
                      || publication.toUpperCase().equals(t1.getText())) {
                    bs1++;
                    rd1 = new FileReader("Database/" + find + ".name");
                    read1 = new JTextField();
                    read1.read(rd1, null);
                    mo1.addElement(read1.getText() + "");
                    rd1.close();

                    rd1 = new FileReader("Database/" + find + ".author");
                    read1 = new JTextField();
                    read1.read(rd1, null);
                    mo2.addElement(read1.getText() + "");
                    rd1.close();

                    rd1 = new FileReader("Database/" + find + ".publication");
                    read1 = new JTextField();
                    read1.read(rd1, null);
                    mo3.addElement(read1.getText() + "");
                    rd1.close();

                    rd1 = new FileReader("Database/" + find + ".issue");
                    read1 = new JTextField();
                    read1.read(rd1, null);
                    mo4.addElement(read1.getText() + "");
                    rd1.close();

                    rd1 = new FileReader("Database/" + find + ".return");
                    read1 = new JTextField();
                    read1.read(rd1, null);
                    mo5.addElement(read1.getText() + "");
                    rd1.close();

                    rd1 = new FileReader("Database/" + find + ".id");
                    read1 = new JTextField();
                    read1.read(rd1, null);
                    mo6.addElement(read1.getText() + "");
                    rd1.close();

                  } else if (publication11.toLowerCase().equals(t1.getText())
                      || author11.toLowerCase().equals(t1.getText())
                      || name11.toLowerCase().equals(t1.getText())
                      || publication11.toUpperCase().equals(t1.getText())
                      || author11.toUpperCase().equals(t1.getText())
                      || name11.toUpperCase().equals(t1.getText())) {
                    bs1++;

                    rd1 = new FileReader("Database/" + find + ".name");
                    read1 = new JTextField();
                    read1.read(rd1, null);
                    mo1.addElement(read1.getText() + "");
                    rd1.close();

                    rd1 = new FileReader("Database/" + find + ".author");
                    read1 = new JTextField();
                    read1.read(rd1, null);
                    mo2.addElement(read1.getText() + "");
                    rd1.close();

                    rd1 = new FileReader("Database/" + find + ".publication");
                    read1 = new JTextField();
                    read1.read(rd1, null);
                    mo3.addElement(read1.getText() + "");
                    rd1.close();

                    rd1 = new FileReader("Database/" + find + ".issue");
                    read1 = new JTextField();
                    read1.read(rd1, null);
                    mo4.addElement(read1.getText() + "");
                    rd1.close();

                    rd1 = new FileReader("Database/" + find + ".return");
                    read1 = new JTextField();
                    read1.read(rd1, null);
                    mo5.addElement(read1.getText() + "");
                    rd1.close();

                    rd1 = new FileReader("Database/" + find + ".id");
                    read1 = new JTextField();
                    read1.read(rd1, null);
                    mo6.addElement(read1.getText() + "");
                    rd1.close();
                  }

                  b_no.setText("Total Book Found =" + bs1 + " (Book's)");
                }

              } else {
                progress1.setValue(0);
                JOptionPane.showMessageDialog(
                    (Component) null,
                    "Please Enter the Book Name or Publcation",
                    "Library Management(Pravin Rane)",
                    JOptionPane.OK_OPTION);
                b_no.setText("User Input Error!");
              }

            } catch (Exception der) {
              System.out.println("Error:" + der);
            }
          }
        });

    b10.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              int bs2 = 0;
              progress1.setValue(0);
              mo1.removeAllElements();
              mo2.removeAllElements();
              mo3.removeAllElements();
              mo4.removeAllElements();
              mo5.removeAllElements();
              mo6.removeAllElements();

              ml1.setText("Book Name");
              ml2.setText("Author");
              ml3.setText("Publication");
              ml4.setText("Issue Date");
              ml5.setText("Return Date");
              ml6.setText("Cust. ID.");

              if (!t14.getText().equals("")) {

                rd1 = new FileReader("Database/pointer.mmm");
                read1 = new JTextField();
                read1.read(rd1, null);
                int no = Integer.parseInt(read1.getText());
                rd1.close();

                int len = t14.getText().length();
                for (int k = 0; k < len; k++) {
                  char ch = t14.getText().charAt(k);
                  stra1 = stra1 + ch;
                  // System.out.println(stra1+"");
                }

                for (int v = 1; v < no; v++) {
                  name11 = "";
                  author11 = "";
                  publication11 = "";
                  progress1.setMaximum(no);

                  int per = v * 100 / no;
                  progress1.updateUI();
                  progress1.setValue(per);

                  FileReader re1 = new FileReader("Database/" + v + ".name");
                  JTextField jt1 = new JTextField();
                  jt1.read(re1, null);
                  String name = jt1.getText();
                  re1.close();

                  FileReader re2 = new FileReader("Database/" + v + ".author");
                  JTextField jt2 = new JTextField();
                  jt2.read(re2, null);
                  String author = jt2.getText();
                  re2.close();

                  FileReader re3 = new FileReader("Database/" + v + ".publication");
                  JTextField jt3 = new JTextField();
                  jt3.read(re3, null);
                  String publication = jt3.getText();
                  re3.close();
                  find = v;

                  try {
                    for (int z = 0; z < len; z++) {

                      // name11=name11+name.charAt(z);

                      author11 = author11 + author.charAt(z);
                      // System.out.println(author11+"");
                      // publication11=publication11+publication.charAt(z);
                      if (z == (len - 1)) {
                        // System.out.println(name11+"");
                        // System.out.println(publication11+"");
                      }
                    }

                  } catch (Exception def) {
                  }

                  if (author.toLowerCase().equals(t14.getText())
                      || author.toUpperCase().equals(t14.getText())) {
                    bs2++;
                    rd1 = new FileReader("Database/" + find + ".name");
                    read1 = new JTextField();
                    read1.read(rd1, null);
                    mo1.addElement(read1.getText() + "");
                    rd1.close();

                    rd1 = new FileReader("Database/" + find + ".author");
                    read1 = new JTextField();
                    read1.read(rd1, null);
                    mo2.addElement(read1.getText() + "");
                    rd1.close();

                    rd1 = new FileReader("Database/" + find + ".publication");
                    read1 = new JTextField();
                    read1.read(rd1, null);
                    mo3.addElement(read1.getText() + "");
                    rd1.close();

                    rd1 = new FileReader("Database/" + find + ".issue");
                    read1 = new JTextField();
                    read1.read(rd1, null);
                    mo4.addElement(read1.getText() + "");
                    rd1.close();

                    rd1 = new FileReader("Database/" + find + ".return");
                    read1 = new JTextField();
                    read1.read(rd1, null);
                    mo5.addElement(read1.getText() + "");
                    rd1.close();

                    rd1 = new FileReader("Database/" + find + ".id");
                    read1 = new JTextField();
                    read1.read(rd1, null);
                    mo6.addElement(read1.getText() + "");
                    rd1.close();

                  } else if (author11.toLowerCase().equals(t14.getText())
                      || author11.toUpperCase().equals(t14.getText())) {
                    bs2++;

                    rd1 = new FileReader("Database/" + find + ".name");
                    read1 = new JTextField();
                    read1.read(rd1, null);
                    mo1.addElement(read1.getText() + "");
                    rd1.close();

                    rd1 = new FileReader("Database/" + find + ".author");
                    read1 = new JTextField();
                    read1.read(rd1, null);
                    mo2.addElement(read1.getText() + "");
                    rd1.close();

                    rd1 = new FileReader("Database/" + find + ".publication");
                    read1 = new JTextField();
                    read1.read(rd1, null);
                    mo3.addElement(read1.getText() + "");
                    rd1.close();

                    rd1 = new FileReader("Database/" + find + ".issue");
                    read1 = new JTextField();
                    read1.read(rd1, null);
                    mo4.addElement(read1.getText() + "");
                    rd1.close();

                    rd1 = new FileReader("Database/" + find + ".return");
                    read1 = new JTextField();
                    read1.read(rd1, null);
                    mo5.addElement(read1.getText() + "");
                    rd1.close();

                    rd1 = new FileReader("Database/" + find + ".id");
                    read1 = new JTextField();
                    read1.read(rd1, null);
                    mo6.addElement(read1.getText() + "");
                    rd1.close();
                  }

                  b_no.setText("Total Book Found =" + bs2 + " (Book's)");
                }
              } else {
                progress1.setValue(0);
                b_no.setText("User Input Error!");
                JOptionPane.showMessageDialog(
                    (Component) null,
                    "Please Enter the Book Author name",
                    "Library Management(Pravin Rane)",
                    JOptionPane.OK_OPTION);
              }
            } catch (Exception der) {
              System.out.println("Error:" + der);
            }
          }
        });

    // End of Serching Book
    // Author : Pravin Rane

    // it use to aplly the skins to UserInteface
    // there are three skins Default which is Windows Skin
    // Metal skin and modified skin.
    // apply it as oer ur requirment.
    // Author : Pravin H. Rane

    item4.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
              SwingUtilities.updateComponentTreeUI(frame);
            } catch (Exception dert) {
              System.out.println(dert);
            }
          }
        });

    item5.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
              SwingUtilities.updateComponentTreeUI(frame);
            } catch (Exception dert) {
              System.out.println(dert);
            }
          }
        });

    item6.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
              SwingUtilities.updateComponentTreeUI(frame);
            } catch (Exception dert) {
              System.out.println(dert);
            }
          }
        });

    item61.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              Date d = new Date();
              int my1 = d.getDate();
              int my2 = d.getMonth();

              FileDialog fd =
                  new FileDialog(frame, "Save Database Backup File (Library Management )");
              fd.setMode(FileDialog.SAVE);
              fd.setFile("Database" + my1 + "." + my2 + ".rar");
              fd.setVisible(true);
              String dir = fd.getDirectory();
              String path = fd.getFile();

              String command = "jar cvf Database1.rar Database/*.*";
              Runtime r = Runtime.getRuntime();
              r.exec(command);

              String command2 = "jar cvf  Database2.rar Cust_Details/*.*";
              Runtime r2 = Runtime.getRuntime();
              r2.exec(command2);

              try {
                Thread.sleep(1000);
              } catch (Exception fr) {
              }
              String command3 = "jar cvf " + dir + path + " Database1.rar  Database2.rar";
              Runtime r3 = Runtime.getRuntime();
              r3.exec(command3);

              System.out.println("Database Backup Sucessfully!");

            } catch (Exception dert) {
              System.out.println(dert);
            }
          }
        });

    item612.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            System.exit(0);
          }
        });

    // End Of Applyinf Skin to UInterface

    // This Button show the details of Book's
    // that specified when the book is adding in the database
    // you can modify the details of book.
    // Author : Pravin H. Rane

    b3.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              // view v=new view(String str,string info,boolean val);

            } catch (Exception der) {
            }
          }
        });

    // End of book details

    b15.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            Addcust ad = new Addcust();
            ad.setVisible(true);
            ad.setSize(380, 400);
            ad.setLocation(80, 140);
          }
        });

    // it show all book's available in database
    // it dosn't sort book by sequensely
    // you can modify the code for sorting the book as per your requirement
    // Author : Pravin

    b1.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            addBook a = new addBook();
          }
        });

    b4.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {

            try {
              mo1.removeAllElements();
              mo2.removeAllElements();
              mo3.removeAllElements();
              mo4.removeAllElements();
              mo5.removeAllElements();
              mo6.removeAllElements();

              ml1.setText("Book Name");
              ml2.setText("Author");
              ml3.setText("Publication");
              ml4.setText("Issue Date");
              ml5.setText("Return Date");
              ml6.setText("Cust. ID.");
              int za = 0;

              rd1 = new FileReader("Database/pointer.mmm");
              read1 = new JTextField();
              read1.read(rd1, null);
              int count = Integer.parseInt(read1.getText());
              int total = count - 1;

              rd1.close();

              for (int i = 1; i < count; i++) {

                rd1 = new FileReader("Database/" + i + ".name");
                read1 = new JTextField();
                read1.read(rd1, null);
                if (!read1.getText().equals("")) {
                  za++;
                  b_no.setText("Total Books = " + za + " (Book's)");
                  mo1.addElement(read1.getText() + "");
                  rd1.close();

                  progress1.setMaximum(total);
                  int per = i * 100 / total;
                  progress1.setValue(per);

                  rd1 = new FileReader("Database/" + i + ".author");
                  read1 = new JTextField();
                  read1.read(rd1, null);
                  mo2.addElement(read1.getText() + "");
                  rd1.close();

                  rd1 = new FileReader("Database/" + i + ".publication");
                  read1 = new JTextField();
                  read1.read(rd1, null);
                  mo3.addElement(read1.getText() + "");
                  rd1.close();

                  rd1 = new FileReader("Database/" + i + ".issue");
                  read1 = new JTextField();
                  read1.read(rd1, null);
                  if (!read1.getText().equals("")) {
                    mo4.addElement(read1.getText() + "");
                  } else {
                    mo4.addElement(read1.getText() + "   _");
                  }
                  rd1.close();

                  rd1 = new FileReader("Database/" + i + ".return");
                  read1 = new JTextField();
                  read1.read(rd1, null);
                  mo5.addElement(read1.getText() + "");
                  rd1.close();

                  rd1 = new FileReader("Database/" + i + ".id");
                  read1 = new JTextField();
                  read1.read(rd1, null);
                  mo6.addElement(read1.getText() + "");
                  rd1.close();

                  progress1.setValue(100);
                }
              }
            } catch (Exception der) {
              a1.setText("Error Occurs: \n" + der);
            }
          }
        });
    // End of View all Book's

    // This source code is used to show information of all customers
    // Author :Pravin Rane

    b6.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {

              ml1.setText("Cust. ID");
              ml2.setText("Cust. Name");
              ml3.setText("Registration Date");
              ml4.setText("Book Name");
              ml5.setText("Purchase Date");
              ml6.setText("Return Date");

              int z12 = 0;

              mo1.removeAllElements();
              mo2.removeAllElements();
              mo3.removeAllElements();
              mo4.removeAllElements();
              mo5.removeAllElements();
              mo6.removeAllElements();

              rd2 = new FileReader("Cust_Details/pointer.mmm");
              jt2 = new JTextField();
              jt2.read(rd2, null);
              rd2.close();

              int no = Integer.parseInt(jt2.getText());
              int tt = no - 1;
              // b_no.setText("Total Customer's :"+tt );

              for (int v = 1; v < no; v++) {

                rd2 = new FileReader("Cust_Details/Cus" + v + ".id");
                jt2 = new JTextField();
                jt2.read(rd2, null);
                if (!jt2.getText().equals("")) {
                  z12++;
                  b_no.setText("Total Customers = " + z12);
                  mo1.addElement(jt2.getText() + "");
                  rd2.close();

                  rd2 = new FileReader("Cust_Details/Cus" + v + ".name");
                  jt2 = new JTextField();
                  jt2.read(rd2, null);
                  mo2.addElement(jt2.getText() + "");
                  rd2.close();

                  rd2 = new FileReader("Cust_Details/Cus" + v + ".date");
                  jt2 = new JTextField();
                  jt2.read(rd2, null);
                  mo3.addElement(jt2.getText() + "");
                  rd2.close();

                  rd2 = new FileReader("Cust_Details/Cus" + v + ".bname");
                  jt2 = new JTextField();
                  jt2.read(rd2, null);
                  if (!jt2.getText().equals("")) {
                    mo4.addElement(jt2.getText() + "");
                  } else {
                    mo4.addElement(jt2.getText() + "   _");
                  }
                  rd2.close();

                  rd2 = new FileReader("Cust_Details/Cus" + v + ".purchase");
                  jt2 = new JTextField();
                  jt2.read(rd2, null);
                  if (!jt2.getText().equals("")) {
                    mo5.addElement(jt2.getText() + "");
                  } else {
                    mo5.addElement(jt2.getText() + "   _");
                  }
                  rd2.close();

                  rd2 = new FileReader("Cust_Details/Cus" + v + ".return");
                  jt2 = new JTextField();
                  jt2.read(rd2, null);
                  if (!jt2.getText().equals("")) {
                    mo6.addElement(jt2.getText() + "");
                  } else {
                    mo6.addElement(jt2.getText() + "   _");
                  }
                  rd2.close();
                }
              }

            } catch (Exception ser) {
              System.out.println(ser);
            }
          }
        });
    // End of showing customer's Info.

    b9.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {

              int ad = list1.getSelectedIndex();
              String str = (String) mo1.getElementAt(ad);

              System.out.println(str);

              cust_detail d = new cust_detail(str);
              d.setVisible(true);
              d.setSize(300, 550);
              d.setLocation(100, 0);
            } catch (Exception fr) {
              JOptionPane.showMessageDialog(
                  (Component) null,
                  "Please Select Customer ID from List of Cust. ID. ",
                  "Library Management(Pravin Rane)",
                  JOptionPane.OK_OPTION);
              try {
                ml1.setText("Cust. ID");
                ml2.setText("Cust. Name");
                ml3.setText("Registration Date");
                ml4.setText("Book Name");
                ml5.setText("Purchase Date");
                ml6.setText("Return Date");

                mo1.removeAllElements();
                mo2.removeAllElements();
                mo3.removeAllElements();
                mo4.removeAllElements();
                mo5.removeAllElements();
                mo6.removeAllElements();

                rd2 = new FileReader("Cust_Details/pointer.mmm");
                jt2 = new JTextField();
                jt2.read(rd2, null);
                rd2.close();
                int no = Integer.parseInt(jt2.getText());

                for (int v = 1; v < no; v++) {
                  rd2 = new FileReader("Cust_Details/Cus" + v + ".id");
                  jt2 = new JTextField();
                  jt2.read(rd2, null);
                  mo1.addElement(jt2.getText() + "");
                  rd2.close();

                  rd2 = new FileReader("Cust_Details/Cus" + v + ".name");
                  jt2 = new JTextField();
                  jt2.read(rd2, null);
                  mo2.addElement(jt2.getText() + "");
                  rd2.close();

                  rd2 = new FileReader("Cust_Details/Cus" + v + ".date");
                  jt2 = new JTextField();
                  jt2.read(rd2, null);
                  mo3.addElement(jt2.getText() + "");
                  rd2.close();

                  rd2 = new FileReader("Cust_Details/Cus" + v + ".bname");
                  jt2 = new JTextField();
                  jt2.read(rd2, null);
                  if (!jt2.getText().equals("")) {
                    mo4.addElement(jt2.getText() + "");
                  } else {
                    mo4.addElement(jt2.getText() + "   _");
                  }
                  rd2.close();

                  rd2 = new FileReader("Cust_Details/Cus" + v + ".purchase");
                  jt2 = new JTextField();
                  jt2.read(rd2, null);
                  if (!jt2.getText().equals("")) {
                    mo5.addElement(jt2.getText() + "");
                  } else {
                    mo5.addElement(jt2.getText() + "   _");
                  }
                  rd2.close();

                  rd2 = new FileReader("Cust_Details/Cus" + v + ".return");
                  jt2 = new JTextField();
                  jt2.read(rd2, null);
                  if (!jt2.getText().equals("")) {
                    mo6.addElement(jt2.getText() + "");
                  } else {
                    mo6.addElement(jt2.getText() + "   _");
                  }
                  rd2.close();
                }
              } catch (Exception fg) {
              }
            }
          }
        });

    b7.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            String mysearchid = t2.getText();
            try {
              ml1.setText("Cust. ID");
              ml2.setText("Cust. Name");
              ml3.setText("Registration Date");
              ml4.setText("Book Name");
              ml5.setText("Purchase Date");
              ml6.setText("Return Date");

              mo1.removeAllElements();
              mo2.removeAllElements();
              mo3.removeAllElements();
              mo4.removeAllElements();
              mo5.removeAllElements();
              mo6.removeAllElements();

              if (!t2.getText().equals("")) {
                rd2 = new FileReader("Cust_Details/pointer.mmm");
                jt2 = new JTextField();
                jt2.read(rd2, null);
                rd2.close();
                int no = Integer.parseInt(jt2.getText());

                int len3 = t2.getText().length();

                for (int v = 1; v < no; v++) {
                  name22 = "";
                  int lg = 0;
                  rd2 = new FileReader("Cust_Details/Cus" + v + ".id");
                  jt2 = new JTextField();
                  jt2.read(rd2, null);
                  // mo1.addElement(jt2.getText()+"");
                  String s1 = jt2.getText();
                  rd2.close();

                  rd2 = new FileReader("Cust_Details/Cus" + v + ".name");
                  jt2 = new JTextField();
                  jt2.read(rd2, null);
                  // mo2.addElement(jt2.getText()+"");
                  String s2 = jt2.getText();
                  rd2.close();

                  for (int z = 0; z < len3; z++) {
                    name22 = name22 + s2.charAt(z);
                  }

                  if (s1.toLowerCase().equals(mysearchid)
                      || s1.toUpperCase().equals(mysearchid)
                      || s2.toLowerCase().equals(mysearchid)
                      || s2.toUpperCase().equals(mysearchid)
                      || name22.toUpperCase().equals(mysearchid)
                      || name22.toLowerCase().equals(mysearchid)) {
                    lg++;
                    b_no.setText("Customer Found :" + lg);
                    rd2 = new FileReader("Cust_Details/Cus" + v + ".id");
                    jt2 = new JTextField();
                    jt2.read(rd2, null);
                    mo1.addElement(jt2.getText() + "");
                    rd2.close();

                    rd2 = new FileReader("Cust_Details/Cus" + v + ".name");
                    jt2 = new JTextField();
                    jt2.read(rd2, null);
                    mo2.addElement(jt2.getText() + "");
                    rd2.close();

                    rd2 = new FileReader("Cust_Details/Cus" + v + ".date");
                    jt2 = new JTextField();
                    jt2.read(rd2, null);
                    mo3.addElement(jt2.getText() + "");
                    rd2.close();

                    rd2 = new FileReader("Cust_Details/Cus" + v + ".bname");
                    jt2 = new JTextField();
                    jt2.read(rd2, null);
                    if (!jt2.getText().equals("")) {
                      mo4.addElement(jt2.getText() + "");
                    } else {
                      mo4.addElement(jt2.getText() + "   _");
                    }
                    rd2.close();

                    rd2 = new FileReader("Cust_Details/Cus" + v + ".purchase");
                    jt2 = new JTextField();
                    jt2.read(rd2, null);
                    if (!jt2.getText().equals("")) {
                      mo5.addElement(jt2.getText() + "");
                    } else {
                      mo5.addElement(jt2.getText() + "   _");
                    }
                    rd2.close();

                    rd2 = new FileReader("Cust_Details/Cus" + v + ".return");
                    jt2 = new JTextField();
                    jt2.read(rd2, null);
                    if (!jt2.getText().equals("")) {
                      mo6.addElement(jt2.getText() + "");
                    } else {
                      mo6.addElement(jt2.getText() + "   _");
                    }
                    rd2.close();
                  }
                }
              } else {
                progress1.setValue(0);
                b_no.setText("User Input Error!");
                JOptionPane.showMessageDialog(
                    (Component) null,
                    "Please Enter Customer Id or Name",
                    "Library Management(Pravin Rane)",
                    JOptionPane.OK_OPTION);
              }

            } catch (Exception de) {
            }
          }
        });

    b2.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            int ad = list1.getSelectedIndex();
            String str99 = (String) mo1.getElementAt(ad);
            try {

              rd2 = new FileReader("Database/pointer.mmm");
              jt2 = new JTextField();
              jt2.read(rd2, null);
              rd2.close();
              int nom = Integer.parseInt(jt2.getText());

              for (int count2 = 1; count2 < nom; count2++) {
                rd1 = new FileReader("Database/" + count2 + ".name");
                read1 = new JTextField();
                read1.read(rd1, null);
                rd1.close();

                if (read1.getText().equals(str99)) {
                  wr1 = new FileWriter("Database/" + count2 + ".name");
                  wr1.write("");
                  wr1.close();

                  wr1 = new FileWriter("Database/" + count2 + ".author");
                  wr1.write("");
                  wr1.close();

                  wr1 = new FileWriter("Database/" + count2 + ".publication");
                  wr1.write("");
                  wr1.close();

                  wr1 = new FileWriter("Database/" + count2 + ".issue");
                  wr1.write("");
                  wr1.close();

                  wr1 = new FileWriter("Database/" + count2 + ".return");
                  wr1.write("");
                  wr1.close();

                  wr1 = new FileWriter("Database/" + count2 + ".detail");
                  wr1.write("");
                  wr1.close();

                  wr1 = new FileWriter("Database/" + count2 + ".id");
                  wr1.write("");
                  wr1.close();
                  try {
                    Library lbc = new Library();
                    setVisible(false);
                    lbc.setVisible(true);
                    lbc.setSize(800, 600);
                  } catch (Exception de) {
                  }
                }
              }

            } catch (Exception fr) {
              System.out.println(fr);
            }
          }
        });

    b3.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              int ad = list1.getSelectedIndex();
              String str34 = (String) mo1.getElementAt(ad);

              jf55 = new JFrame("Book Details");
              jf55.setVisible(true);
              jf55.setLayout(null);
              jf55.setLocation(160, 180);

              JTextArea ak47 = new JTextArea();
              ak47.setEditable(false);
              ak47.setText(
                  "Book Details" + "\n" + "**************************************************");
              ak47.setBounds(10, 10, 250, 250);
              jf55.add(ak47);

              Button b1 = new Button("Ok");
              b1.setBounds(80, 270, 100, 25);
              jf55.add(b1);
              b1.addActionListener(
                  new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                      jf55.setVisible(false);
                    }
                  });

              jf55.setSize(285, 335);

              rd2 = new FileReader("Database/pointer.mmm");
              jt2 = new JTextField();
              jt2.read(rd2, null);
              rd2.close();
              int nov = Integer.parseInt(jt2.getText());

              for (int i = 1; i < nov; i++) {
                rd1 = new FileReader("Database/" + i + ".name");
                read1 = new JTextField();
                read1.read(rd1, null);
                String hj = read1.getText();
                rd1.close();

                if (hj.equals(str34)) {
                  rd1 = new FileReader("Database/" + i + ".name");
                  read1 = new JTextField();
                  read1.read(rd1, null);
                  if (!read1.getText().equals("")) {
                    ak47.setText(ak47.getText() + "\n" + "Book Name :" + read1.getText());
                    rd1.close();

                    rd1 = new FileReader("Database/" + i + ".author");
                    read1 = new JTextField();
                    read1.read(rd1, null);
                    ak47.setText(ak47.getText() + "\n" + "Book Author :" + read1.getText());
                    rd1.close();

                    rd1 = new FileReader("Database/" + i + ".publication");
                    read1 = new JTextField();
                    read1.read(rd1, null);
                    ak47.setText(ak47.getText() + "\n" + "Book Publication :" + read1.getText());
                    rd1.close();

                    rd1 = new FileReader("Database/" + i + ".issue");
                    read1 = new JTextField();
                    read1.read(rd1, null);
                    if (!read1.getText().equals("")) {
                      ak47.setText(ak47.getText() + "\n" + "Issue Date :" + read1.getText());
                    } else {
                      ak47.setText(ak47.getText() + "\n" + "Issue Date : None");
                    }
                    rd1.close();

                    rd1 = new FileReader("Database/" + i + ".return");
                    read1 = new JTextField();
                    read1.read(rd1, null);
                    ak47.setText(ak47.getText() + "\n" + "Return Date :" + read1.getText());
                    rd1.close();

                    rd1 = new FileReader("Database/" + i + ".id");
                    read1 = new JTextField();
                    read1.read(rd1, null);
                    ak47.setText(ak47.getText() + "\n" + "Cust. Id :" + read1.getText());
                    rd1.close();

                    rd1 = new FileReader("Database/" + i + ".detail");
                    read1 = new JTextField();
                    read1.read(rd1, null);
                    if (!read1.getText().equals("")) {
                      ak47.setText(ak47.getText() + "\n" + "Other Details : \n" + read1.getText());
                    } else {
                      ak47.setText(ak47.getText() + "\n" + "Other Details : Not Found");
                    }
                    rd1.close();
                  }
                }
              }

            } catch (Exception de) {
              JOptionPane.showMessageDialog(
                  (Component) null,
                  "Please Select Book Name from List",
                  "Library Management(Pravin Rane)",
                  JOptionPane.OK_OPTION);
            }
          }
        });
  }
コード例 #22
0
ファイル: dbfShow.java プロジェクト: akerigan/staxer
  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);
  }
コード例 #23
0
ファイル: Hw2.java プロジェクト: citrit/ECSE4750
  public static void main(String argv[]) {
    PolylineCell polyLCell = new PolylineCell(); // new class
    TriangleCell triCell = new TriangleCell(); // new class
    PointSet myPts = new PointSet();
    PointCell ptCell = new PointCell();
    LineCell lCell = new LineCell();
    LineCell sCell = new LineCell();
    PolygonCell pCell = new PolygonCell();
    Material mat;
    MaterialSet matSet = new MaterialSet();
    Actor actor = new Actor();
    OGLRenderer aren = new OGLRenderer();
    int count, shape, j, i, k;
    float tmp[] = new float[3];
    float rgba[] = new float[3];
    objectReader in = new objectReader(argv[0]);
    PointType data;

    while (!in.eof()) {
      shape = in.getInt();
      count = in.getInt();
      for (i = 0; i < 3; i++) rgba[i] = in.getFloat(); // get color

      switch (shape) {
        case 0: // coord. of points
          myPts = new PointSet();
          for (i = 0; i < count; i++) {
            for (j = 0; j < 3; j++) tmp[j] = in.getFloat(); // get the x,y,z coord.
            data = new PointType(tmp);
            myPts.addPoint(data);
          }
          break;
        case 1: // a point
          ptCell = new PointCell();
          matSet = new MaterialSet();
          mat = new Material(rgba[0], rgba[1], rgba[2], 0);
          matSet.addMaterial(mat); // set color
          for (i = 0; i < count; i++) ptCell.addVal(in.getInt()); // get point
          ptCell.setMaterials(matSet);
          ptCell.setPoints(myPts);
          actor.addCell(ptCell); // add it to the entity
          break;
        case 2: // a line
          lCell = new LineCell();
          matSet = new MaterialSet();
          mat = new Material(rgba[0], rgba[1], rgba[2], 0);
          matSet.addMaterial(mat); // set color
          for (i = 0; i < count; i++) // read 2 numbers
          for (j = 0; j < 2; j++) lCell.addVal(in.getInt());
          lCell.setMaterials(matSet);
          lCell.setPoints(myPts);
          actor.addCell(lCell); // add to entity
          break;
        case 3: // a polygon
          pCell = new PolygonCell();
          matSet = new MaterialSet();
          mat = new Material(rgba[0], rgba[1], rgba[2], 0);
          matSet.addMaterial(mat); // set color
          for (i = 0; i < count; i++)
            while ((j = in.getInt()) != -1) // read until -1 for each set
            pCell.addVal(j);
          pCell.setMaterials(matSet);
          pCell.setPoints(myPts);
          actor.addCell(pCell); // add to entity
          break;
        case 4: // a triangle
          triCell = new TriangleCell();
          matSet = new MaterialSet();
          mat = new Material(rgba[0], rgba[1], rgba[2], 0);
          matSet.addMaterial(mat); // set color
          for (i = 0; i < count; i++)
            for (k = 0; k < 3; k++) triCell.addVal(in.getInt()); // read 3 numbers
          triCell.setMaterials(matSet);
          triCell.setPoints(myPts);
          actor.addCell(triCell); // add to entity
          break;
        case 5: // a polyline
          polyLCell = new PolylineCell();
          matSet = new MaterialSet();
          mat = new Material(rgba[0], rgba[1], rgba[2], 0); // set color
          matSet.addMaterial(mat);
          for (i = 0; i < count; i++)
            while ((j = in.getInt()) != -1) // read until -1 for each set
            polyLCell.addVal(j);
          polyLCell.setMaterials(matSet);
          polyLCell.setPoints(myPts);
          actor.addCell(polyLCell); // add to entity
          break;
      }
    }

    // Add this  DataSet to the Renderers collection.
    aren.addActor(actor);
    aren.addCamera(new OGLCamera());
    aren.addLight(new OGLLight(0));

    Hw2 hw2 = new Hw2();
    hw2.renderer = aren;
    hw2.act = actor;
    // Make it visible and set size
    aren.setVisible(true);
    aren.setSize(300, 300);
    aren.getCamera().setFrom(0.0F, 5.0F, 15.0F);
    System.out.println("Here we go");

    // Add the canvas to the frame and make it show
    hw2.add("Center", aren);
    hw2.pack();

    // Set up the menu
    MenuBar mb = new MenuBar();
    Menu file = new Menu("File");
    file.add(new MenuItem("Run"));
    mb.add(file);
    hw2.setMenuBar(mb);

    hw2.show();
  }