示例#1
0
  private void init() {
    btnOpen = new JButton("Open");
    btnOpen.setSize(100, 50);
    textArea = new JTextArea("sd");
    textArea.setSize(200, 100);
    textArea.setDragEnabled(true);

    btnOpen.addActionListener(new OpenAction());

    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

    } catch (ClassNotFoundException e) {
      // TODO 自动生成 catch 块
      e.printStackTrace();
    } catch (InstantiationException e) {
      // TODO 自动生成 catch 块
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      // TODO 自动生成 catch 块
      e.printStackTrace();
    } catch (UnsupportedLookAndFeelException e) {
      // TODO 自动生成 catch 块
      e.printStackTrace();
    }
    Container container = getContentPane();
    GroupLayout groupLayout = new GroupLayout(container);
    container.setLayout(groupLayout);

    groupLayout.setAutoCreateContainerGaps(true);
    groupLayout.setAutoCreateGaps(true);
    // 左对齐
    GroupLayout.ParallelGroup p1 = groupLayout.createParallelGroup(GroupLayout.Alignment.LEADING);
    p1.addComponent(btnOpen);
    p1.addComponent(textArea);
    // 水平
    groupLayout.setHorizontalGroup(groupLayout.createSequentialGroup().addGroup(p1));

    GroupLayout.ParallelGroup v1 = groupLayout.createParallelGroup(GroupLayout.Alignment.LEADING);
    v1.addComponent(btnOpen);

    GroupLayout.ParallelGroup v2 = groupLayout.createParallelGroup(GroupLayout.Alignment.LEADING);
    v2.addComponent(textArea);

    GroupLayout.SequentialGroup vGroup = groupLayout.createSequentialGroup();
    vGroup.addGroup(v1).addGroup(v2);

    // 垂直
    groupLayout.setVerticalGroup(groupLayout.createSequentialGroup().addGroup(vGroup));

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setTitle("通讯录");
    setSize(300, 500);
    Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
    setLocation((dimension.width - getSize().width) / 2, (dimension.height - getSize().height) / 3);

    // pack();
    setVisible(true);
  }
示例#2
0
文件: GUI.java 项目: sametkaya/BLM305
  public GUI() {
    String[] keys = {"no Quotation found"};
    if (tryDir(".") || tryDir("BLM305") || tryDir("CSE470")) keys = Q.keySet().toArray(keys);
    menu = new JComboBox<String>(keys);
    if (Q.size() > 0) setMessage(0);

    JPanel pan = new JPanel();
    pan.setLayout(new BorderLayout(GAP, GAP - 4));
    pan.setBorder(new javax.swing.border.EmptyBorder(GAP, GAP, GAP, GAP));
    pan.setBackground(COLOR);

    pan.add(topPanel(), "North");

    txt.setFont(LARGE);
    txt.setEditable(false);
    txt.setRows(5);
    txt.setColumns(30);
    txt.setWrapStyleWord(true);
    txt.setLineWrap(true);
    txt.setDragEnabled(true);
    pan.add(new JScrollPane(txt), "Center");

    ref.setFont(SMALL);
    ref.setEditable(false);
    ref.setColumns(35);
    ref.setDragEnabled(true);
    pan.add(ref, "South");

    pan.setToolTipText("A project realized collectively by the class");
    menu.setToolTipText("Quotation classes");
    who.setToolTipText("author()+year()");
    txt.setToolTipText("text()");
    ref.setToolTipText("reference()");

    frm.setContentPane(pan);
    frm.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frm.setLocation(scaled(120), scaled(90));
    frm.pack();
    frm.setVisible(true);
  }
