Example usage for java.awt Color RED

List of usage examples for java.awt Color RED

Introduction

In this page you can find the example usage for java.awt Color RED.

Prototype

Color RED

To view the source code for java.awt Color RED.

Click Source Link

Document

The color red.

Usage

From source file:ColorComboBoxEditor.java

public static void main(String args[]) {
    Color colors[] = { Color.RED, Color.BLUE, Color.BLACK, Color.WHITE };
    JFrame frame = new JFrame("Editable JComboBox");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final JComboBox comboBox = new JComboBox(colors);
    comboBox.setEditable(true);/*from  w  w w.j a v  a 2 s. c  o m*/
    comboBox.setEditor(new ColorComboBoxEditor(Color.RED));
    frame.add(comboBox, BorderLayout.NORTH);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:ComboTableCellRenderer.java

public static void main(String args[]) {
    Color choices[] = { Color.RED, Color.ORANGE, Color.YELLOW, Color.GREEN, Color.BLUE, Color.MAGENTA };
    ComboTableCellRenderer renderer = new ComboTableCellRenderer();
    JComboBox comboBox = new JComboBox(choices);
    comboBox.setRenderer(renderer);//from  w w  w . j a  v  a2s  . com

    TableCellEditor editor = new DefaultCellEditor(comboBox);

    JFrame frame = new JFrame("Editable Color Table");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    TableModel model = new ColorTableModel();
    JTable table = new JTable(model);
    TableColumn column = table.getColumnModel().getColumn(1);
    column.setCellRenderer(renderer);
    column.setCellEditor(editor);

    JScrollPane scrollPane = new JScrollPane(table);
    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(400, 150);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    final JFormattedTextField textField1 = new JFormattedTextField(new Float(10.01));
    textField1.setFormatterFactory(new AbstractFormatterFactory() {
        @Override/*from   www .  j a va  2  s .com*/
        public AbstractFormatter getFormatter(JFormattedTextField tf) {
            NumberFormat format = DecimalFormat.getInstance();
            format.setMinimumFractionDigits(2);
            format.setMaximumFractionDigits(2);
            format.setRoundingMode(RoundingMode.HALF_UP);
            InternationalFormatter formatter = new InternationalFormatter(format);
            formatter.setAllowsInvalid(false);
            formatter.setMinimum(0.0);
            formatter.setMaximum(1000.00);
            return formatter;
        }
    });
    Map attributes = (new Font("Serif", Font.BOLD, 16)).getAttributes();
    attributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
    final JFormattedTextField textField2 = new JFormattedTextField(new Float(10.01));
    textField2.setFormatterFactory(new AbstractFormatterFactory() {

        @Override
        public AbstractFormatter getFormatter(JFormattedTextField tf) {
            NumberFormat format = DecimalFormat.getInstance();
            format.setMinimumFractionDigits(2);
            format.setMaximumFractionDigits(2);
            format.setRoundingMode(RoundingMode.HALF_UP);
            InternationalFormatter formatter = new InternationalFormatter(format);
            formatter.setAllowsInvalid(false);
            formatter.setMinimum(0.0);
            formatter.setMaximum(1000.00);
            return formatter;
        }
    });
    textField2.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void changedUpdate(DocumentEvent documentEvent) {
            printIt(documentEvent);
        }

        @Override
        public void insertUpdate(DocumentEvent documentEvent) {
            printIt(documentEvent);
        }

        @Override
        public void removeUpdate(DocumentEvent documentEvent) {
            printIt(documentEvent);
        }

        private void printIt(DocumentEvent documentEvent) {
            DocumentEvent.EventType type = documentEvent.getType();
            double t1a1 = (((Number) textField2.getValue()).doubleValue());
            if (t1a1 > 100) {
                textField2.setFont(new Font(attributes));
                textField2.setForeground(Color.red);
            } else {
                textField2.setFont(new Font("Serif", Font.BOLD, 16));
                textField2.setForeground(Color.black);
            }
        }
    });
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(textField1, BorderLayout.NORTH);
    frame.add(textField2, BorderLayout.SOUTH);
    frame.setVisible(true);
    frame.pack();
}

From source file:jat.examples.TwoBodyExample.TwoBodyExample.java

