예제 #1
0
  public void init() {
    setLayout(new BorderLayout());

    single.add("0");
    single.add("1");
    single.add("2");
    single.add("3");
    single.add("4");
    single.add("5");
    single.add("6");
    single.add("7");
    single.add("8");

    multiple.add("0");
    multiple.add("1");
    multiple.add("2");
    multiple.add("3");
    multiple.add("4");
    multiple.add("5");
    multiple.add("6");
    multiple.add("7");
    multiple.add("8");

    single.addKeyListener(this);
    single.addItemListener(this);
    single.addFocusListener(this);
    p1.add(single);
    add("North", p1);

    multiple.addKeyListener(this);
    multiple.addItemListener(this);
    multiple.addFocusListener(this);
    p2.add(multiple);
    add("South", p2);
  } // End  init()
  /** This method initializes styleList */
  private List getStyleList() {
    if (styleList == null) {
      styleList = new List(styleListChoices.length);
      for (String s : styleListChoices) {
        styleList.add(s);
      }

      styleList.setPreferredSize(new Dimension(97, 117));
      styleList.select(0);
      styleList.addItemListener(
          new ItemListener() {

            public void itemStateChanged(ItemEvent e) {
              if (e.getStateChange() == ItemEvent.SELECTED) {
                styleIndex = styleList.getSelectedIndex();
                if (model.items() != null) {
                  algorithm = algs[styleIndex];
                  refreshObjects();
                }
              }
            }
          });
    }
    return styleList;
  }
예제 #3
0
 public void go() {
   f = new Frame("좋아하는 선수 고르기");
   f.addWindowListener(
       new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
           f.setVisible(false);
           f.dispose();
           System.exit(0);
         }
       });
   lstSunsu = new List(4, true); // 4개 보여주고,여러명 선택가능
   lstSunsu.addItemListener(this); // 2. step
   lstSunsu.add("==선수선택==");
   lstSunsu.add("조오련");
   lstSunsu.add("박찬호");
   lstSunsu.add("박세리");
   lstSunsu.add("안정환");
   lstSunsu.add("이천수");
   lstSunsu.add("이영표");
   lstSunsu.add("차범근");
   lstSunsu.add("김남일");
   lstSunsu.add("차두리");
   tf = new TextField();
   f.add(new Label("좋아하는 선수를 여러명 선택하세요"), "North");
   f.add(lstSunsu, "Center");
   f.add(tf, "South");
   f.setSize(200, 300);
   f.setVisible(true);
 }
예제 #4
0
  public void initComponents() {
    /** ******************** The main container *************************** */
    Container container = this.getContentPane();
    container.setLayout(new BorderLayout());
    container.setBackground(Color.black);
    this.setSize(650, 600);
    this.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent e) {}
        });

    /** ************************* MAIN PANEL ******************************* */
    mainPanel = new JPanel();
    // If put to False: we see the container's background
    mainPanel.setOpaque(false);
    mainPanel.setLayout(new BorderLayout());
    container.add(mainPanel, BorderLayout.CENTER);

    allmessagesTextArea = new TextArea();
    allmessagesTextArea.setEditable(false);
    allmessagesTextArea.setFont(new Font("Dialog", 1, 12));
    allmessagesTextArea.setForeground(Color.black);
    allmessagesTextArea.append("Select a session in the list to view its messages");
    mainPanel.add(allmessagesTextArea, BorderLayout.CENTER);

    sessionsList = new List();
    sessionsList.addItemListener(
        new ItemListener() {
          @Override
          public void itemStateChanged(ItemEvent e) {
            showMessages(e);
          }
        });
    sessionsList.setForeground(Color.black);
    sessionsList.setFont(new Font("Dialog", 1, 14));
    mainPanel.add(sessionsList, BorderLayout.WEST);

    okButton = new JButton("  OK  ");
    okButton.setToolTipText("Returns to the main frame");
    okButton.setFont(new Font("Dialog", 1, 16));
    okButton.setFocusPainted(false);
    okButton.setBackground(Color.lightGray);
    okButton.setBorder(new BevelBorder(BevelBorder.RAISED));
    okButton.setVerticalAlignment(SwingConstants.CENTER);
    okButton.setHorizontalAlignment(SwingConstants.CENTER);
    container.add(okButton, BorderLayout.SOUTH);
    okButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent evt) {
            setVisible(false);
          }
        });
  }
