public void setOutputPanel() { BoxLayout box = new BoxLayout(output, BoxLayout.Y_AXIS); output.setLayout(box); Color c1 = new Color(166, 209, 241); Color c2 = new Color(204, 210, 211); JLabel label3 = new JLabel("Messaggi interni:"); output.add(label3); outp.setBackground(c1); outp.setAutoscrolls(true); outp.setEditable(false); intmsg.setBackground(c2); intmsg.setAutoscrolls(true); intmsg.setEditable(false); output.add(scrollPaneM); JLabel label4 = new JLabel("Output:"); output.add(label4); output.add(scrollPaneO); output.setBorder(BorderFactory.createEtchedBorder()); }
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); }
private void initializeComponents() { this.setTitle("Synchro - Kopierassistent"); this.setBounds(0, 0, 550, 600); this.setResizable(true); this.setLayout(null); this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); this.addWindowListener(this); mainPanel = new JPanel(); mainPanel.setBounds(0, 0, this.getWidth() - 20, 25); // fcPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); mainPanel.setLayout(null); btnBackup = new JButton("Backup"); btnBackup.setBounds(this.getWidth() / 2, 0, this.getWidth() / 2 - 20, mainPanel.getHeight()); btnBackup.addActionListener(this); mainPanel.add(btnBackup); this.add(mainPanel); fcPanel = new JPanel(); fcPanel.setBounds(10, 40, this.getWidth(), 260); // fcPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); fcPanel.setLayout(null); quellLabel = new JLabel("Bitte Quellverzeichnis auswählen"); quellLabel.setBounds(10, 5, 320, 20); fcPanel.add(quellLabel); quellListModel = new DefaultListModel<>(); quellJList = new JList<ListItem>(quellListModel); quellJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); quellJList.setLayoutOrientation(JList.VERTICAL); quellJList.addListSelectionListener(this); listBoxScroller = new JScrollPane(quellJList); listBoxScroller.setBounds(0, 30, 315, 100); fcPanel.add(listBoxScroller); btnQAuswahl = new JButton("Quellverz. hinzufügen"); btnQAuswahl.setBounds(320, 30, 200, 25); btnQAuswahl.addActionListener(this); fcPanel.add(btnQAuswahl); btnQEntfernen = new JButton("Quellverz. entfernen"); btnQEntfernen.setBounds(320, 60, 200, 25); btnQEntfernen.addActionListener(this); fcPanel.add(btnQEntfernen); zielLabel = new JLabel("Bitte Zielverzeichnis auswählen"); zielLabel.setBounds(10, 135, 320, 20); fcPanel.add(zielLabel); zielListModel = new DefaultListModel<>(); zielJList = new JList<ListItem>(zielListModel); zielJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); zielJList.setLayoutOrientation(JList.VERTICAL); zielJList.addListSelectionListener(this); listBoxScroller2 = new JScrollPane(zielJList); listBoxScroller2.setBounds(0, 160, 315, 100); fcPanel.add(listBoxScroller2); btnZAuswahl = new JButton("Zielverz. hinzufügen"); btnZAuswahl.setBounds(320, 160, 200, 25); btnZAuswahl.addActionListener(this); fcPanel.add(btnZAuswahl); btnZEntfernen = new JButton("Zielverz. entfernen"); btnZEntfernen.setBounds(320, 190, 200, 25); btnZEntfernen.addActionListener(this); fcPanel.add(btnZEntfernen); this.add(fcPanel); ButtonGroup bGrp = new ButtonGroup(); optionPanel = new JPanel(); optionPanel.setBounds(10, 300 + 10, this.getWidth() - 40, 90); optionPanel.setPreferredSize(new Dimension(this.getWidth() - 40, 90)); // optionPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); optionPanel.setLayout(new GridLayout(3, 1)); nUebSchr = new JRadioButton("Keine Dateien überschreiben"); nUebSchr.addItemListener(this); bGrp.add(nUebSchr); optionPanel.add(nUebSchr); ueSchr = new JRadioButton("Neuere Dateien überschreiben"); ueSchr.addItemListener(this); bGrp.add(ueSchr); optionPanel.add(ueSchr); aUeSchr = new JRadioButton("Alle Dateien überschreiben"); aUeSchr.addItemListener(this); bGrp.add(aUeSchr); optionPanel.add(aUeSchr); this.add(optionPanel); syncPanel = new JPanel(); syncPanel.setBounds( 10, optionPanel.getY() + optionPanel.getHeight() + 10, this.getWidth() - 30, 25); // syncPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); syncPanel.setLayout(new BorderLayout()); btnSync = new JButton("Sync it!"); btnSync.setBounds(0, 0, 150, (syncPanel.getHeight() / 3)); btnSync.addActionListener(this); btnSync.setPreferredSize(new Dimension(150, (syncPanel.getHeight() / 3))); btnSync.setMaximumSize(new Dimension(150, (syncPanel.getHeight() / 3))); syncPanel.add(btnSync, BorderLayout.LINE_START); btnAbbruch = new JButton("Abbrechen"); btnAbbruch.setBounds(0, 0, 150, (syncPanel.getHeight() / 3)); btnAbbruch.addActionListener(this); btnAbbruch.setPreferredSize(new Dimension(150, (syncPanel.getHeight() / 3))); btnAbbruch.setMaximumSize(new Dimension(150, (syncPanel.getHeight() / 3))); btnAbbruch.setVisible(false); syncPanel.add(btnAbbruch, BorderLayout.LINE_END); progressBar = new JProgressBar(JProgressBar.HORIZONTAL); progressBar.setBorderPainted(true); progressBar.setPreferredSize(new Dimension(300, (syncPanel.getHeight() / 3))); progressBar.setForeground(Color.RED); progressBar.setStringPainted(true); progressBar.setVisible(true); syncPanel.add(progressBar, BorderLayout.CENTER); this.add(syncPanel); logPanel = new JPanel(); logPanel.setBounds( 10, syncPanel.getY() + syncPanel.getHeight() + 10, this.getWidth() - 30, 105); logPanel.setLayout(new BorderLayout()); textArea = new JTextArea(); textArea.setMargin(new Insets(3, 3, 3, 3)); textArea.setBackground(Color.black); textArea.setForeground(Color.LIGHT_GRAY); textArea.setAutoscrolls(true); textArea.setFocusable(false); textAreaScroller = new JScrollPane(textArea); DefaultCaret caret = (DefaultCaret) textArea.getCaret(); caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); textAreaScroller.setBounds(0, 0, syncPanel.getWidth(), 50); logPanel.add(textAreaScroller, BorderLayout.CENTER); this.add(logPanel, BorderLayout.SOUTH); }
public void setInputPanel() throws IOException { final String newline = "\n"; final JTextArea log = new JTextArea(2, 28); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); input.setLayout(gridbag); // Create the log first, because the action listeners // need to refer to it. log.setMargin(new Insets(1, 1, 1, 1)); log.setEditable(false); JScrollPane logScrollPane = new JScrollPane(log); // Create a file chooser final JFileChooser fc = new JFileChooser(); // Create the open button ImageIcon openIcon = new ImageIcon("Images/open.gif"); JButton openButton = new JButton("Open a File...", openIcon); openButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int returnVal = fc.showOpenDialog(prologApplet.this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); String name = file.getName(); String path = file.getAbsolutePath(); try { FileInputStream inps = new FileInputStream(path); ch = 0; ss = ""; while (ch != -1) { ch = inps.read(); ss = ss + (char) ch; } inps.close(); } catch (Exception exc) { System.out.println("" + e); } code.selectAll(); code.cut(); code.append(ss); log.append("Opening: " + name + "." + newline); } else { log.append("Open command cancelled by user." + newline); } } }); // Create the save button ImageIcon saveIcon = new ImageIcon("Images/save.gif"); JButton saveButton = new JButton("Save a File...", saveIcon); saveButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int returnVal = fc.showSaveDialog(prologApplet.this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); // this is where a real application would save the file. log.append("Saving: " + file.getName() + "." + newline); } else { log.append("Save command cancelled by user." + newline); } } }); // For layout purposes, put the buttons in a separate panel JPanel buttonPanel = new JPanel(); buttonPanel.add(openButton); buttonPanel.add(saveButton); // Explicitly set the focus sequence. // rimossi poichè deprecati // openButton.setNextFocusableComponent(saveButton); // saveButton.setNextFocusableComponent(openButton); // Add the buttons and the log to the frame // Container contentPane = getContentPane(); // contentPane.add(buttonPanel, BorderLayout.NORTH); // contentPane.add(logScrollPane, BorderLayout.CENTER); c.gridx = 0; c.gridy = 0; c.gridwidth = 3; c.fill = GridBagConstraints.NONE; gridbag.setConstraints(buttonPanel, c); input.add(buttonPanel); c.gridx = 0; c.gridy = 1; c.gridwidth = 3; c.fill = GridBagConstraints.NONE; gridbag.setConstraints(logScrollPane, c); input.add(logScrollPane); JLabel label1 = new JLabel("Codice:"); c.gridx = 0; c.gridy = 2; c.gridwidth = 3; c.fill = GridBagConstraints.NONE; gridbag.setConstraints(label1, c); input.add(label1); c.gridx = 0; c.gridy = 3; c.gridwidth = 3; c.fill = GridBagConstraints.HORIZONTAL; gridbag.setConstraints(scrollPaneC, c); input.add(scrollPaneC); JLabel label2 = new JLabel("GOAL clause:"); c.gridx = 0; c.gridy = 4; // c.weightx=1; c.gridwidth = 3; c.fill = GridBagConstraints.NONE; gridbag.setConstraints(label2, c); input.add(label2); c.gridx = 0; c.gridy = 5; c.gridwidth = 3; c.fill = GridBagConstraints.HORIZONTAL; gridbag.setConstraints(gl, c); input.add(gl); c.gridx = 0; c.gridy = 6; c.weightx = 0.3; c.gridwidth = 1; gridbag.setConstraints(compile, c); input.add(compile); compile.addActionListener(this); c.gridx = 1; c.gridy = 6; c.weightx = 0.3; c.gridwidth = 1; gridbag.setConstraints(compileG, c); input.add(compileG); compileG.addActionListener(this); c.gridx = 2; c.gridy = 6; c.weightx = 0.3; c.gridwidth = 1; gridbag.setConstraints(run, c); input.add(run); run.addActionListener(this); Color c1 = new Color(166, 209, 241); code.setBackground(c1); code.setAutoscrolls(true); code.setEditable(true); /* mb1 input.add(load); input.add(scrollPaneC); input.add(gl); */ input.setBorder(BorderFactory.createEtchedBorder()); }