public static void main(String[] args) {

    TwoBodyExample x = new TwoBodyExample();

    // create a TwoBody orbit using orbit elements
    TwoBodyAPL sat = new TwoBodyAPL(7000.0, 0.3, 0.0, 0.0, 0.0, 0.0);

    double[] y = sat.randv();

    ArrayRealVector v = new ArrayRealVector(y);

    DecimalFormat df2 = new DecimalFormat("#,###,###,##0.00");
    RealVectorFormat format = new RealVectorFormat(df2);
    System.out.println(format.format(v));

    // find out the period of the orbit
    double period = sat.period();

    // set the final time = one orbit period
    double tf = period;

    // set the initial time to zero
    double t0 = 0.0;

    // propagate the orbit
    FirstOrderIntegrator dp853 = new DormandPrince853Integrator(1.0e-8, 100.0, 1.0e-10, 1.0e-10);
    dp853.addStepHandler(sat.stepHandler);
    // double[] y = new double[] { 7000.0, 0, 0, .0, 8, 0 }; // initial
    // state//  w  w w.j a  v a  2  s .c o m

    dp853.integrate(sat, 0.0, y, 8000, y); // now y contains final state at
    // tf

    Double[] objArray = sat.time.toArray(new Double[sat.time.size()]);
    double[] timeArray = ArrayUtils.toPrimitive(objArray);
    double[] xsolArray = ArrayUtils.toPrimitive(sat.xsol.toArray(new Double[sat.time.size()]));
    double[] ysolArray = ArrayUtils.toPrimitive(sat.ysol.toArray(new Double[sat.time.size()]));

    double[][] XY = new double[timeArray.length][2];

    // int a=0;
    // System.arraycopy(timeArray,0,XY[a],0,timeArray.length);
    // System.arraycopy(ysolArray,0,XY[1],0,ysolArray.length);

    for (int i = 0; i < timeArray.length; i++) {
        XY[i][0] = xsolArray[i];
        XY[i][1] = ysolArray[i];
    }

    Plot2DPanel p = new Plot2DPanel();

    // Plot2DPanel p = new Plot2DPanel(min, max, axesScales, axesLabels);

    ScatterPlot s = new ScatterPlot("orbit", Color.RED, XY);
    // LinePlot l = new LinePlot("sin", Color.RED, XY);
    // l.closed_curve = false;
    // l.draw_dot = true;
    p.addPlot(s);
    p.setLegendOrientation(PlotPanel.SOUTH);
    double plotSize = 10000.;
    double[] min = { -plotSize, -plotSize };
    double[] max = { plotSize, plotSize };
    p.setFixedBounds(min, max);

    new FrameView(p).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    System.out.println("end");

}

From source file:PowerMethod.power_method.java