예제 #5
0
 private void PreencheGenero() {
   for (int i = 0; i < Main.facade.recuperarGeneros().size(); i++) {
     list.add(Main.facade.recuperarGeneros().get(i).getTitulo());
   }
   list.addItemListener(
       new ItemListener() {
         public void itemStateChanged(ItemEvent ie) {
           Genero gen = Main.facade.recuperarGeneros().get(list.getSelectedIndex());
           selecionado1.setText("Gênero: " + gen.getTitulo());
           selecionado2.setText("Descrição: " + gen.getDescricao());
         }
       });
 }
예제 #6
0
  public babylonServerWindow(babylonServer parent, String Name) {
    super(Name);
    server = parent;

    myLayout = new GridBagLayout();
    setLayout(myLayout);

    p = new Panel();
    p.setLayout(myLayout);

    listening = new Label(server.strings.get(thisClass, "listenport") + " " + server.port);
    p.add(
        listening,
        new babylonConstraints(
            0,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, 0),
            0,
            0));

    logChat = new Checkbox(server.strings.get(thisClass, "logchats"), server.logChats);
    logChat.addItemListener(this);
    p.add(
        logChat,
        new babylonConstraints(
            1,
            0,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, 0),
            0,
            0));

    userList = new List(4, false);
    userList.addItemListener(this);
    p.add(
        userList,
        new babylonConstraints(
            0,
            1,
            1,
            5,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 5, 0),
            0,
            0));

    userAdmin = new Button(server.strings.get(thisClass, "usermanagement"));
    userAdmin.addActionListener(this);
    p.add(
        userAdmin,
        new babylonConstraints(
            1,
            1,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 0, 0),
            0,
            0));

    console = new Button(server.strings.get(thisClass, "adminclient"));
    console.addActionListener(this);
    p.add(
        console,
        new babylonConstraints(
            1,
            2,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 0, 0),
            0,
            0));

    disconnect = new Button(server.strings.get(thisClass, "disconnectuser"));
    disconnect.setEnabled(false);
    disconnect.addActionListener(this);
    p.add(
        disconnect,
        new babylonConstraints(
            1,
            3,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 0, 0),
            0,
            0));

    disconnectAll = new Button(server.strings.get(thisClass, "disconnectall"));
    disconnectAll.setEnabled(false);
    disconnectAll.addActionListener(this);
    p.add(
        disconnectAll,
        new babylonConstraints(
            1,
            4,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 0, 0),
            0,
            0));

    shutdown = new Button(server.strings.get(thisClass, "shutdown"));
    shutdown.addActionListener(this);
    p.add(
        shutdown,
        new babylonConstraints(
            1,
            5,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 0, 0),
            0,
            0));

    stats =
        new TextField(
            server.strings.get(thisClass, "connectionscurrent")
                + " 0  "
                + server.strings.get(thisClass, "connectionspeak")
                + " 0  "
                + server.strings.get(thisClass, "connectionstotal")
                + " 0",
            40);
    stats.setEditable(false);
    p.add(
        stats,
        new babylonConstraints(
            0,
            7,
            2,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0),
            0,
            0));

    logWindow =
        new TextArea(
            server.strings.get(thisClass, "activitylog") + "\n",
            10,
            40,
            TextArea.SCROLLBARS_VERTICAL_ONLY);
    logWindow.setEditable(false);
    p.add(
        logWindow,
        new babylonConstraints(
            0,
            8,
            2,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 5, 0),
            0,
            0));

    canvas = new babylonPictureCanvas(this);
    p.add(
        canvas,
        new babylonConstraints(
            0,
            9,
            2,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0),
            0,
            0));

    add(
        p,
        new babylonConstraints(
            0,
            0,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.BOTH,
            new Insets(5, 5, 5, 5),
            0,
            0));

    try {
      URL url = new URL("file", "localhost", "babylonPic.jpg");
      Image image = getToolkit().getImage(url);

      canvas.setimage(image);
    } catch (Exception e) {
      System.out.println(e);
    }

    try {
      URL iconUrl = new URL("file", "localhost", "babylonIcon.jpg");
      ImageIcon icon = new ImageIcon(iconUrl);
      this.setIconImage(icon.getImage());
    } catch (Exception e) {
      /* Not important */
    }

    addWindowListener(this);

    setSize(600, 600);
    pack();
  }
