MainWindow() { home.setSize(450, 400); home.setLocation(0, 0); home.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); error.setForeground(Color.red); home.add(error, "North"); ipAddress.setEditable(true); f.setEditable(true); b.setEditable(true); l.setEditable(true); r.setEditable(true); start.addActionListener(this); help.addActionListener(this); quit.addActionListener(this); start.addMouseMotionListener(this); help.addMouseMotionListener(this); quit.addMouseMotionListener(this); JPanel homePanel = new JPanel(); homePanel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.weightx = 0.5; c.weighty = 0.5; // first col c.gridx = 0; c.gridy = 0; c.gridwidth = 1; homePanel.add(ip, c); c.gridy = 1; ipAddress.grabFocus(); ipAddress.selectAll(); homePanel.add(ipAddress, c); c.gridy = 2; homePanel.add(timeUnit, c); c.gridwidth = 1; c.gridy = 3; homePanel.add(forward, c); c.gridy = 4; homePanel.add(f, c); c.gridy = 5; homePanel.add(left, c); c.gridy = 6; homePanel.add(l, c); // second col c.ipadx = 50; c.gridx = 1; c.gridy = 0; homePanel.add(pinLabel, c); c.gridy = 1; homePanel.add(pin, c); c.gridy = 3; homePanel.add(reverse, c); c.gridy = 4; homePanel.add(b, c); c.gridy = 5; homePanel.add(right, c); c.gridy = 6; homePanel.add(r, c); // third col c.ipadx = 0; c.gridx = 2; c.gridy = 4; homePanel.add(start, c); c.gridy = 5; homePanel.add(help, c); c.gridy = 6; homePanel.add(quit, c); homePanel.setBackground(Color.white); homePanel.setOpaque(true); home.add(homePanel, "Center"); home.setVisible(true); }
private void setMovable(final JFrame frame) { String titlePath = "img/Title/"; JButton title = new JButton(new ImageIcon(titlePath + frameName + ".png")); title.addMouseListener( new MouseAdapter() { public void mousePressed(MouseEvent e) { CommonFrame.origin.x = e.getX(); CommonFrame.origin.y = e.getY(); } }); title.addMouseMotionListener( new MouseMotionAdapter() { public void mouseDragged(MouseEvent e) { Point p = frame.getLocation(); frame.setLocation(p.x + e.getX() - origin.x, p.y + e.getY() - origin.y); } }); if (frameName.equals("LoginFrame")) { title.setBounds(30, 30, 900, 82); } else { title.setBounds(30, 30, 800, 70); } title.setBorderPainted(false); title.setFocusable(false); add(title); }
/** * Creates a JButton. * * @param Default text for the button * @return The JButton Object */ private JButton createButton(String text) { JButton b = new JButton(); b.setText(text); b.setBackground(java.awt.Color.orange); b.addMouseListener(buttonEvents); b.addMouseMotionListener(buttonEvents); return b; }
private void initComponent() { // TODO Auto-generated method stub top = new JPanel(); nodeGraph = new JPanel(); FRLayout<String, String> graphLayout = new FRLayout<String, String>(graph); nodeGraphView = new VisualizationViewer<String, String>(graphLayout); // nodeGraphView.setBackground(new Color(228,247,186)); // nodeGraphView.setBackground(new Color(178,204,255)); nodeGraphView.setBackground(new Color(255, 216, 216)); nodeGraphView .getRenderContext() .setEdgeDrawPaintTransformer( new PickableEdgePaintTransformer<String>( nodeGraphView.getPickedEdgeState(), Color.black, Color.GREEN)); nodeGraphView .getRenderContext() .setVertexFillPaintTransformer( new PickableVertexPaintTransformer<String>( nodeGraphView.getPickedVertexState(), new Color(67, 116, 217), new Color(5, 0, 153))); final AbstractModalGraphMouse graphMouse = new DefaultModalGraphMouse(); graphMouse.setMode(ModalGraphMouse.Mode.PICKING); nodeGraphView.setGraphMouse(graphMouse); nodeGraphProtocolFilter = new JPanel(); nodeGraph.add(nodeGraphProtocolFilter); nodeGraph.add(nodeGraphView); nodeGraphInform = new JPanel(); nodeGraphMap = new SatelliteVisualizationViewer<String, String>(nodeGraphView); // nodeGraphMap.getRenderContext().setEdgeDrawPaintTransformer(new // PickableEdgePaintTransformer<String>(nodeGraphMap.getPickedEdgeState(), Color.black, // Color.GREEN)); nodeGraphMap .getRenderContext() .setVertexFillPaintTransformer( new PickableVertexPaintTransformer<String>( nodeGraphMap.getPickedVertexState(), new Color(67, 116, 217), new Color(5, 0, 153))); nodeTrafficTableModel = new NodeTrafficTableModel(); TableColumnModel columnModel = new DefaultTableColumnModel(); TableColumn column = new TableColumn(0); column.setHeaderValue("IP"); columnModel.addColumn(column); column = new TableColumn(1); column.setHeaderValue("PORT"); columnModel.addColumn(column); column = new TableColumn(2); column.setHeaderValue("PACKETS"); columnModel.addColumn(column); column = new TableColumn(3); column.setHeaderValue("BYTES"); columnModel.addColumn(column); column = new TableColumn(4); column.setHeaderValue("LEVEL"); columnModel.addColumn(column); DefaultTableCellRenderer cellAlign = new DefaultTableCellRenderer(); cellAlign.setHorizontalAlignment(JLabel.RIGHT); nodeTrafficTable = new JTable(nodeTrafficTableModel, columnModel); /* nodeTrafficTable.getColumn("IP").setCellRenderer(cellAlign); nodeTrafficTable.getColumn("IP").setPreferredWidth(90); nodeTrafficTable.getColumn("PORT").setCellRenderer(cellAlign); nodeTrafficTable.getColumn("PORT").setPreferredWidth(30); nodeTrafficTable.getColumn("PACKETS").setCellRenderer(cellAlign); nodeTrafficTable.getColumn("PACKETS").setPreferredWidth(60); nodeTrafficTable.getColumn("BYTES").setCellRenderer(cellAlign); nodeTrafficTable.getColumn("BYTES").setPreferredWidth(60); nodeTrafficTable.getColumn("LEVEL").setCellRenderer(cellAlign); nodeTrafficTable.getColumn("LEVEL").setPreferredWidth(5); */ nodeGraphicTable = new JTable(nodeGraphicTableModel); nodeGraphProtocolView = new JScrollPane(nodeTrafficTable); // nodeGraphProtocolView.setLayout(new BorderLayout()); // nodeGraphProtocolView.add(nodeTrafficTable); nodeGraphInform.add(nodeGraphMap); nodeGraphInform.add(nodeGraphProtocolView); top.add(nodeGraph); top.add(nodeGraphInform); this.add(top); trafficGraph = new ChartPanel(trafficChart); trafficGraph.setFocusable(false); trafficChart.getLegend().setPosition(RectangleEdge.LEFT); this.add(trafficGraph); graphVerticalSizeBt = new JButton("::::::::△▽::::::::"); graphVerticalSizeBt.setFont(graphVerticalSizeBt.getFont().deriveFont(10.0f)); graphVerticalSizeBt.addMouseMotionListener(new GraphVerticalSizeMotionListener()); graphVerticalSizeBt.addActionListener(new GraphVerticalSizeMotionListener()); this.add(graphVerticalSizeBt); graphHorizontalSizeBt = new JButton(); graphHorizontalSizeBt.setEnabled(false); top.add(graphHorizontalSizeBt); }
public MouseEventDemo() { super("MouseEvent Demo"); setLayout(null); // posizionameto assoluto // componenti button = new JButton("...sono a tua disposizione..."); area = new JTextArea(); wheel_area = new JTextArea(); sp = new JScrollPane(area); sp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); sp.setBounds(1, 100, 580, 250); // aggiungo i componenti al container add(button); add(sp); add(wheel_area); button.setBounds(1, 1, 200, 60); wheel_area.setBounds(210, 1, 360, 90); class MyMouseAdapter extends MouseAdapter { public void mouseEntered(MouseEvent e) // mouse enter { Cursor c1 = new Cursor(Cursor.HAND_CURSOR); button.setCursor(c1); area.append("[Enter] --> (x)" + e.getX() + ", (y)" + e.getY() + "\n"); } public void mouseExited(MouseEvent e) // mouse exit { area.append("[Exit]\n"); } public void mousePressed(MouseEvent e) // pressione del mouse { int nr_click = e.getClickCount(); String msg = "numero di click " + nr_click; area.append("[Press] --> " + msg + "\n"); } public void mouseReleased(MouseEvent e) // rilascio del mouse { area.append("[Release] --> " + "\n"); } public void mouseClicked(MouseEvent e) // click del mouse { int b = e.getButton(); String what = ""; switch (b) // quale pulsante è stato premuto? { case MouseEvent.BUTTON1: what = "pulsante sinistro..."; break; case MouseEvent.BUTTON2: what = "pulsante centrale..."; break; case MouseEvent.BUTTON3: what = "pulsante destro..."; break; default: what = "pulsante sconosciuto..."; } area.append("[Click] --> " + what + "\n"); } public void mouseDragged(MouseEvent e) { Point p_l = e.getLocationOnScreen(); area.append("[Dragging] --> (x)" + p_l.x + ", (y)" + p_l.y + "\n"); } public void mouseMoved(MouseEvent e) // muovo il mouse { String msg = ""; // test di alcuni modificatori if ((e.getModifiersEx() == (e.ALT_DOWN_MASK | e.SHIFT_DOWN_MASK))) msg += "premuti contemporaneamente SHIFT+ALT"; area.append("[Moving] --> " + msg + "\n"); } public void mouseWheelMoved(MouseWheelEvent e) { String st[] = {"PER UNITA'", "PER BLOCCO"}; int unit = e.getUnitsToScroll(); // calcolo per la scrollbar verticale l'attuale posizione // e l'unità di incremento per scroll JScrollBar sb = sp.getVerticalScrollBar(); int y = sb.getValue(); int y1 = e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL ? sb.getUnitIncrement(1) : sb.getBlockIncrement(1); sb.setValue(y + y1 * unit); // aggiorna la view della textarea int a = e.getScrollAmount(); int b = e.getScrollType(); int c = e.getUnitsToScroll(); int d = e.getWheelRotation(); double f = e.getPreciseWheelRotation(); String g = "Unità da scorrere per giro di tacca: " + a + "\nTipo di scroll: " + st[e.getScrollType()] + "\nUnità che scorreranno verso l'alto: " + c + "\nNumero di tacche ruotate: " + d + "\nNumero di tacche precisamente ruotate: " + f; wheel_area.setText(g); } } MyMouseAdapter mma = new MyMouseAdapter(); // listeners button.addMouseListener(mma); button.addMouseMotionListener(mma); button.addMouseWheelListener(mma); }
/** * Constructor: The one we're working on right now. * * @param id * @param label * @param desktop */ public kCodeWindow(String id, String label, JDesktopPane desktop) { this.id = id; this.desktop = desktop; // make the editor portions TextAreaDefaults editareaSettings = new PdeTextAreaDefaults(); editareaSettings.rows = TEXTAREA_DEFAULT_ROWS; editareaSettings.cols = TEXTAREA_DEFAULT_COLS; textarea = new JEditTextArea(editareaSettings); textarea.getDocument().setTokenMarker(Editor.pdeTokenMarker); textarea.setEventsEnabled( false); // suppress JEditTextArea events (not that anyone is listening to it) textarea.setEditable(true); textarea.setHorizontalOffset(TEXTAREA_HORIZ_OFFSET); textarea.getPainter().setLineHighlightEnabled(false); // else looks funny textarea.getPainter().setBackground(kConstants.CODE_WINDOW_COLOR); setShortcutKeystrokes(); JScrollPane scrollPane = new JScrollPane(textarea); scrollPane.setBorder(null); // scrollPane.setOpaque(true); editFrame = new JInternalFrame(label, true, false, false, false); editFrame.setContentPane(textarea); editFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); editFrame.setSize(editFrame_DEFAULT_WIDTH, editFrame_DEFAULT_HEIGHT); editFrame.setBorder(null); editFrame.setOpaque(true); // make the triangle triangleFrame = new JInternalFrame("", false, false, false, false); triangleFrame.setOpaque(false); triangleFrame .getRootPane() .setBackground(new Color(0, 0, 0, 0)); // needs this to actually do the trick triangleFrame.setContentPane( new Triangle("SE", 0, TRIANGLE_BASE, TRIANGLE_DEFAULT_HEIGHT, TRIANGLE_BASE)); triangleFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); triangleFrame.setSize(TRIANGLE_BASE, TRIANGLE_DEFAULT_HEIGHT); triangleFrame.setBorder(null); // remove the ability to move the triangle iframe MouseMotionListener[] actions = (MouseMotionListener[]) triangleFrame.getListeners(MouseMotionListener.class); for (int i = 0; i < actions.length; i++) triangleFrame.removeMouseMotionListener(actions[i]); // make the buttons moveButton = new JButton(Base.getImageIcon("codewindow-activ-move.gif", desktop)); moveButton.setDisabledIcon(Base.getImageIcon("codewindow-inact-move.gif", desktop)); moveButton.setVisible(true); moveButton.setBorder(null); moveButton.setOpaque(false); moveButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); closeButton = new JButton(Base.getImageIcon("codewindow-activ-close.gif", desktop)); closeButton.setDisabledIcon(Base.getImageIcon("codewindow-inact-close.gif", desktop)); closeButton.setVisible(true); closeButton.setBorder(null); closeButton.setOpaque(false); closeButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 1, 0)); buttonPanel.setBorder(null); buttonPanel.setOpaque(false); buttonPanel.add(moveButton); buttonPanel.add(closeButton); buttonFrame = new JInternalFrame("", false, false, false, false); buttonFrame.setContentPane(buttonPanel); buttonFrame.setOpaque(false); buttonFrame.getRootPane().setBackground(new Color(0, 0, 0, 0)); buttonFrame.setSize(BUTTON_ICON_WIDTH * 2 + BUTTON_GAP, BUTTON_ICON_HEIGHT); buttonFrame.setBorder(null); // myriad event handling installFocusHandlers(buttonPanel); // hide code window when escape key is hit textarea.addKeyListener( new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) setVisible(false); } }); // add dragging function of the move button, // reset the triangle after mouse release, and shift the editFrame // along with the mouse when the user is moving the window mxMouseControl moveListener = createMoveListener(); moveButton.addMouseListener(moveListener); moveButton.addMouseMotionListener(moveListener); closeButton.addMouseListener(createCloseListener()); // listens to resizing of editFrame and adjusts the position of the // buttons and the shape of the triangle accordingly editFrame.addComponentListener(createResizeListener()); // when code windows are on top of each other, layers them correctly // such that when the user clicks on any part of a code window // all three component internal frames are brought to the top // so they appear "focused" also InternalFrameListener iframeListener = new InternalFrameAdapter() { public void internalFrameActivated(InternalFrameEvent e) { moveToFrontLayer(); } public void internalFrameDeactivated(InternalFrameEvent e) { moveToBackLayer(); } }; editFrame.addInternalFrameListener(iframeListener); buttonFrame.addInternalFrameListener(iframeListener); triangleFrame.addInternalFrameListener(iframeListener); // add everything to desktop desktop.add(editFrame); desktop.add(buttonFrame); desktop.add(triangleFrame); moveToBackLayer(); }