public static void main(String[] args) {
    //////////////////////////////////////////////////////
    // Edit vals to contain values for matrix A         //
    // Edit vals2 to contain values for initial vector  //
    //////////////////////////////////////////////////////
    double[][] vals = { { 3, 4 }, { 3, 1 } };
    RealMatrix A = new Array2DRowRealMatrix(vals);
    double[][] vals2 = { { 1 }, { 1 } };
    RealMatrix u = new Array2DRowRealMatrix(vals2);
    power_object a = power_method(A, u, .1, 7);

    List<RealMatrix> matrices = genMatrices();
    List<trace_det> trace_dets = new ArrayList<>();
    double trace;
    double det;//from   ww  w  . j  av  a 2  s. co  m
    int iterA;
    int iterInverseA;
    for (RealMatrix r : matrices) {
        MatrixMethods m = new MatrixMethods(r);
        RealMatrix inverseR = m.inverseMatrix();
        power_object largestVal = power_method(r, u, .00005, 100);
        power_object smallestVal = power_method(inverseR, u, .00005, 100);
        if (largestVal == null || smallestVal == null) {
            continue;
        }
        trace = m.trace();
        det = m.determinant();
        iterA = largestVal.getNumN();
        iterInverseA = smallestVal.getNumN();
        trace_det td = new trace_det(trace, det, iterA, iterInverseA);
        trace_dets.add(td);
    }
    JFreeChart chart = ChartFactory.createXYLineChart("Trace vs. Determinant for Power Method", "Determinant",
            "Trace", createDataSetA(trace_dets), PlotOrientation.VERTICAL, true, true, false);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
    final XYPlot plot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesPaint(1, Color.BLUE);
    renderer.setSeriesPaint(2, Color.GREEN);
    renderer.setSeriesPaint(3, Color.BLACK);
    renderer.setSeriesPaint(4, Color.YELLOW);
    renderer.setSeriesPaint(5, Color.PINK);
    renderer.setSeriesPaint(6, Color.ORANGE);
    renderer.setSeriesPaint(7, Color.GRAY);
    renderer.setSeriesPaint(8, Color.MAGENTA);
    renderer.setSeriesPaint(9, Color.LIGHT_GRAY);
    renderer.setSeriesPaint(10, Color.DARK_GRAY);
    //renderer.setSeriesStroke( 0 , new BasicStroke( 3.0f ) );
    //renderer.setSeriesStroke( 1 , new BasicStroke( 2.0f ) );
    plot.setRenderer(renderer);
    ChartFrame frame = new ChartFrame("Power Method", chart);
    frame.pack();
    frame.setVisible(true);

    JFreeChart inverseChart = ChartFactory.createXYLineChart("Trace vs. Determinant for Inverse Power Method",
            "Determinant", "Trace", createDataSetAInverse(trace_dets), PlotOrientation.VERTICAL, true, true,
            false);
    ChartPanel inverseChartPanel = new ChartPanel(inverseChart);
    inverseChartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
    final XYPlot inversePlot = inverseChart.getXYPlot();
    XYLineAndShapeRenderer inverseRenderer = new XYLineAndShapeRenderer();
    inverseRenderer.setSeriesPaint(0, Color.RED);
    inverseRenderer.setSeriesPaint(1, Color.BLUE);
    inverseRenderer.setSeriesPaint(2, Color.GREEN);
    inverseRenderer.setSeriesPaint(3, Color.BLACK);
    inverseRenderer.setSeriesPaint(4, Color.YELLOW);
    inverseRenderer.setSeriesPaint(5, Color.PINK);
    inverseRenderer.setSeriesPaint(6, Color.ORANGE);
    inverseRenderer.setSeriesPaint(7, Color.GRAY);
    inverseRenderer.setSeriesPaint(8, Color.MAGENTA);
    inverseRenderer.setSeriesPaint(9, Color.LIGHT_GRAY);
    inverseRenderer.setSeriesPaint(10, Color.DARK_GRAY);
    inversePlot.setRenderer(renderer);
    ChartFrame inverseFrame = new ChartFrame("Power Method", inverseChart);
    inverseFrame.pack();
    inverseFrame.setVisible(true);
}

From source file:ega.projekt.graphDraw.DrawGraph.java

/**
 * @param args the command line arguments
 *///www .  j  a va 2 s  .co  m
public static void main(String[] args) {
    ega.projekt.graph.Graph dataGraph = new ega.projekt.graph.Graph(5, 100, 295, 295);
    if (dataGraph.getEdges().isEmpty())
        System.out.println("Error initializing graph");
    DrawGraph graphView = new DrawGraph(dataGraph); // This builds the graph
    // Layout<V, E>, VisualizationComponent<V,E>
    Layout<Node, Edge> layout = new StaticLayout(graphView.drawGraph);
    for (Node n : graphView.drawGraph.getVertices()) {
        layout.setLocation(n, new java.awt.geom.Point2D.Double(n.getX(), n.getY()));
    }
    layout.setSize(new Dimension(300, 300));
    BasicVisualizationServer<Node, Edge> vv = new BasicVisualizationServer<>(layout);
    vv.setPreferredSize(new Dimension(350, 350));
    // Setup up a new vertex to paint transformer...
    Transformer<Node, Paint> vertexPaint = new Transformer<Node, Paint>() {
        public Paint transform(Node i) {
            return Color.GREEN;
        }
    };

    // Set up a new stroke Transformer for the edges
    //float dash[] = {10.0f};
    final Stroke edgeStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
    Transformer<Edge, Stroke> edgeStrokeTransformer = new Transformer<Edge, Stroke>() {
        public Stroke transform(Edge e) {
            if (e.isMarked()) {
                final Stroke modStroke = new BasicStroke(5.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
                return modStroke;
            }
            return edgeStroke;
        }
    };
    Transformer<Edge, Paint> edgePaint = new Transformer<Edge, Paint>() {
        public Paint transform(Edge e) {
            if (e.isMarked()) {
                return Color.RED;
            }
            return Color.BLACK;
        }
    };
    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
    vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.QuadCurve<Node, Edge>());
    vv.getRenderContext().setEdgeLabelTransformer(new Transformer<Edge, String>() {
        public String transform(Edge e) {
            return (e.getFlowString() + "/" + Integer.toString(e.getCapacity()));
        }
    });
    vv.getRenderContext().setVertexLabelTransformer(new Transformer<Node, String>() {
        public String transform(Node n) {
            return (Integer.toString(n.getID()));
        }
    });
    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR);

    JFrame frame = new JFrame("Simple Graph View 2");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(vv);
    frame.pack();
    frame.setVisible(true);
}