示例#3
0
文件: JChat.java 项目: ThatoP/JChat
  public JChat() {
    this.setSize(500, 600);
    this.setResizable(false);
    this.setLayout(new BorderLayout());

    JPanel topPanel = new JPanel();
    topPanel.setLayout(new GridLayout(2, 1));

    // set up buttons
    openChat = new JButton("Open to chat");
    openChat.addActionListener(new OpenChat());
    chatWith = new JButton("Chat with");
    chatWith.addActionListener(new ChatWith());
    send = new JButton("send");
    send.addActionListener(new Send());
    send.setEnabled(false);
    InputMap inputMap = send.getInputMap(JButton.WHEN_IN_FOCUSED_WINDOW);
    KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
    inputMap.put(enter, "ENTER");
    send.getActionMap().put("ENTER", new ClickAction(send));

    // set up labels
    pickPort = new JLabel();
    pickPort.setText("Pick your port number:");
    desPort = new JLabel();
    desPort.setText("Or enter a destinaltion port number:");

    // set up text fields
    pickText = new JTextField();
    pickText.setPreferredSize(new Dimension(150, 30));
    desText = new JTextField();
    desText.setPreferredSize(new Dimension(150, 30));
    chatText = new JTextField();
    chatText.setPreferredSize(new Dimension(400, 30));
    chatText.setEnabled(false);

    JPanel top1 = new JPanel();
    top1.add(pickPort);
    top1.add(pickText);
    top1.add(openChat);

    JPanel top2 = new JPanel();
    top2.add(desPort);
    top2.add(desText);
    top2.add(chatWith);

    topPanel.add(top1);
    topPanel.add(top2);

    chatField = new JTextArea();
    chatField.setAutoscrolls(true);
    chatField.setDragEnabled(true);
    chatField.setEditable(false);
    chatField.setAlignmentY(TOP_ALIGNMENT);

    JPanel bottomPanel = new JPanel();
    bottomPanel.add(chatText);
    bottomPanel.add(send);

    this.add(topPanel, BorderLayout.NORTH);
    this.add(chatField, BorderLayout.CENTER);
    this.add(bottomPanel, BorderLayout.SOUTH);

    this.setVisible(true);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
示例#4
0
  public DefaultDnDSupport() {
    JFrame fen = new JFrame("DnD et CCP");
    fen.getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER));
    fen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Panel gauche
    JPanel panelgauche = new JPanel();
    panelgauche.setLayout(new BoxLayout(panelgauche, BoxLayout.Y_AXIS));

    // JTextField
    JTextField textField = new JTextField(10);
    textField.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("JTextField"),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    textField.setDragEnabled(true);

    // JPasswordField
    JPasswordField passwordField = new JPasswordField(10);
    passwordField.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("JPasswordField"),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    passwordField.setDragEnabled(true);

    // JFormattedTextField
    JFormattedTextField ftf = new JFormattedTextField("Universite de Lille 1");
    ftf.setFont(new Font("Courier", Font.ITALIC, 12));
    ftf.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("JFormattedTextField"),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    ftf.setDragEnabled(true);

    // JTextArea
    JTextArea jta = new JTextArea("Master 1 informatique");
    jta.setFont(new Font("Arial", Font.BOLD, 12));
    jta.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("JTextArea"),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    jta.setDragEnabled(true);

    // JEditorPane
    JEditorPane editorPane = createEditorPane();
    editorPane.setDragEnabled(true);
    JScrollPane editorScrollPane = new JScrollPane(editorPane);
    editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    editorScrollPane.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("JEditorPane"),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    // JColorChooser
    JColorChooser cc = new JColorChooser();
    cc.setDragEnabled(true);
    cc.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("JColorChooser"),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    // Panel droit
    JPanel paneldroit = new JPanel();
    paneldroit.setLayout(new BoxLayout(paneldroit, BoxLayout.Y_AXIS));

    // JList
    String[] data = {
      "AAC", "AEV", "ANG", "ASE", "COA", "PJE", "CAR", "PJI", "AeA", "BDA", "CALP", "FDD", "HECI",
      "IHM", "M3DS", "PAC", "PPD", "RdF", "SVL", "TI"
    };
    JList liste = new JList(data);
    JScrollPane jscrollListe = new JScrollPane(liste);
    jscrollListe.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("JList"),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    // liste.setDragEnabled(true);

    // JTree
    DefaultMutableTreeNode m1 = new DefaultMutableTreeNode("M1");
    DefaultMutableTreeNode s1 = new DefaultMutableTreeNode("S1");
    m1.add(s1);
    s1.add(new DefaultMutableTreeNode("AAC"));
    s1.add(new DefaultMutableTreeNode("AEV"));
    s1.add(new DefaultMutableTreeNode("ANG"));
    s1.add(new DefaultMutableTreeNode("ASE"));
    s1.add(new DefaultMutableTreeNode("COA"));
    s1.add(new DefaultMutableTreeNode("PJE"));
    DefaultMutableTreeNode s2 = new DefaultMutableTreeNode("S2");
    m1.add(s2);
    s2.add(new DefaultMutableTreeNode("CAR"));
    s2.add(new DefaultMutableTreeNode("PJI"));
    s2.add(new DefaultMutableTreeNode("AeA"));
    s2.add(new DefaultMutableTreeNode("BDA"));
    s2.add(new DefaultMutableTreeNode("CALP"));
    s2.add(new DefaultMutableTreeNode("FDD"));
    s2.add(new DefaultMutableTreeNode("HECI"));
    s2.add(new DefaultMutableTreeNode("IHM"));
    s2.add(new DefaultMutableTreeNode("M3DS"));
    s2.add(new DefaultMutableTreeNode("PAC"));
    s2.add(new DefaultMutableTreeNode("PPD"));
    s2.add(new DefaultMutableTreeNode("RdF"));
    s2.add(new DefaultMutableTreeNode("SVL"));
    s2.add(new DefaultMutableTreeNode("TI"));
    JTree tree = new JTree(m1);
    // tree.setDragEnabled(true);
    JScrollPane jscrollTree = new JScrollPane(tree);
    jscrollTree.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("JTree"),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    jscrollTree.setPreferredSize(new Dimension(200, 200));

    // JTable
    String[] columnNames = {"S1", "S2"};
    Object[][] data2 = {
      {"AAC", "CAR"},
      {"AEV", "PJI"},
      {"ANG", "AeA"},
      {"ASE", "BDA"},
      {"COA", "CALP"},
      {"PJE", "FDD"},
      {"", "HECI"},
      {"", "IHM"},
      {"", "M3DS"},
      {"", "PAC"},
      {"", "PPD"},
      {"", "RdF"},
      {"", "SVL"},
      {"", "TI"}
    };

    JTable table = new JTable(data2, columnNames);
    JScrollPane scrollPaneTable = new JScrollPane(table);
    table.setDragEnabled(true);

    // JFileChooser
    JFileChooser fc = new JFileChooser();
    fc.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("JFileChooser"),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    fc.setDragEnabled(true);

    panelgauche.add(textField);
    panelgauche.add(passwordField);
    panelgauche.add(ftf);
    panelgauche.add(jta);
    panelgauche.add(cc);
    panelgauche.add(editorScrollPane);
    fen.getContentPane().add(panelgauche);

    paneldroit.add(fc);
    paneldroit.add(jscrollListe);
    paneldroit.add(jscrollTree);
    paneldroit.add(scrollPaneTable);

    fen.getContentPane().add(paneldroit);

    fen.pack();
    fen.setVisible(true);
  }