예제 #7
0
 /**
  * 新增視窗物件 設定物件屬性 內容
  *
  * @param o 物件instances
  * @param reg 物件位置
  * @param name 物件名稱
  * @param value 物件標籤 或 內容
  */
 protected void addObject(Object o, Rectangle reg, String name, String value) {
   if (o instanceof Label) {
     ((Label) o).setText(value);
     ((Label) o).setName(name);
     ((Label) o).setBounds(reg);
     ((Label) o).addMouseListener(this);
     this.add((Label) o);
   } else if (o instanceof TextField) {
     ((TextField) o).setText(value);
     ((TextField) o).setName(name);
     ((TextField) o).setBounds(reg);
     ((TextField) o).addMouseListener(this);
     ((TextField) o).addTextListener(this);
     ((TextField) o).addKeyListener(this);
     if (value.equalsIgnoreCase("password")) ((TextField) o).setEchoChar('*');
     this.add((TextField) o);
   } else if (o instanceof Button) {
     int len = (int) ((float) reg.width / FONTWIDTH);
     ((Button) o).setLabel(StringUtil_.splitStringSpace(value, len));
     ((Button) o).setName(name);
     ((Button) o).setBounds(reg);
     ((Button) o).addMouseListener(this);
     this.add((Button) o);
   } else if (o instanceof TextArea) {
     ((TextArea) o).setText(value);
     ((TextArea) o).setName(name);
     ((TextArea) o).setBounds(reg);
     ((TextArea) o).addMouseListener(this);
     ((TextArea) o).addTextListener(this);
     ((TextArea) o).addKeyListener(this);
     this.add((TextArea) o);
   } else if (o instanceof Choice) {
     String[] values = value.split(",");
     for (int ii = 0; ii < values.length; ii++) ((Choice) o).addItem(values[ii]);
     ((Choice) o).setName(name);
     ((Choice) o).setBounds(reg);
     ((Choice) o).addMouseListener(this);
     ((Choice) o).addItemListener(this);
     this.add((Choice) o);
   } else if (o instanceof Checkbox) {
     ((Checkbox) o).setLabel(value);
     ((Checkbox) o).setName(name);
     ((Checkbox) o).setBounds(reg);
     ((Checkbox) o).addMouseListener(this);
     ((Checkbox) o).addItemListener(this);
     this.add((Checkbox) o);
   } else if (o instanceof CheckboxGroup) {
     String[] values = value.split(",");
     for (int ii = 0; ii < values.length; ii++) {
       Checkbox chk = new Checkbox();
       chk.setLabel(values[ii]);
       chk.setName(name + ii);
       chk.setBounds(reg);
       reg.y += 25;
       chk.addMouseListener(this);
       chk.addItemListener(this);
       chk.setCheckboxGroup((CheckboxGroup) o);
       this.add(chk);
     }
   } else if (o instanceof List) {
     String[] values = value.split(",");
     ((List) o).setName(name);
     ((List) o).setBounds(reg);
     ((List) o).addMouseListener(this);
     ((List) o).addItemListener(this);
     for (int ii = 0; ii < values.length; ii++) ((List) o).add(values[ii]);
     this.add(((List) o));
   }
 }
예제 #8
0
  /** 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);
  }
예제 #9
0
 public void addItemListener(ItemListener listener) {
   awtList.addItemListener(listener);
 }