From source file:Examples.java

public static void main(String args[]) {

    JFrame frame = new JFrame("Example Popup");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new GridLayout(0, 1));

    JFrame frame2 = new JFrame("Desktop");
    final JDesktopPane desktop = new JDesktopPane();
    frame2.getContentPane().add(desktop);
    JButton pick = new JButton("Pick");
    pick.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            System.out.println("Hi");
        }// www . java  2 s  .co m
    });
    frame2.getContentPane().add(pick, BorderLayout.SOUTH);

    JButton messagePopup = new JButton("Message");
    contentPane.add(messagePopup);
    messagePopup.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            Component source = (Component) actionEvent.getSource();
            JOptionPane.showMessageDialog(source, "Printing complete");
            JOptionPane.showInternalMessageDialog(desktop, "Printing complete");
        }
    });

    JButton confirmPopup = new JButton("Confirm");
    contentPane.add(confirmPopup);
    confirmPopup.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            Component source = (Component) actionEvent.getSource();
            JOptionPane.showConfirmDialog(source, "Continue printing?");
            JOptionPane.showInternalConfirmDialog(desktop, "Continue printing?");
        }
    });

    JButton inputPopup = new JButton("Input");
    contentPane.add(inputPopup);
    inputPopup.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            Component source = (Component) actionEvent.getSource();
            JOptionPane.showInputDialog(source, "Enter printer name:");
            // Moons of Neptune
            String smallList[] = { "Naiad", "Thalassa", "Despina", "Galatea", "Larissa", "Proteus", "Triton",
                    "Nereid" };
            JOptionPane.showInternalInputDialog(desktop, "Pick a printer", "Input",
                    JOptionPane.QUESTION_MESSAGE, null, smallList, "Triton");
            // Moons of Saturn - includes two provisional designations to
            // make 20
            String bigList[] = { "Pan", "Atlas", "Prometheus", "Pandora", "Epimetheus", "Janus", "Mimas",
                    "Enceladus", "Tethys", "Telesto", "Calypso", "Dione", "Helene", "Rhea", "Titan", "Hyperion",
                    "Iapetus", "Phoebe", "S/1995 S 2", "S/1981 S 18" };
            //        Object saturnMoon = JOptionPane.showInputDialog(source, "Pick
            // a printer", "Input", JOptionPane.QUESTION_MESSAGE, null,
            // bigList, "Titan");
            Object saturnMoon = JOptionPane.showInputDialog(source, "Pick a printer", "Input",
                    JOptionPane.QUESTION_MESSAGE, null, bigList, null);
            System.out.println("Saturn Moon: " + saturnMoon);
        }
    });

    JButton optionPopup = new JButton("Option");
    contentPane.add(optionPopup);
    optionPopup.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            Component source = (Component) actionEvent.getSource();

            Icon greenIcon = new DiamondIcon(Color.green);
            Icon redIcon = new DiamondIcon(Color.red);
            Object iconArray[] = { greenIcon, redIcon };
            JOptionPane.showOptionDialog(source, "Continue printing?", "Select an Option",
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, iconArray, iconArray[1]);

            Icon blueIcon = new DiamondIcon(Color.blue);
            Object stringArray[] = { "Do It", "No Way" };
            JOptionPane.showInternalOptionDialog(desktop, "Continue printing?", "Select an Option",
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, blueIcon, stringArray,
                    stringArray[0]);
        }
    });

    frame.setSize(300, 200);
    frame.setVisible(true);
    frame2.setSize(300, 200);
    frame2.setVisible(true);
}

From source file:SimpleMenu.java

