コード例 #1
0
ファイル: ImageFrame.java プロジェクト: msramosjr/DarwinsBox
  public ImageFrame(int width, int height) throws HeadlessException {
    main = new JPanel();
    main.setLayout(new BoxLayout(main, BoxLayout.X_AXIS));
    ScrollPane scroll = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
    getContentPane().add(scroll);
    scroll.add(main);

    setPreferredSize(new Dimension(width, height));
    pack();
    setVisible(true);
    setLocationRelativeTo(null);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
コード例 #2
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);
  }
コード例 #3
0
ファイル: JListFriendPanel.java プロジェクト: PhyTeam/ChatP2P
  /** Create the panel. */
  public JListFriendPanel(String name, String path, ChatPanel chatpanel) {
    super(name, path);
    temp = chatpanel;

    setLayout(null);
    txtSearch = new JTextField();
    txtSearch.setBounds(10, 11, 151, 29);
    add(txtSearch);
    txtSearch.setColumns(10);

    JButton btnSearch = new JButton("Tìm");
    btnSearch.addMouseListener(
        new MouseAdapter() {
          @Override
          /** Tìm kiếm keyword trong danh sách bạn bè */
          public void mouseClicked(MouseEvent arg0) {
            String keyword = txtSearch.getText();
            if (keyword.isEmpty()) copy2view();
            else {
              list_view.clear();
              for (int i = 0; i < list.size(); i++)
                if (list.get(i).contains(keyword)) {
                  list_view.add(list.get(i));
                }
            }
            list_fri.setListData(list_view.toArray());
          }
        });
    btnSearch.setBounds(171, 11, 69, 29);
    add(btnSearch);
    list_fri = new JList();
    list_fri.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list_fri.addListSelectionListener(
        new ListSelectionListener() {
          public void valueChanged(ListSelectionEvent arg0) {}
        });
    list_fri.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseReleased(MouseEvent arg0) {
            int n = list_fri.getSelectedIndex();
            txtSearch.setText(list_view.get(n));
          }
        });
    // Khởi tạo danh sách bạn
    copy2view();
    // Cap nhat danh sach ban
    ScrollPane scrollPane = new ScrollPane();
    list_fri.setListData(list.toArray());
    list_fri.setSelectedIndex(0);
    scrollPane.setBounds(10, 76, 230, 305);
    scrollPane.add(list_fri);
    add(scrollPane);

    JLabel lblTrcTuyn = new JLabel("Danh sách bạn bè");
    lblTrcTuyn.setForeground(new Color(144, 238, 144));
    lblTrcTuyn.setBounds(10, 51, 123, 14);
    add(lblTrcTuyn);

    JButton btnSearchServer = new JButton("Tìm kiếm tất cả");
    btnSearchServer.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent arg0) {
            change2searchserver();
          }
        });
    btnSearchServer.setBounds(127, 387, 113, 29);
    add(btnSearchServer);

    JButton btnChat = new JButton("Trò chuyện");
    btnChat.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent arg0) {
            temp.CreateTab(list_view.get(list_fri.getSelectedIndex()));
          }
        });
    btnChat.setBounds(10, 387, 113, 29);
    add(btnChat);
  }
コード例 #4
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);
  }