/** A simple test program for the above code */
public static void main(String[] args) {
    // Get the locale: default, or specified on command-line
    Locale locale;/*from  w ww.  j a v  a 2s  .c o  m*/
    if (args.length == 2)
        locale = new Locale(args[0], args[1]);
    else
        locale = Locale.getDefault();

    // Get the resource bundle for that Locale. This will throw an
    // (unchecked) MissingResourceException if no bundle is found.
    ResourceBundle bundle = ResourceBundle.getBundle("com.davidflanagan.examples.i18n.Menus", locale);

    // Create a simple GUI window to display the menu with
    final JFrame f = new JFrame("SimpleMenu: " + // Window title
            locale.getDisplayName(Locale.getDefault()));
    JMenuBar menubar = new JMenuBar(); // Create a menubar.
    f.setJMenuBar(menubar); // Add menubar to window

    // Define an action listener for that our menu will use.
    ActionListener listener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String s = e.getActionCommand();
            Component c = f.getContentPane();
            if (s.equals("red"))
                c.setBackground(Color.red);
            else if (s.equals("green"))
                c.setBackground(Color.green);
            else if (s.equals("blue"))
                c.setBackground(Color.blue);
        }
    };

    // Now create a menu using our convenience routine with the resource
    // bundle and action listener we've created
    JMenu menu = SimpleMenu.create(bundle, "colors", new String[] { "red", "green", "blue" }, listener);

    // Finally add the menu to the GUI, and pop it up
    menubar.add(menu); // Add the menu to the menubar
    f.setSize(300, 150); // Set the window size.
    f.setVisible(true); // Pop the window up.
}

From source file:akori.AKORI.java

public static void main(String[] args) throws IOException, InterruptedException {
    System.out.println("esto es AKORI");

    URL = "http://www.mbauchile.cl";
    PATH = "E:\\NetBeansProjects\\AKORI\\";
    NAME = "mbauchile.png";
    // Extrar DOM tree

    Document doc = Jsoup.connect(URL).timeout(0).get();

    // The Firefox driver supports javascript 
    WebDriver driver = new FirefoxDriver();
    driver.manage().window().maximize();
    System.out.println(driver.manage().window().getSize().toString());
    System.out.println(driver.manage().window().getPosition().toString());
    int xmax = driver.manage().window().getSize().width;
    int ymax = driver.manage().window().getSize().height;

    // Go to the URL page
    driver.get(URL);/*from   ww  w .ja  v a 2  s.  c  o  m*/

    File screen = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
    FileUtils.copyFile(screen, new File(PATH + NAME));

    BufferedImage img = ImageIO.read(new File(PATH + NAME));
    //Graphics2D graph = img.createGraphics();

    BufferedImage img1 = new BufferedImage(xmax, ymax, BufferedImage.TYPE_INT_ARGB);
    Graphics2D graph1 = img.createGraphics();
    double[][] matrix = new double[ymax][xmax];
    BufferedReader in = new BufferedReader(new FileReader("et.txt"));
    String linea;
    double max = 0;
    graph1.drawImage(img, 0, 0, null);
    HashMap<String, Integer> lista = new HashMap<String, Integer>();
    int count = 0;
    for (int i = 0; (linea = in.readLine()) != null && i < 10000; ++i) {
        String[] datos = linea.split(",");
        int x = (int) Double.parseDouble(datos[0]);
        int y = (int) Double.parseDouble(datos[2]);
        long time = Double.valueOf(datos[4]).longValue();
        if (x >= xmax || y >= ymax)
            continue;
        if (time < 691215)
            continue;
        if (time > 705648)
            break;
        if (lista.containsKey(x + "," + y))
            lista.put(x + "," + y, lista.get(x + "," + y) + 1);
        else
            lista.put(x + "," + y, 1);
        ++count;
    }
    System.out.println(count);
    in.close();
    Iterator iter = lista.entrySet().iterator();
    Map.Entry e;
    for (String key : lista.keySet()) {
        Integer i = lista.get(key);
        if (max < i)
            max = i;
    }
    System.out.println(max);
    max = 0;
    while (iter.hasNext()) {
        e = (Map.Entry) iter.next();
        String xy = (String) e.getKey();
        String[] datos = xy.split(",");
        int x = Integer.parseInt(datos[0]);
        int y = Integer.parseInt(datos[1]);
        matrix[y][x] += (int) e.getValue();
        double aux;
        if ((aux = normalMatrix(matrix, y, x, ((int) e.getValue()) * 4)) > max) {
            max = aux;
        }
        //normalMatrix(matrix,x,y,20);
        if (matrix[y][x] > max)
            max = matrix[y][x];
    }
    int A, R, G, B, n;
    for (int i = 0; i < xmax; ++i) {
        for (int j = 0; j < ymax; ++j) {
            if (matrix[j][i] != 0) {
                n = (int) Math.round(matrix[j][i] * 100 / max);
                R = Math.round((255 * n) / 100);
                G = Math.round((255 * (100 - n)) / 100);
                B = 0;
                A = Math.round((255 * n) / 100);
                ;
                if (R > 255)
                    R = 255;
                if (R < 0)
                    R = 0;
                if (G > 255)
                    G = 255;
                if (G < 0)
                    G = 0;
                if (R < 50)
                    A = 0;
                graph1.setColor(new Color(R, G, B, A));
                graph1.fillOval(i, j, 1, 1);
            }
        }
    }
    //graph1.dispose();

    ImageIO.write(img, "png", new File("example.png"));
    System.out.println(max);

    graph1.setColor(Color.RED);
    // Extraer elementos
    Elements e1 = doc.body().getAllElements();
    int i = 1;
    ArrayList<String> tags = new ArrayList<String>();
    for (Element temp : e1) {

        if (tags.indexOf(temp.tagName()) == -1) {
            tags.add(temp.tagName());

            List<WebElement> query = driver.findElements(By.tagName(temp.tagName()));
            for (WebElement temp1 : query) {
                Point po = temp1.getLocation();
                Dimension d = temp1.getSize();
                if (d.width <= 0 || d.height <= 0 || po.x < 0 || po.y < 0)
                    continue;
                System.out.println(i + " " + temp.nodeName());
                System.out.println("  x: " + po.x + " y: " + po.y);
                System.out.println("  width: " + d.width + " height: " + d.height);
                graph1.draw(new Rectangle(po.x, po.y, d.width, d.height));
                ++i;
            }
        }
    }

    graph1.dispose();
    ImageIO.write(img, "png", new File(PATH + NAME));

    driver.quit();

}

From source file:Graph_with_jframe_and_arduino.java

public static void main(String[] args) {

    // create and configure the window
    JFrame window = new JFrame();
    window.setTitle("Sensor Graph GUI");
    window.setSize(600, 400);/*w  ww  .ja  v  a  2 s.c  o m*/
    window.setLayout(new BorderLayout());
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // create a drop-down box and connect button, then place them at the top of the window
    JComboBox<String> portList_combobox = new JComboBox<String>();
    Dimension d = new Dimension(300, 100);
    portList_combobox.setSize(d);
    JButton connectButton = new JButton("Connect");
    JPanel topPanel = new JPanel();
    topPanel.add(portList_combobox);
    topPanel.add(connectButton);
    window.add(topPanel, BorderLayout.NORTH);
    //pause button
    JButton Pause_btn = new JButton("Start");

    // populate the drop-down box
    SerialPort[] portNames;
    portNames = SerialPort.getCommPorts();
    //check for new port available
    Thread thread_port = new Thread() {
        @Override
        public void run() {
            while (true) {
                SerialPort[] sp = SerialPort.getCommPorts();
                if (sp.length > 0) {
                    for (SerialPort sp_name : sp) {
                        int l = portList_combobox.getItemCount(), i;
                        for (i = 0; i < l; i++) {
                            //check port name already exist or not
                            if (sp_name.getSystemPortName().equalsIgnoreCase(portList_combobox.getItemAt(i))) {
                                break;
                            }
                        }
                        if (i == l) {
                            portList_combobox.addItem(sp_name.getSystemPortName());
                        }

                    }

                } else {
                    portList_combobox.removeAllItems();

                }
                portList_combobox.repaint();

            }

        }

    };
    thread_port.start();
    for (SerialPort sp_name : portNames)
        portList_combobox.addItem(sp_name.getSystemPortName());

    //for(int i = 0; i < portNames.length; i++)
    //   portList.addItem(portNames[i].getSystemPortName());

    // create the line graph
    XYSeries series = new XYSeries("line 1");
    XYSeries series2 = new XYSeries("line 2");
    XYSeries series3 = new XYSeries("line 3");
    XYSeries series4 = new XYSeries("line 4");
    for (int i = 0; i < 100; i++) {
        series.add(x, 0);
        series2.add(x, 0);
        series3.add(x, 0);
        series4.add(x, 10);
        x++;
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series);
    dataset.addSeries(series2);
    XYSeriesCollection dataset2 = new XYSeriesCollection();
    dataset2.addSeries(series3);
    dataset2.addSeries(series4);

    //create jfree chart
    JFreeChart chart = ChartFactory.createXYLineChart("Sensor Readings", "Time (seconds)", "Arduino Reading",
            dataset);
    JFreeChart chart2 = ChartFactory.createXYLineChart("Sensor Readings", "Time (seconds)", "Arduino Reading 2",
            dataset2);

    //color render for chart 1
    XYLineAndShapeRenderer r1 = new XYLineAndShapeRenderer();
    r1.setSeriesPaint(0, Color.RED);
    r1.setSeriesPaint(1, Color.GREEN);
    r1.setSeriesShapesVisible(0, false);
    r1.setSeriesShapesVisible(1, false);

    XYPlot plot = chart.getXYPlot();
    plot.setRenderer(0, r1);
    plot.setRenderer(1, r1);

    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.DARK_GRAY);
    plot.setRangeGridlinePaint(Color.blue);

    //color render for chart 2
    XYLineAndShapeRenderer r2 = new XYLineAndShapeRenderer();
    r2.setSeriesPaint(0, Color.BLUE);
    r2.setSeriesPaint(1, Color.ORANGE);
    r2.setSeriesShapesVisible(0, false);
    r2.setSeriesShapesVisible(1, false);

    XYPlot plot2 = chart2.getXYPlot();
    plot2.setRenderer(0, r2);
    plot2.setRenderer(1, r2);

    ChartPanel cp = new ChartPanel(chart);
    ChartPanel cp2 = new ChartPanel(chart2);

    //multiple graph container
    JPanel graph_container = new JPanel();
    graph_container.setLayout(new BoxLayout(graph_container, BoxLayout.X_AXIS));
    graph_container.add(cp);
    graph_container.add(cp2);

    //add chart panel in main window
    window.add(graph_container, BorderLayout.CENTER);
    //window.add(cp2, BorderLayout.WEST);

    window.add(Pause_btn, BorderLayout.AFTER_LAST_LINE);
    Pause_btn.setEnabled(false);
    //pause btn action
    Pause_btn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (Pause_btn.getText().equalsIgnoreCase("Pause")) {

                if (chosenPort.isOpen()) {
                    try {
                        Output.write(0);
                    } catch (IOException ex) {
                        Logger.getLogger(Graph_with_jframe_and_arduino.class.getName()).log(Level.SEVERE, null,
                                ex);
                    }
                }

                Pause_btn.setText("Start");
            } else {
                if (chosenPort.isOpen()) {
                    try {
                        Output.write(1);
                    } catch (IOException ex) {
                        Logger.getLogger(Graph_with_jframe_and_arduino.class.getName()).log(Level.SEVERE, null,
                                ex);
                    }
                }

                Pause_btn.setText("Pause");
            }
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    });

    // configure the connect button and use another thread to listen for data
    connectButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            if (connectButton.getText().equals("Connect")) {
                // attempt to connect to the serial port
                chosenPort = SerialPort.getCommPort(portList_combobox.getSelectedItem().toString());
                chosenPort.setComPortTimeouts(SerialPort.TIMEOUT_SCANNER, 0, 0);
                if (chosenPort.openPort()) {
                    Output = chosenPort.getOutputStream();
                    connectButton.setText("Disconnect");
                    Pause_btn.setEnabled(true);
                    portList_combobox.setEnabled(false);
                }

                // create a new thread that listens for incoming text and populates the graph
                Thread thread = new Thread() {
                    @Override
                    public void run() {
                        Scanner scanner = new Scanner(chosenPort.getInputStream());
                        while (scanner.hasNextLine()) {
                            try {
                                String line = scanner.nextLine();
                                int number = Integer.parseInt(line);
                                series.add(x, number);
                                series2.add(x, number / 2);
                                series3.add(x, number / 1.5);
                                series4.add(x, number / 5);

                                if (x > 100) {
                                    series.remove(0);
                                    series2.remove(0);
                                    series3.remove(0);
                                    series4.remove(0);
                                }

                                x++;
                                window.repaint();
                            } catch (Exception e) {
                            }
                        }
                        scanner.close();
                    }
                };
                thread.start();
            } else {
                // disconnect from the serial port
                chosenPort.closePort();
                portList_combobox.setEnabled(true);
                Pause_btn.setEnabled(false);
                connectButton.setText("Connect");

            }
        }
    });

    // show the window
    window.setVisible(true);
}